Home  >  Article  >  Backend Development  >  Xnova (ogame) source code interpretation for PHP web game learning (5)_PHP tutorial

Xnova (ogame) source code interpretation for PHP web game learning (5)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:24:18696browse

6. Game main interface (frames.php)

The function of the frames.php file is to display the main interface of the game. 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);
$XNovaRootURL = "http://". $XNova_Host ."/". $XNova_URI ."/"; 

The above code is mainly to spell out the URL of the server, which is relatively simple; the previous variable $InLogin will not be discussed for the time being, and will be explained in detail when we explain common.php specifically.

Then it includes the two files we talked about before, and finally outputs a large piece of HTML code. It should be noted that two frames are constructed in the HTML code, namely leftmenu.php and overview.php, which I will analyze below.

7. Left navigation bar (leftmenu.php)

This file is actually very simple. Apart from the common code we used before, it only declares the ShowLeftMenu() function, and finally uses display() to output the page. The function ShowLeftMenu() is not difficult. The code is nothing more than getting the template file, getting the parameters set by the server and the logged-in user level, and then constructing the page. What should be noted is the user level variable $Level. When the value of $level is greater than 0, the administrator link will be displayed. The level represented by the value of $level is defined in the system.mo file. 0 is an ordinary player, 1 is a game operator, 2 is a game administrator, and 3 is an administrator.

8. Overview (overview.php)

This file is actually the corresponding link 'Overview' in the left navigation bar. Its main function is to display the general information of the current planet and the user's information, including the current status of other planets. The amount of code is large, but the organization is actually very clear. As we slowly look at it, we will skip the first few lines of code.

$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); 

The function of this code is to obtain the moon of the current planet and check and correct the usage space of the moon. The CheckPlanetUsedFields function not only works on the moon, but can also be used to check the planet. Let's continue without looking at the code.

The next step is a security verification. This function needs to be enabled in the parameters. You can take a look at it yourself. There are many such codes. I generally won’t analyze them in the future, and they have little to do with the game process. Next is a switch, two branches, one to rename the planet (abandon the planet), I will not look at it for now; the other default branch is the process to be carried out after logging in, as follows

1. Check the user’s messages and display the message link if there are new messages
2. I removed this logic of the expert system process myself, so I don’t plan to analyze it
3. Check whether the user has fleet activities, and if so, construct a fleet activity information table using the BuildFleetEventTable function, which will be introduced later
4. If the user has other planets, construct a list of other planets and display the current activities of each planet
5. Display the activity information of star missiles launched by yourself and attacks from other players
6. Other information display, such as announcements, Google ads, etc.
7. If there is a moon, display moon information
8. Below are some planet names, planet spaces, user rankings and other information, which is quite messy

The codes of the above processes are all commented, so 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 the current planet information, where b_building is the building queue. The above code first determines whether there is a building queue, and then updates the building information based on the current time; if there are still unfinished buildings, it displays the building units and the remaining time of the building. Regarding the building queue function, we will introduce it in detail later, but we will skip it now.

Let’s briefly introduce the previous branch. There are three processes in the branch:

1. Rename the planet, the code is not difficult and there is not much to say
2. Abandon the colonized planet and display the page where the user needs to enter the password
3. The user enters the password. If the password is correct, the information of this planet and the user’s default planet ID are updated (the moon is not judged)

At this point, the process for users to log in to the main game interface is clear, and they finally enter the game.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825513.htmlTechArticle 6. Game main interface (frames.php) The function of the frames.php file is to display the game main interface, first look at the following Code: $InLogin = false;$XNova_Host = $_SERVER['HTTP_HOST'];$XNova_Scri...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn