PHP Web Game Development Introductory Tutorial One (webgame+design) _php instance

Source: Internet
Author: User
Tags map class
a simple procedural framework.
Webgame Program Composition:
Three parts.
The first is the data flow. The second is the procedure. The third is art.
Among them, the data flow includes the function. Data flow can only be reflected in the function.
The data flow is quite troublesome and is discussed later.
For example, the simplest selling and buying products.
To implement this function.
Then you need to have a product base table, product detail table, shop table, backpack table. If the scalability is stronger, the corresponding double table is less.
The problem with the table is simple. The point is what's the use of this item. The source of such goods, a lot of data, the direction of the goods, is a lot of data.
Finally, the data has to be circled in a circle.
It's a difficult thing to circle around. Especially when the features and props are up. The difficulty is 2 of the n-th side.

Before you circle, if you are more proficient in design mode. Then this process can be simplified. The difficulty is changed from 2 of the N times to 1.
Only need to have controller, event factory, abstract props factory These three virtual classes, plus timers, Task Editor, these two general classes. To build a robust, high-scale webgame.
In Webgame the controller can be almost identical to the page. Casually adopt a template technology that can be very convenient processing.
Event Factory is an abstract class, where all events such as working, fighting, moving, etc. are produced by the event factory. And the same interface, convenient controller control. Factory mode.
Abstract props Factory is an abstract class, all props, such as cities, maps, equipment, etc., are produced by the abstract props factory. And the same interface, Factory mode, the combination of events and props is a bridging mode.

Art:
Ui. Simple and beautiful interface is always good. Small icons. Props, maps, equipment. A class of at least 10? In general, hundreds of them are needed.
The program is divided into 5 parts:
Server timers. (The C language or the server you set) periodically loops through a piece of code. This code is mainly based on data from the database to update. This can be done by a C-language programmer. For C-language programmers, this feature is fairly straightforward. Of course, the specific processing data of the judgment and operation of the database, you need to write your own. Let the C-language programmer give you a piece of standard code on the line. Full support for SQL statements.
PHP, you can configure the corn implementation. But no matter what the operating system, the minimum configured time is 1 minutes. So, if you're going to handle a 1-second refresh situation. You also need a dedicated timer program to handle, or the PHP that is timed to be executed will need to include sleep (). Of course, even with instant interaction, it can be done regardless of the server side. Handles only the client side of the interaction. JS and Ajax implementations.
Feature pages, function functions. The main data access, judgment, data trends.
The use of abstract classes, it will be more relaxed. But the explosion of the sub-category is unavoidable.
Ajax functions. (optional) Some features that need to be pseudo-instant are used.
To make the game look cool. Use it.
JavaScript functions. Optionally, simulate the data calculation for the client. This is webgame time-related data. is divided into two parts. Part of this is real data, which is calculated by the server-side timer. The other part is only the initial value that the client displays. No immediate synchronization is required, just a simulation of synchronization is required.
It also includes some nice UI effects. After all, it's a game.
Database. A large pile of basic data tables and detailed data tables. Base data table: For example, the attribute initial value of a user of level 1 to level 100. Detail Data Sheet: The specific properties of each user.
Database, and try to optimize it. The structure can use 1 bytes of 2 bytes.

second a detailed example.
It is painful to simply discuss the data flow.
It is more painful to discuss the procedure without giving the code.
The Php+mysql is used here. At the same time, this example does not use a class. If time is good, at the end of this year, I will provide a simple webgame code with instant interaction and a core class to illustrate the benefits of using design patterns.
Let's discuss it in a super-simple webgame way. With the appropriate code. should be helpful. The shortage of places also please point out that for me personally also help.
We do not consider the game's playability, numerical balance and so on. Let's consider the implementation of a simple example first.
So what does the basic content of a webgame need?
Databases: Players, maps, cities, buildings, weapons, soldiers.
Features: Landing, upgrading, personal fighting, fighting between soldiers, fighting with cities, building buildings, building weapons, buying and selling props.
(Note: Each function must correspond to 1 or more data tables.) The database listed above is only the basis of the foundation. )
The first is the map, the city, the building.
It is thought that the map can have more than one, the city on the map, the building in the city.
Ground chart
map:map_id, x-coordinate, y-coordinate, city_id (city ID), description.
Where map_id refers to the ID of the map. is not auto-numbered. A map is a map_id that can be repeated.
City table
city:city_id, city name, city owner, city rank, city resource, description.
Building tables
build:id,city_id, building name, building grade, building function.
Among them, the map table determines the location of the city, the city table determines the relevant data of the city, as well as all people, the construction of the table in a number of information belongs to a city.
After the table is built, it is displayed.
A For loop. Take the entire chart out of the ground to be OK.
It's not much different from the news list on a regular site. The difference is that you need to get the x-coordinate and y-coordinate positioning. Can use Tabel can also use Div.


Code
Copy CodeThe code is as follows:
Class map//Map Classes
{
var $Map _id;
function Map_bg_css ($Map _id) {

$this->map_id = $Map _id;

mysql_select_db ($db _name, $link);
$sql = "SELECT * from map where map_id= '". $this->map_id. "' Limit 1 ';
$result =mysql_query ($sql, $link);
echo "

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.