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

Source: Internet
Author: User

6. Main game interface (frames. php)

The frames. php file function is used to display the game's main interface. first look at the following code:

$InLogin = false;$XNova_Host  = $_SERVER['HTTP_HOST'];$XNova_Script = $_SERVER['SCRIPT_NAME'];$Uri_Array   = explode ('/', $XNova_Script);// On vire le scriptarray_pop($Uri_Array);$XNova_URI   = implode ('/', $Uri_Array);$XNovaRootURL = "http://". $XNova_Host ."/". $XNova_URI ."/"; 

The above code is mainly to spell out the server URL, which is relatively simple; the previous variable $ InLogin will not be mentioned for the time being, so we will focus on the explanation when talking about common. php.

Then we include two files we mentioned earlier, and finally output a large HTML code. Note that two frames are constructed in the HTML code, leftmenu. php and overview. php. I will analyze them below.

7. Left Navigation Bar (leftmenu. php)

This file is actually very simple. Apart from the common code above, only the ShowLeftMenu () function is declared, and the page is output using display. The ShowLeftMenu () function is not difficult. The code is nothing more than the gettemplate template file, get the parameters set by the server, and the logon user level, and then construct the page. Note that the user Level variable $ level is displayed. When the value of $ Level is greater than 0, the Administrator link is displayed. The $ level value represents the level defined in the system.mo file. 0 is a common player, 1 is a game operator, 2 is a game administrator, and 3 is an administrator.

8. overview (overview. php)

In fact, this file is the "Overview" link in the left navigation bar. The main function is to display the approximate information of the current planet and user information, including the current status of other planets. The amount of code is very large, in fact it is very clear, we slowly look at the previous lines of code we skipped.

$lunarow = doquery("SELECT * FROM {{table}} WHERE 'id_owner' = '" . $planetrow['id_owner'] . "' AND 'galaxy' = '" . $planetrow['galaxy'] . "' AND 'system' = '" . $planetrow['system'] . "' AND 'lunapos' = '" . $planetrow['planet'] . "';", 'lunas', true);CheckPlanetUsedFields ($lunarow); 

This code function is used to get the current planet's moon and check the space used to repair the lunar January ball. The CheckPlanetUsedFields function is used not only to check the moon, but also to check the planet. Let's continue without looking at the code.

Next is a piece of security verification. You need to enable this function in the parameter settings. You can take a look at it on your own. There are a lot of such code that I will not analyze in the future, it has little to do with the game process. The next step is a switch with two branches. One is to rename the planet (discard the planet), and the other is not to be viewed for the moment. The other default branch is the process to be performed after login, as shown below:

1. Check the user's message. If there is a new message, the message link will be displayed.
2. The process of the expert system is removed by myself, so I am not planning to analyze it.
3. Check whether the user has a fleet activity. If yes, construct the fleet activity information table and use the BuildFleetEventTable function to construct the table.
4. If a user has another planet, a list of other planets is constructed and the current activity of each planet is displayed.
5. Display interstellar missile activity information for self-launch and attacks from other players
6. display other information, such as announcements and google ads.
7. If there is a moon, the moon information will be displayed.
8. The following are some information about the planet name, planet space, and User ranking, which are messy.

The codes of the above processes are annotated and it is not difficult to understand. We will introduce the following code.

if ($planetrow['b_building'] != 0) { UpdatePlanetBatimentQueueList ($planetrow, $user); if ($planetrow['b_building'] != 0) { $BuildQueue = explode (";", $planetrow['b_building_id']); $CurrBuild = explode (",", $BuildQueue[0]); $RestTime = $planetrow['b_building'] - time(); $PlanetID = $planetrow['id']; $Build = InsertBuildListScript ("overview"); $Build .= $lang['tech'][$CurrBuild[0]] . ' (' . ($CurrBuild[1]) . ')'; $Build .= "<div id="\"blc\"" class="\"z\"">" . pretty_time($RestTime) . "</div>"; $Build .= "\n<script type="text/javascript"><!--mce:0--></script>\n";  $parse['building'] = $Build; } else { $parse['building'] = $lang['Free']; }} else { $parse['building'] = $lang['Free'];} 

$ Planetrow stores information about the current planet. The B _building is a building queue. The code above first checks whether there is a building queue, and then updates the building information based on the current time. If there is still a building unfinished, the remaining time of the building unit and the building is displayed. The building queue function will be described in detail later.

Let's briefly introduce the previous Branch, which contains three steps:

1. Rename the planet. The code is not difficult, and I will not talk about it much.
2. Discard the colonial planet and display the page on which the user wants to enter the password
3. the user enters the password. If the password is correct, the information of the current planet and the user's default planet ID will be updated (the moon has not been determined)

Now, the process for logging on to the game's main interface is clear, and the user finally enters the game.

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.