Php Web Game Development tutorial 1 (webgame + design) _ php instance

Source: Internet
Author: User
Webgame development tutorial 1 webgame + design. For details, refer. 1. Simple Program Framework.
Webgame program composition:
Three major parts.
The first is the data process. The second is the program. The third is art.
The data flow includes functions. Data flows can only be reflected in functions.
The data process is quite troublesome and will be discussed later.
For example, the simplest product to sell.
To implement this function.
The basic table of the product, detailed table of the product, store table, and catalog table are required. If the scalability is higher, the corresponding dual tables cannot be less.
Table problems are all simple. The key is how to use this item. In this way, the source of an item, a lot of data, the trend of the item, and a lot of data.
Finally, the data must be circled.
Circle is a difficult task. Especially when there are more functions and items. The difficulty is the Npower of 2.

If you are familiar with the design mode before bypassing the circle. This process can be simplified. The difficulty is changed from the Npower of 2 to 1.
You only need to have three virtual classes: controller, event factory, and abstract prop factory. With the addition of timer and task Editor, these two general classes are used. You can build a robust and highly scalable webgame.
In webgame, controllers are almost equivalent to pages. It is convenient to use a template technology.
The event factory is an abstract class. All events, such as working, fighting, and moving, are produced by the event factory. The interfaces are the same to facilitate the controller control. Factory mode.
Abstract item factory is an abstract class. All items, such as cities, maps, and equipment, are produced by abstract item factory. In addition, the interface is the same, the factory mode, and the combination of events and items is a bridge mode.

Art:
UI. Simple and beautiful interfaces will always benefit. Small icon. Item, map, and equipment. Should there be at least 10 in a category? Generally, hundreds of requests are required.
The program consists of five parts:
Server timer. (C language or self-configured server) Periodically executes a piece of code. This code is mainly updated based on the database data. This can be done by a C-language programmer. For C programmers, this function is quite simple. Of course, you need to write your own data processing judgment and database operations. Let the C language programmers give you standard code. Fully supports SQL statements.
You can configure the corn implementation for php. However, no matter what operating system, the minimum configuration time is 1 minute. Therefore, if you want to refresh once every second. You also need a dedicated Timer Program for processing, or the regularly executed php needs to contain sleep (). Of course, even if there is instant interaction, you can ignore the server side. Only clients on both sides of the interaction are processed. Js and ajax implementations.
Function page and function. It mainly refers to data access, judgment, and data trend.
It is easier to use abstract classes. However, subclass explosion is indispensable.
Ajax functions. Optional. Some functions that require pseudo-instant processing are required.
To make the game look cool. Use it.
Javascript Functions. (Optional) simulate data computing on the client. That is, time-related data of webgame. It is divided into two parts. Some of them are real data and are calculated by the server timer. The other part is only the initial value, which is displayed on the client. Instant synchronization is not required. You only need to simulate synchronization.
Some nice UI effects are also included. After all, it is a game.
Database. A large number of basic data tables and detailed data tables. Basic data table: for example, the initial attribute values of users from grade 1 to grade 100. Detailed data table: the specific attributes of each user.
Optimize the database as much as possible. If the structure can use 1 byte, do not use 2 bytes.

2. A detailed example.
Simply discussing the data process is a pain point.
Discussing programs without code is also a pain point.
Php + mysql is used here. Classes are not used in this example. If you have enough time, at the end of this year, I will provide a simple webgame code and core class with instant interaction to illustrate the benefits of using the design pattern.
We will discuss it in a simple webgame method. With appropriate code. It should be helpful. Please note that it is also helpful to me.
We don't consider the game playability, numerical balance, and so on. We will first consider the implementation of a simple example.
So what is the basic content of a webgame?
Database: players, maps, cities, buildings, weapons, soldiers.
Features: Login, upgrade, personal combat, fighting between soldiers, fighting with the city, building, creating weapons, and buying and selling items.
(Note: each function must correspond to one or more data tables. What is listed in the above database is only the basis of the Basic .)
First, maps, cities, and buildings.
It is believed that there can be multiple maps. The city is on the map and the building is in the city.
GEO chart
Map: Map_ID, X, Y, City_ID (city ID), description.
Map_ID indicates the id of the map. It is not an automatic number. A map is a Map_ID, which can be repeated.
City table
City: City_ID, City name, City owner, City level, City resource, description.
Building table
Build: ID, City_ID, Building Name, building grade, building function.
The GEO chart determines the location of the city, the city table determines the relevant data of the city and the owner, and multiple pieces of information in the building table belong to a city.
After the table is created, it is displayed.
A for loop. It is OK to retrieve the whole geo chart.
It is not much different from the news list of a common website. The difference is that you need to obtain the X and Y coordinates for positioning. You can use tabel or p.


Code

The Code is as follows:


Class Map // Map class
{
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.