PHP webpage game learning-Explanation of Xnova (ogame) source code (15th) _ php instance

Source: Internet
Author: User
This article mainly introduces how to process the fleet activity page of PHP Web Game Xnova (ogame) source code. If you need it, refer to the following October 18 and fleet activity (FlyingFleetHandler. php)

In the previous article, we have initially studied the source code of the fleet activity and mentioned the triggering of the fleet activity. Now I will further analyze the Xnova fleet activities, which are essentially triggered by players rather than timer computing. The triggering of fleet activities is carried out in common. php, so the entry is in this file, and the code is as follows:

// Check whether there is a fleet $ _ fleets = doquery ("SELECT * FROM {table} WHERE 'fleet _ start_time '<= '". time (). "';", 'fleets'); // OR fleet_end_time <= ". time () // cyclically process each fleet while ($ row = mysql_fetch_array ($ _ fleets) {$ array = array (); $ array ['galaxy '] = $ row ['fleet _ start_galaxy']; $ array ['system'] = $ row ['fleet _ start_system ']; $ array ['Planet '] = $ row ['fleet _ start_planet']; $ array ['Planet _ type'] = $ row ['fleet _ start_type ']; // fleet handler function $ temp = FlyingFleetHandler ($ array );} // check whether the ship $ _ fleets = doquery ("SELECT * FROM {table} WHERE 'fleet _ end_time '<='" is returned '". time (). "';", 'fleets'); // OR fleet_end_time <= ". time () // cyclically process each fleet while ($ row = mysql_fetch_array ($ _ fleets) {$ array = array (); $ array ['galaxy '] = $ row ['fleet _ end_galaxy']; $ array ['system'] = $ row ['fleet _ end_system ']; $ array ['Planet '] = $ row ['fleet _ end_planet']; $ array ['Planet _ type'] = $ row ['fleet _ end_type ']; // fleet handler function $ temp = FlyingFleetHandler ($ array );}

As you can see, the previous code is actually not well written, because it is called every time and the efficiency is too low. Therefore, we can optimize it here so that each loop only needs the ID of a fleet to be passed to the function. The corresponding function also needs to be modified and you can modify it as you like.

Next let's take a look at the function FlyingFleetHandler (), which is a function that calls the fleet activity in a centralized manner.

// LOCK the TABLE to prevent data synchronization and other problems. doquery ("LOCK table {table} lunas WRITE, {TABLE} rw WRITE, {table} errors WRITE, {table} messages WRITE, {table} fleets WRITE, {table} planets WRITE, {table} galaxy WRITE, {table} users WRITE "," "); // a large segment here is to obtain the fleet array. The parameter can use the Fleet ID, optimized $ QryFleet = "SELECT * FROM {table}"; $ QryFleet. = "WHERE ("; $ QryFleet. = "("; $ QryFleet. = "'fleet _ start_galaxy '= ". $ planet ['galaxy ']. "AND"; $ QryFleet. = "'fleet _ start_system '= ". $ planet ['system']. "AND"; $ QryFleet. = "'fleet _ start_planet '= ". $ planet ['Planet ']. "AND"; $ QryFleet. = "'fleet _ start_type '= ". $ planet ['Planet _ type']. ""; $ QryFleet. = ") OR ("; $ QryFleet. = "'fleet _ end_galaxy '= ". $ planet ['galaxy ']. "AND"; $ QryFleet. = "'fleet _ end_system '= ". $ planet ['system']. "AND"; $ QryFleet. = "'fleet _ end_planet '= ". $ planet ['Planet ']. ") AND"; $ QryFleet. = "'fleet _ end_type '= ". $ planet ['Planet _ type']. ") AND"; $ QryFleet. = "('fleet _ start_time '<'". time (). "'OR 'fleet _ end_time' <'". time (). "');"; $ fleetquery = doquery ($ QryFleet, 'fleets'); // varies depending on the purpose of the fleet activity, go to different function processing while ($ CurrentFleet = mysql_fetch_array ($ fleetquery) {switch ($ CurrentFleet ["fleet_mission"]) {case 1: // MissionCaseAttack ($ CurrentFlee T); break; case 2: // This should be an ACS attack or another attack, however, doquery ("delete from {table} WHERE 'fleet _ id' = '" is not used now '". $ CurrentFleet ['fleet _ id']. "';", 'fleets'); break; case 3: // transport MissionCaseTransport ($ CurrentFleet); break; case 4: // dispatch MissionCaseStay ($ CurrentFleet); break; case 5: // joint dispatch, that is, ACS defense MissionCaseStayAlly ($ CurrentFleet); break; case 6: // detects MissionCaseSpy ($ CurrentFleet); break; case 7: // colonial MissionCaseColonisation ($ CurrentFleet); break; case 8: // reclaim MissionCaseRecycling ($ CurrentFleet); break; case 9: // destroy the month, missionCaseDestruction ($ CurrentFleet); break; case 10: // retained !! Break; case 15: // expedition, adventure missioncaseincludition ($ CurrentFleet); break; // Delete the fleet in other cases. This is a good habit of default: {doquery ("delete from {table} WHERE 'fleet _ id' = '". $ CurrentFleet ['fleet _ id']. "';", 'fleets') ;}}// UNLOCK table doquery ("unlock tables ","");

The above function structure is clear, the code is clear, and the comments are also very clear.

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.