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


C++ Country::SetOwner方法代码示例

本文整理汇总了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;
}
开发者ID:Harbus,项目名称:Risk,代码行数:65,代码来源:World.cpp


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