本文整理汇总了C++中World::AddContinent方法的典型用法代码示例。如果您正苦于以下问题:C++ World::AddContinent方法的具体用法?C++ World::AddContinent怎么用?C++ World::AddContinent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类World
的用法示例。
在下文中一共展示了World::AddContinent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateTestMap
//default map, hard coded, mostly used for testing as well as to play the game without creating a new map.
World* World::CreateTestMap() {
World* world = new World("Default.map");
Continent* north_america = new Continent("North America", 9);
//creating all the countries in NA
Country* alaska = new Country("Alaska");
Country* northwest_territory = new Country("Northwest Territory");
Country* alberta = new Country("Alberta");
Country* ontario = new Country("Ontario");
Country* greenland = new Country("Greenland");
Country* eastern_canada = new Country("Eastern Canada");
Country* western_united_states = new Country("Western United States");
Country* eastern_united_states = new Country("Eastern United States");
Country* central_america = new Country("Central America");
//creating all the edges between the countries in the NA
Country::Connect(alaska, northwest_territory);
Country::Connect(alaska, alberta);
Country::Connect(northwest_territory, alberta);
Country::Connect(northwest_territory, ontario);
Country::Connect(northwest_territory, greenland);
Country::Connect(alberta, ontario);
Country::Connect(alberta, western_united_states);
Country::Connect(ontario, greenland);
Country::Connect(ontario, eastern_canada);
Country::Connect(ontario, eastern_united_states);
Country::Connect(ontario, western_united_states);
Country::Connect(eastern_canada, eastern_united_states);
Country::Connect(eastern_canada, greenland);
Country::Connect(eastern_united_states, western_united_states);
Country::Connect(eastern_united_states, central_america);
Country::Connect(western_united_states, central_america);
//adding all the country of NA to continent north_america
north_america->AddCountry(alaska);
north_america->AddCountry(northwest_territory);
north_america->AddCountry(alberta);
north_america->AddCountry(ontario);
north_america->AddCountry(greenland);
north_america->AddCountry(eastern_canada);
north_america->AddCountry(eastern_united_states);
north_america->AddCountry(western_united_states);
north_america->AddCountry(central_america);
//adding north_america to the map
world->AddContinent(north_america);
Continent* south_america = new Continent("South America", 4);
//creating all the countries in SA
Country* venezuela = new Country("Venezuela");
Country* brazil = new Country("Brazil");
Country* peru = new Country("Peru");
Country* argentina = new Country("Argentina");
//creating all of the edges between the countries in SA
Country::Connect(central_america, venezuela);
Country::Connect(venezuela, peru);
Country::Connect(venezuela, brazil);
Country::Connect(brazil, peru);
Country::Connect(brazil, argentina);
Country::Connect(argentina, peru);
//adding all the countries in SA to south_america continent
south_america->AddCountry(venezuela);
south_america->AddCountry(brazil);
south_america->AddCountry(peru);
south_america->AddCountry(argentina);
//adding south_america to the world map
world->AddContinent(south_america);
Continent* europe = new Continent("Europe", 7);
//creating all the countries in Europe
Country* iceland = new Country("Iceland");
Country* great_britain = new Country("Great Britain");
Country* western_europe = new Country("Western Europe");
Country* scandinavia = new Country("Scandinavia");
Country* northern_europe = new Country("Northern Europe");
Country* southern_europe = new Country("Southrern Europe");
Country* russia = new Country("Russia");
//creating all the edges between the europe countries
Country::Connect(greenland, iceland);
Country::Connect(iceland, great_britain);
Country::Connect(iceland, scandinavia);
Country::Connect(great_britain, scandinavia);
Country::Connect(great_britain, western_europe);
Country::Connect(great_britain, northern_europe);
Country::Connect(western_europe, southern_europe);
Country::Connect(western_europe, northern_europe);
Country::Connect(scandinavia, russia);
Country::Connect(scandinavia, northern_europe);
Country::Connect(northern_europe, southern_europe);
Country::Connect(northern_europe, russia);
Country::Connect(southern_europe, russia);
//.........这里部分代码省略.........
示例2: 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;
}