本文整理汇总了C++中Planet::getDistanceTo方法的典型用法代码示例。如果您正苦于以下问题:C++ Planet::getDistanceTo方法的具体用法?C++ Planet::getDistanceTo怎么用?C++ Planet::getDistanceTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Planet
的用法示例。
在下文中一共展示了Planet::getDistanceTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processOrders
//.........这里部分代码省略.........
tokens.erase(tokens.begin());
if (tokens.size() == 4 && tokens[0] == "planet") {
int planetId = atoi(tokens[1].c_str());
const std::string& name = tokens[2];
const std::string& value = tokens[3];
Planet* planet = m_planets[planetId];
planet->setProperty(name, value);
}
continue;
}
std::vector<std::string> tokens = Tokenize(line, " ");
//Check whether the player bot output a bad thing.
if (3 != tokens.size()) {
std::stringstream message;
message << "Error on line " << i << " of stdout output; expected 3 tokens on a move order line, have "
<< tokens.size() << ".";
player->logError(message.str());
return false;
}
const int sourcePlanetId = atoi(tokens[0].c_str());
const int destinationPlanetId = atoi(tokens[1].c_str());
const int numShips = atoi(tokens[2].c_str());
//Check whether the player has made any illegal moves.
const int numPlanets = static_cast<int>(m_planets.size());
if (sourcePlanetId < 0 || sourcePlanetId >= numPlanets) {
std::stringstream message;
message << "Error on line " << i << " of stdout output. Source planet "
<< sourcePlanetId << " does not exist.";
player->logError(message.str());
return false;
}
if (destinationPlanetId < 0 || destinationPlanetId >= numPlanets) {
std::stringstream message;
message << "Error on line " << i << " of stdout output. Destination planet "
<< destinationPlanetId << " does not exist.";
player->logError(message.str());
return false;
}
if (sourcePlanetId == destinationPlanetId) {
std::stringstream message;
message << "Error on line " << i
<< " of stdout output. Source planet and destination planet are the same. ";
player->logError(message.str());
return false;
}
Planet* sourcePlanet = m_planets[sourcePlanetId];
Planet* destinationPlanet = m_planets[destinationPlanetId];
if (sourcePlanet->getOwner()->getId() != player->getId()) {
std::stringstream message;
message << "Error on line " << i << " of stdout output. Source planet "
<< destinationPlanetId << " does not belong to this player.";
player->logError(message.str());
return false;
}
if (numShips > sourcePlanet->getNumShips() || numShips < 0) {
std::stringstream message;
message << "Error on line " << i << " of stdout output. Cannot send " << numShips
<< " ships from planet " << sourcePlanetId
<< ". Planet has " << sourcePlanet->getNumShips() << " ships.";
player->logError(message.str());
return false;
}
sourcePlanet->setNumShips(sourcePlanet->getNumShips() - numShips);
//Create a new fleet.
Fleet* fleet = new Fleet(this);
fleet->setOwner(player);
fleet->setSource(sourcePlanet);
fleet->setDestination(destinationPlanet);
fleet->setNumShips(numShips);
const int distance = sourcePlanet->getDistanceTo(destinationPlanet);
fleet->setTotalTripLength(distance);
fleet->setTurnsRemaining(distance);
m_newFleets.push_back(fleet);
m_fleets.push_back(fleet);
}
if (!foundGo) {
std::stringstream message;
message << "Error: player did not send \"go\" within allotted time.";
player->logError(message.str());
return false;
}
return true;
}