PHP web game learning-Explanation of Xnova (ogame) source code (13th)

Source: Internet
Author: User
This article mainly introduces the shipbuilding and Defense Code Part Of The PHP web game Xnova (ogame) Source Code. For more information, see

This article mainly introduces the shipbuilding and Defense Code Part Of The PHP web game Xnova (ogame) Source Code. For more information, see

16th. Shipbuilding and defense (FleetBuildingPage. php and DefensesBuildingPage. php pages)

Let's talk about the shipyard page first. In fact, there is no real shipbuilding on this page, but it just saves the ship and quantity to the database. The code for generating the ship is in another function. Next, we will analyze this page and explain the code for constructing the page according to the previous ideas.

First, judge whether the planet already has a shipyard.

The following uses a loop statement to construct the construction page for each type of ship. I don't think I need to explain this code in detail.

The next step is to display the list of ships being manufactured. A script is used to dynamically display the images. Even if a ship is created, it is not displayed in the database if it is not refreshed. Note that there are two important fields: B _hangar_id stores the list of ships to be created, and B _hangar stores the remaining time after the last update, in seconds.

You can use the ElementBuildListBox () function to construct a shipbuilding script. You can understand the two fields I mentioned earlier.

Finally, the shipyard page is output.

Now let's go back to the front. players enter the number of ships to be manufactured and enter this code.

1. Obtain the Ship code and quantity to be manufactured
2. Determine whether the manufacturing quantity exceeds the allowed maximum value. If the maximum value is exceeded, the maximum value is used.
3. If the manufacturing quantity is not zero, determine whether manufacturing is allowed.
4. then obtain the maximum value that the current resource can manufacture.
5. Set resource consumption and time consumption
6. Finally, update the planet data, including reducing the resource and constructing the ship field B _hangar_id. The Code is as follows:

If ($ Count> = 1) {$ CurrentPlanet ['metal']-= $ Ressource ['metal']; $ CurrentPlanet ['crystal ']-= $ Ressource ['crystal']; $ CurrentPlanet ['deletery']-= $ Ressource ['deletery']; $ CurrentPlanet ['B _ hangar_id']. = "". $ Element. ",". $ Count. ";";}

The shipyard page is complete. Let's look at the Defense page. The basic logic of this page is the same as that of the shipyard. The difference is that there are some logic restrictions listed as follows:

1. When constructing the Defense Unit page, code 407 and 408 are the size defense shield. Note that only one
2. In the manufacturing code of the number entered by the player, codes 502 and 503 are used to intercept missiles and interstellar missiles. Pay attention to the relationship between the number of missiles in the two missiles and the number of missiles in the manufacturing list.
3. Use the field B _hangar_id to save the file.

The shipbuilding and defense page is simply explained. The most important manufacturing code is analyzed in the next chapter in another function.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.