PHP web game learning-Xnova (ogame) source code explanation (15th) _ PHP Tutorial

Source: Internet
Author: User
PHP web game learning-Xnova (ogame) source code explanation (15th ). 18. FlyingFleetHandler. php previously we had a preliminary study of the source code of the fleet activity and mentioned the triggering of the fleet activity. Now I will further analyze the Xnova October 18 and fleet activities (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.

In the previous articles, we 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...

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.