本文整理汇总了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()));
}