Home Backend Development PHP Tutorial Xnova (ogame) source code interpretation for PHP web game learning (13)_PHP tutorial

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

Jul 13, 2016 am 10:26 AM
php Source code interpretation Web games

16. Shipbuilding and defense (FleetBuildingPage.php and DefensesBuildingPage.php pages)

Let’s talk about the shipyard page first. In fact, there is no real shipbuilding in this page. It just saves the ships to be built and their quantity in the database; the code for generating ships is in another function. Next we start to analyze this page, and also follow the previous ideas, first explain the code that constructs the page.

First determine whether there is a shipyard on this planet. If not, of course, you will be prompted.

The following uses loop statements to construct the construction page for each type of ship. I don’t think this code needs to be explained in detail.

The next step is to display the list of ships being built. The script needs to dynamically display it, which is actually an illusion; even if it shows that there are ships built, if it is not refreshed, it will not be in the database. Note that there are two important fields here: b_hangar_id holds the list of ships to be built; b_hangar holds the time remaining since the last update, in seconds.

Use the function ElementBuildListBox() to construct a script for building a ship. You can read the function code yourself. It is not difficult, as long as you understand the two fields I mentioned earlier.

Finally output the shipyard page.

Now we are back to the front. The player enters the number of ships to be built and enters this code.

1. Obtain the code and quantity of the ship to be built
2. Determine whether the manufactured quantity exceeds the allowed maximum value. If it exceeds the allowed maximum value, take the maximum value
3. If the manufacturing quantity is not zero, determine whether manufacturing is allowed
4. Then get the maximum value that the current resources can produce
5. Set resource consumption and time consumption
6. Finally update the planet data, including the field b_hangar_id for reducing resources and building ships, and post the code as follows:

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

The shipyard page is completed, now let’s look at the defense page. The basic logic of this page is the same as that of the shipyard, so I won’t write it down here. The difference is that there are more logical restrictions, which are listed as follows:

1. When constructing the defense unit page, codes 407 and 408 are large and small defense shields. Please note that there can only be one
2. In the manufacturing code after the player inputs the quantity, codes 502 and 503 are interceptor missiles and interstellar missiles. Pay attention to the quantity relationship between the two missiles and the number of missiles in the manufacturing list
3. Also use the field b_hangar_id to save

The shipbuilding and defense page has been briefly explained. The most important manufacturing code is in another function, which will be analyzed in the next chapter.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824767.htmlTechArticle16. Shipbuilding and defense (FleetBuildingPage.php and DefensesBuildingPage.php pages) Let’s talk about the shipyard page first. In fact, this There is no real shipbuilding on the page, it just puts the ship to be built and the number...
Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles