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


C++ Weapon::read_txt_properties方法代码示例

本文整理汇总了C++中Weapon::read_txt_properties方法的典型用法代码示例。如果您正苦于以下问题:C++ Weapon::read_txt_properties方法的具体用法?C++ Weapon::read_txt_properties怎么用?C++ Weapon::read_txt_properties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Weapon的用法示例。


在下文中一共展示了Weapon::read_txt_properties方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: read_weapons_txt

void Weapon::read_weapons_txt() {
    std::ifstream weapons_file("weapons.txt");
    std::string line;

    if (!weapons_file.is_open()) {
        log_file << "Unable to open weapons.txt" << std::endl;
        std::cerr << "Unable to open weapons.txt" << std::endl;
        return;
    }

    Weapon* weap;
    while (std::getline(weapons_file, line)) {
        if (line.front() == '#') continue;
        if (line.find_first_not_of(" \n\t\r") == std::string::npos) continue;   //if line is empty
        while (line.find(";") == std::string::npos) {   //line ends with semicolon
            std::string buffer_line = "";
            std::getline(weapons_file, buffer_line);
            line += buffer_line;
        }
        line.erase(line.find(";"));
        trimr_string(line); //erasing unnecessary from end
        if (line == "NEW_ITEM")
            weap = new Weapon();
        else if (line == "PUSH_ITEM") {
            LIST.insert(std::pair<std::string, Weapon>(weap->name, *weap));
            log_file << "Added new weapon to WEAPONS_LIST: " << weap->name << std::endl;
            delete weap;
            weap = nullptr;
        } else if (line.find("available_attacks") != std::string::npos) {
            line = take_value(line);
            for (auto& it : split_with_match_chars(line)) {
                it = it.substr(it.find('{') + 1, it.find('}') - 1);
                Attack::ptr attack;
                if (it.find("Ranged ::") != std::string::npos) {
                    it = it.substr(it.find("::") + 2);
                    attack = RangedAttack::ptr(new RangedAttack(weap, it));
                    weap->available_attacks.push_back(attack);
                } else if (it.find("Close ::") != std::string::npos) {
                    it = it.substr(it.find("::") + 2);
                    attack = CloseAttack::ptr(new CloseAttack(weap, it));
                    weap->available_attacks.push_back(attack);
                }
            }
        } else if (line.find("ammo") != std::string::npos) {
            for (auto& it : split_with_match_chars(take_value(line))) {
                Ammo new_ammo = {it.substr(it.find("{") + 1, it.find("}") - 1)};
                weap->ammo.insert({new_ammo.type, new_ammo});
            }
        } else if (line.find("hold_type") != std::string::npos) {
            line = take_value(line);
            if (line == "one_handed")
                weap->hold_type = one_handed;
            else if (line == "two_handed")
                weap->hold_type = two_handed;
        } else weap->read_txt_properties(line);
    }
    weapons_file.close();
}
开发者ID:koval4,项目名称:DarkAsteroids,代码行数:58,代码来源:weapon.cpp


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