本文整理汇总了C++中Country::SetOwner方法的典型用法代码示例。如果您正苦于以下问题:C++ Country::SetOwner方法的具体用法?C++ Country::SetOwner怎么用?C++ Country::SetOwner使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Country
的用法示例。
在下文中一共展示了Country::SetOwner方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadFromFile
//this method will be used in 2 seperate occasions, one when the user wants to load a map
//the other when the user wants to load a game in progress, hence the boolean parameter
World* World::LoadFromFile(std::string fileName, bool loadInProgress) {
std::ifstream in(fileName);
World* world = new World(fileName);
std::string line;
//making use of maps for loading process
std::map<std::string, Continent*> continentMap;
std::map<std::string, Country*> countryMap;
while (std::getline(in, line)) {
if (line.find("[World]") != std::string::npos)
continue;
if (line.find("continent") != std::string::npos) {
int continentStart = (int)line.find("\"") + 1;
int continentEnd = (int)line.find("\"", continentStart) - 1;
int controlValueStart = continentEnd + 3;
std::string continentName = line.substr(continentStart, continentEnd - continentStart + 1);
int controlValue = atoi(line.substr(controlValueStart).c_str());
Continent* continent = new Continent(continentName, controlValue);
continentMap[continentName] = continent;
world->AddContinent(continent);
}
else if (line.find("country") != std::string::npos) {
int countryStart = (int)line.find("\"") + 1;
int countryEnd = (int)line.find("\"", countryStart) - 1;
int continentStart = countryEnd + 4;
int continentEnd = (int)line.find("\"", continentStart) - 1;
std::string countryName = line.substr(countryStart, countryEnd - countryStart + 1);
std::string continentName = line.substr(continentStart, continentEnd - continentStart + 1);
Country* country = new Country(countryName);
//this if will only be accessed when loading in progress, this will load the information of the country
//concerning the player owning it as well as the army count.
if (loadInProgress) {
int playerNameStart = continentEnd + 4;
int playerNameEnd = (int)line.find("\"", playerNameStart) - 1;
std::string playerName = line.substr(playerNameStart, playerNameEnd - playerNameStart + 1);
int army = atoi(line.substr(playerNameEnd + 2).c_str());
for (Player* player : RiskGame::Instance().GetPlayers()) {
if (player->GetName() == playerName) {
country->SetOwner(player);
player->AddOwnedCountry(country);
}
}
country->SetArmy(army);
}
countryMap[countryName] = country;
continentMap[continentName]->AddCountry(country);
}
else if (line.find("connection") != std::string::npos) {
int countryStart = (int)line.find("\"") + 1;
int countryEnd = (int)line.find("\"", countryStart) - 1;
int connectionsStart = countryEnd + 4;
int connectionsEnd = (int)line.length() - 3;
std::string countryName = line.substr(countryStart, countryEnd - countryStart + 1);
std::string connectionsNames = line.substr(connectionsStart, connectionsEnd - connectionsStart + 1);
std::string currentConnection;
std::istringstream ss(connectionsNames);
while (std::getline(ss, currentConnection, ',')) {
Country::Connect(countryMap[countryName], countryMap[currentConnection]);
}
}
}
in.close();
return world;
}