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

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

WBOY
Release: 2016-07-13 10:26:05
Original
860 people have browsed it

13. Construction Overview (buildings.php)

Starting from this article, the research on xnova focuses on the process, which is actually a large number of functions; the structure of the page will not be explained in detail.

The buildings.php file not only deals with construction, metals and minerals, but also includes four functions: construction, research, shipyards, and defense. It determines which function to enter by passing different parameters, so this file is actually a navigation file. . Below we briefly explain this file.

//更新当前星球的建筑队列,比较复杂
UpdatePlanetBatimentQueueList ( $planetrow, $user );
//处理当前用户的科技研究
HandleTechnologieBuild ( $planetrow, $user );
//下面是根据参数进入不同的功能页面
//造船厂页面
case 'fleet':
FleetBuildingPage ( $planetrow, $user );
//研究页面
case 'research':
ResearchBuildingPage ( $planetrow, $user, $IsWorking['OnWork'], $IsWorking['WorkOn'] );
//防御页面
case 'defense':
DefensesBuildingPage ( $planetrow, $user );
//剩下的自然是建筑页面
default:
BatimentBuildingPage ( $planetrow, $user ); 
下面我们看更新当前星球的建筑队列函数
function UpdatePlanetBatimentQueueList ( &$CurrentPlanet, &$CurrentUser ) {
 $RetValue = false;
 //判断是否有建筑队列,字段b_building_id保存建筑队列
 if ( $CurrentPlanet['b_building_id'] != 0 ) {
 //进入循环,开始处理队列
 while ( $CurrentPlanet['b_building_id'] != 0 ) {
  //如果当前建造的建筑时间小于time的话,就处理,字段b_building保存建筑到期的时间
  if ( $CurrentPlanet['b_building'] <= time() ) {
  //先更新下星球的资源,以后再解析
  PlanetResourceUpdate ( $CurrentUser, $CurrentPlanet, $CurrentPlanet['b_building'], false );
  //处理掉当前的建筑,并把当前建筑字段清空;代码很多,其实比较简单
  $IsDone = CheckPlanetBuildingQueue( $CurrentPlanet, $CurrentUser );
  //如果前面处理成功,这里就要处理队列中的下一个建筑,包括扣除资源
  if ( $IsDone == true ) {
   SetNextQueueElementOnTop ( $CurrentPlanet, $CurrentUser );
  }
  } else {
  $RetValue = true;
  break;
  }
 }
 }
 return $RetValue;
} 

Copy after login

Let’s continue and trace into the CheckPlanetBuildingQueue function. This function has a lot of code, but it’s actually simple; I won’t write comments and will talk about the process. First parse the type of building, construction or demolition, end of construction time, etc. from the field b_building_id; then update the level of the building, upgrade or downgrade; update the maximum space and usable space of the planet; update the time of the current building to 0 and update the current of the remaining construction queue. It's not difficult, haha.

Next, it is not difficult to process the next building in the queue and track the SetNextQueueElementOnTop function. First parse the building data from the queue; then determine whether it can be built, and if so, calculate the construction resources, etc.; if not, send a message, etc.; finally update the time when the building is completed, the remaining building queue and resources, etc. The process is as simple as above, get it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824836.htmlTechArticle 13. Construction Overview (buildings.php) Starting from this article, the research on xnova focuses on the process The above is actually a large number of functions; as for the structure of the page, I will not explain it in detail...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template