This article mainly introduces the shipbuilding and Defense Code part of PHP Web Game Xnova (ogame) source code. If you need it, you can refer to section 16, shipbuilding and defense (FleetBuildingPage. php and DefensesBuildingPage. php page)
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['deuterium'] -= $Ressource['deuterium']; $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.