PHP Web Game Learning Xnova (ogame) Source code interpretation (13) _php instance

Source: Internet
Author: User
Tags php and

16. Shipbuilding and defense (fleetbuildingpage.php and defensesbuildingpage.php page)

First of all, the shipyard page, in fact, this page does not really ship, but to build the ship and the number of the database to save the ship's code in another function. Here we start to analyze this page, and also follow the previous ideas, first to explain the construction of the page code.

First of all to determine whether the planet has a shipyard, there is no course to hint.

The following uses the Loop statement, constructs each kind of ship the construction page, this piece of code I thought does not need to explain in detail.

The next step is to display the list of ships that are being manufactured, and to animate the script, which is actually a false image, even if the ship has been built, if not refreshed, the database will not be there. Note that there are two important fields: b_hangar_id the list of ships to be built, and b_hangar the remaining time after the last update, in seconds.

Using the function Elementbuildlistbox (), constructs a shipbuilding the script, the function code everybody sees, is not difficult, as long as understands the front I said two fields to be possible.

The final output of the shipyard page.

Now we're back to the front, and the player enters this code by entering the number of ships to be built.

1. Obtain the code and number of ships to be manufactured
2. Determine whether the manufacturing quantity exceeds the maximum allowable value, and the maximum value is exceeded.
3. If the manufacturing quantity is not zero, determine whether to allow manufacturing
4. Then get the maximum value that the current resource can produce
5. Set resource consumption and time consumption
6. The final update of the planetary data, including the reduction of resources and the construction of the ship's field b_hangar_id, is posted as follows:

if ($Count >= 1) {
 $CurrentPlanet [' metal '] = $Ressource [' Metal '];
 $CurrentPlanet [' crystal ']-= $Ressource [' Crystal '];
 $CurrentPlanet [' deuterium ']-= $Ressource [' deuterium '];
 $CurrentPlanet [' b_hangar_id '].= ']. $Element. ",". $Count. ";";
}

The shipyard page is complete, so let's look at the defense page below. The basic logic of this page is the same as that of a shipyard, which is not written here. The difference is a few more logical restrictions, listed below:

1. In the Construction of Defense units page, code 407 and 408 is the size of defense shield, to note that there can only be one
2. In the production code after the input number of players, code 502 and 503 are interceptor missiles and interstellar missiles, pay attention to the number of two missiles and the number of missiles in the manufacturing list.
3. Use the same field b_hangar_id to save

Shipbuilding and Defense page simply explained, the most important manufacturing code in another function, the next chapter analysis.

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.