PHP Web Game Learning Xnova (ogame) Source code Interpretation (v) _php instance

Source: Internet
Author: User
Tags explode

Six, game main interface (frames.php)

frames.php file function is to display the game 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 script
array_pop ($Uri _array);
$XNova _uri   = implode ('/', $Uri _array);

The above code is mainly spelled out the URL of the server, relatively simple; the previous variable $inlogin for the time being, when we specialize in explaining the common.php, focus on the description.

Then include two of the files we talked about before, and then output a large section of HTML code. It should be noted that the HTML code constructs two frame, respectively, leftmenu.php and overview.php, which I will analyze below.

Seven, left navigation bar (leftmenu.php)

This file is actually very simple, remove the previous common code, only declared the Showleftmenu () function, and finally use display () output page. The function Showleftmenu () is not difficult, the code is nothing more than a gettemplate template file, get the parameters of the server settings and the user level of the login, and then construct the page. Note that the user level variable $level, when the value of $level is greater than 0, will display the Administrator link. The level defined by the $level value is in the System.mo file, 0 is a regular player, 1 is a game operator, 2 is a game manager, and 3 is an administrator.

Viii. Overview (overview.php)

This file is actually the corresponding link ' profile ' in the left navigation bar, the main function is to display the approximate information of the current planet and the user's information, including the current state of other planets and so on. The amount of code is very large, in fact, the organization is very clear, we slowly look, the first few lines of code we skip.

$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 to get the moon on the current planet and check the space used to modify the moon. The Checkplanetusedfields function not only works on the moon, it can also be used to check the planet, without looking at the code, we continue.

Next is a security verification, you need to set the ability to enable this function in the parameters, we can see for themselves, such a lot of code, after I generally do not analyze the game process is not very related. Next is a switch, two branches, a renamed planet (abandonment of the planet), temporarily do not look; the other default branch is the process to be performed after the login, as follows

1. Check the user's message, if there is a new message to display the message link
2. The process of the expert system, I removed this logic myself, so I do not intend to analyze
3. Check whether the user has fleet activities, if there is a structure of the Fleet Activity Information table, using the Buildfleeteventtable function construction, later introduced
4. If the user has other planets, then construct a list of other planets and show the current activity of each planet
5. Information on the interstellar missile activity showing its launch and attacks from other players
6. Other information display, such as announcements Ah, Google's ads and so on
7. If there is a moon, show the moon information
8. Below are some of the planet's name, planet Space, user rankings and other information, more cluttered

The above process code, there are comments, not difficult to understand, the following code we want to introduce.

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 Store The current planet information, the b_building of which is the construction queue. The above code first determines whether there is a building queue, and then according to the current time, update the building information, if the building is not completed, show the construction units and the remaining time of the building. About the construction of the queue function, to be introduced in detail, now skip.

Let's briefly introduce the next branch of the branch, which has three more processes:

1. Rename the planet, the code is not difficult, not much said
2. Abandon the Colonial planet and display the user to enter the password page
3. User input password, if the password is correct update the information on the planet and the user's default planet ID (the moon is not judged)

At this point, the user login to the game main interface process is clear, finally entered 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.