当前位置: 首页>>代码示例>>C++>>正文


C++ Fleet::getKillPercent方法代码示例

本文整理汇总了C++中Fleet::getKillPercent方法的典型用法代码示例。如果您正苦于以下问题:C++ Fleet::getKillPercent方法的具体用法?C++ Fleet::getKillPercent怎么用?C++ Fleet::getKillPercent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Fleet的用法示例。


在下文中一共展示了Fleet::getKillPercent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: onChangeTurn

void GameController::onChangeTurn()
{
  currentTurn++;

  /* impose production on owned planets */
  for(int i=0; i<players.size(); i++)
    {
      Player* tempP = players[i];
      for(int j=0; j<players[i]->getPlanets().size(); j++)
	{
	  Planet* tempPl = tempP->getPlanets()[j];
	  tempPl->setShips( tempPl->getShips() +  tempPl->getProduction());
	}
    }

  for(int k=0; k<fleets.size(); k++)
    {
      Fleet* tempF = fleets[k];
      /* fleet has arrived */
      if(fleets[k]->getArrivalTurn() == currentTurn)
	{
	  /* fleet owner same as destination owner, so reinforcing a planet */
	  if(tempF->getOwner() == tempF->getDestination()->getOwner())
	    {
	      tempF->getDestination()->setShips(tempF->getDestination()->getShips() + tempF->getNumShips());
	    }
	  else /* attacking planet */
	    {
	      double attackScore, defenseScore;

	      attackScore = tempF->getNumShips()*tempF->getKillPercent();
	      defenseScore = tempF->getDestination()->getShips()*tempF->getDestination()->getKillPercent();

	      if(attackScore >= defenseScore) /* attackers win */
		{
		  if(tempF->getDestination()->getOwner() != NULL)
		    tempF->getDestination()->getOwner()->removeFromPlanets(tempF->getDestination());

		  tempF->getOwner()->addToPlanets(tempF->getDestination());
		  tempF->getDestination()->setOwner(tempF->getOwner());
		  
		  tempF->getDestination()->setShips((int)attackScore-defenseScore);
		  emit displayInfo(QString("Turn %1: Planet %2 has fallen to %3").arg(currentTurn).arg(tempF->getDestination()->getName()).arg(tempF->getOwner()->getName()));
		  
		}
	      else /* defense wins */
		{
		  tempF->getDestination()->setShips((int)defenseScore-attackScore);
		  emit displayInfo(QString("Turn %1: Planet %2 has held against an attack from %3.").arg(currentTurn).arg(tempF->getDestination()->getName()).arg(tempF->getOwner()->getName()));
		}
	    }
	  /* processed fleet, so remove it */
	  fleets.removeAt(k);
	}
    }
     

  if(currentPlayer < players.size() - 1)
    currentPlayer++;
  else
    currentPlayer = 0;

  emit displayControl(QString("<font color=%1>%2</font>:Select source planet").arg(players[currentPlayer]->getColor().name()).arg(players[currentPlayer]->getName()));
}
开发者ID:alaasalman,项目名称:spaceexplorer,代码行数:64,代码来源:GameController.cpp


注:本文中的Fleet::getKillPercent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。