c++异世界文字游戏

emm也是写了很久

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <windows.h>
#include <algorithm>
#include <cctype>

using namespace std;

// 颜色设置
void setColor(int color) {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}

// 清屏
void clearScreen() {
    system("cls");
}

// 暂停
void pause() {
    cout << "\n按任意键继续...";
    _getch();
}

// 职业枚举
enum class Profession {
    WARRIOR,        // 战士
    MAGE,           // 法师
    ARCHER,         // 弓箭手
    ROGUE,          // 盗贼
    CLERIC,         // 牧师
    SPELLSWORD,     // 魔剑士
    PALADIN,        // 圣骑士
    BATTLEMAGE,     // 战斗法师
    DRAGONKNIGHT,   // 龙骑士
    NECROMANCER,    // 死灵法师
    RANGER,         // 游侠
    ASSASSIN        // 刺客
};

// 技能结构体
struct Skill {
    string name;
    int level;
    int experience;
    int maxExperience;
    int baseDamage;
    int uses;
    bool isActive;  // 主动技能还是被动技能
    string description;
};

// 物品结构体
struct Item {
    string name;
    string type; // weapon, armor, material, consumable, skillbook, special
    int value;
    int attackBonus;
    int defenseBonus;
    vector<string> materials; // 锻造所需材料
    string skillTaught;       // 技能书教授的技能
    string requiredProfession;// 转职道具要求的职业
    string advancedProfession;// 转职道具可以转职的职业
};

// 怪物结构体
struct Monster {
    string name;
    int health;
    int attack;
    int defense;
    int experience;
    vector<string> drops;
    string region;
    bool isBoss;
};

// 宝箱结构体
struct TreasureChest {
    vector<string> commonDrops;
    vector<string> rareDrops;
    vector<string> epicDrops;
    int goldMin;
    int goldMax;
};

// 区域结构体
struct Region {
    string name;
    string description;
    vector<string> monsters;
    bool hasBoss;
    string bossName;
    bool hasTreasure;
    
    bool operator==(const Region& other) const {
        return name == other.name;
    }
};

// 游戏状态结构体
struct GameState {
    string playerName;
    Profession profession;
    Profession previousProfession; // 用于转职后保留部分原职业技能
    int level;
    int experience;
    int maxExperience;
    int health;
    int maxHealth;
    int attack;
    int defense;
    int gold;
    vector<Skill> skills;
    vector<Item> inventory;
    vector<Item> equipment;
    vector<string> unlockedAchievements;
    map<string, int> materials;
    string currentLocation;
    int daysPassed;
    bool hasDiscoveredBoss[12]; // 对应12个区域是否有发现boss
};

// 全局游戏状态
GameState gameState;

// 全局数据
map<string, string> achievements = {
    {"first_kill", "第一滴血:击败第一个怪物"},
    {"level_10", "资深冒险者:达到10级"},
    {"level_20", "传奇冒险者:达到20级"},
    {"skill_master", "技能大师:有一个技能达到5级"},
    {"craftsman", "工匠:第一次锻造装备"},
    {"legendary_craftsman", "传奇工匠:锻造出隐藏装备"},
    {"explorer", "探索者:访问所有区域"},
    {"rich", "富豪:累积获得5000金币"},
    {"monster_slayer", "怪物杀手:击败所有类型的怪物"},
    {"boss_slayer", "屠龙者:击败第一个首领"},
    {"dragon_slayer", "屠龙勇士:击败魔龙"},
    {"class_master", "职业大师:完成一次转职"},
    {"treasure_hunter", "宝藏猎人:打开第一个宝箱"},
    {"skill_learner", "博学者:学习5个技能"}
};

map<Profession, string> professionNames = {
    {Profession::WARRIOR, "战士"},
    {Profession::MAGE, "法师"},
    {Profession::ARCHER, "弓箭手"},
    {Profession::ROGUE, "盗贼"},
    {Profession::CLERIC, "牧师"},
    {Profession::SPELLSWORD, "魔剑士"},
    {Profession::PALADIN, "圣骑士"},
    {Profession::BATTLEMAGE, "战斗法师"},
    {Profession::DRAGONKNIGHT, "龙骑士"},
    {Profession::NECROMANCER, "死灵法师"},
    {Profession::RANGER, "游侠"},
    {Profession::ASSASSIN, "刺客"}
};

map<Profession, vector<Skill>> professionSkills = {
    {Profession::WARRIOR, {
        {"强力斩击", 1, 0, 100, 15, 0, true, "强力斩击敌人,造成物理伤害"},
        {"盾牌猛击", 1, 0, 100, 10, 0, true, "用盾牌猛击敌人,有几率眩晕"},
        {"战斗怒吼", 1, 0, 100, 0, 0, true, "提升自身攻击力"}
    }},
    {Profession::MAGE, {
        {"火球术", 1, 0, 100, 20, 0, true, "发射火球攻击敌人"},
        {"冰霜新星", 1, 0, 100, 15, 0, true, "冰冻周围敌人"},
        {"魔法护盾", 1, 0, 100, 0, 0, true, "用魔法能量保护自己"}
    }},
    {Profession::ARCHER, {
        {"精准射击", 1, 0, 100, 18, 0, true, "瞄准敌人弱点射击"},
        {"多重箭", 1, 0, 100, 12, 0, true, "同时射出多支箭矢"},
        {"闪避", 1, 0, 100, 0, 0, true, "提高闪避几率"}
    }},
    {Profession::ROGUE, {
        {"背刺", 1, 0, 100, 25, 0, true, "从背后攻击敌人,造成暴击伤害"},
        {"毒刃", 1, 0, 100, 10, 0, true, "在武器上涂毒,造成持续伤害"},
        {"潜行", 1, 0, 100, 0, 0, true, "进入潜行状态"}
    }},
    {Profession::CLERIC, {
        {"神圣打击", 1, 0, 100, 12, 0, true, "用神圣力量攻击敌人"},
        {"治疗术", 1, 0, 100, 0, 0, true, "恢复生命值"},
        {"祝福", 1, 0, 100, 0, 0, true, "提升队友属性"}
    }},
    {Profession::SPELLSWORD, {
        {"魔法剑", 1, 0, 100, 18, 0, true, "将魔法注入剑中攻击"},
        {"元素护甲", 1, 0, 100, 0, 0, true, "用元素能量强化护甲"},
        {"剑刃风暴", 1, 0, 100, 25, 0, true, "快速旋转攻击周围敌人"}
    }},
    {Profession::PALADIN, {
        {"神圣之锤", 1, 0, 100, 20, 0, true, "用神圣之锤打击敌人"},
        {"神圣护盾", 1, 0, 100, 0, 0, true, "召唤神圣护盾保护自己"},
        {"净化", 1, 0, 100, 0, 0, true, "驱散负面效果"}
    }},
    {Profession::BATTLEMAGE, {
        {"奥术冲击", 1, 0, 100, 22, 0, true, "释放奥术能量冲击敌人"},
        {"魔法武器", 1, 0, 100, 0, 0, true, "临时增强武器威力"},
        {"能量爆发", 1, 0, 100, 30, 0, true, "释放体内所有魔法能量"}
    }},
    {Profession::DRAGONKNIGHT, {
        {"龙息", 1, 0, 100, 25, 0, true, "释放龙息攻击前方敌人"},
        {"龙鳞护甲", 1, 0, 100, 0, 0, true, "召唤龙鳞保护自己"},
        {"龙之怒", 1, 0, 100, 40, 0, true, "释放巨龙之力"}
    }},
    {Profession::NECROMANCER, {
        {"死亡之触", 1, 0, 100, 18, 0, true, "用死亡能量攻击敌人"},
        {"召唤骷髅", 1, 0, 100, 0, 0, true, "召唤骷髅战士"},
        {"生命吸取", 1, 0, 100, 15, 0, true, "吸取敌人生命"}
    }},
    {Profession::RANGER, {
        {"穿甲箭", 1, 0, 100, 20, 0, true, "穿透敌人护甲的箭矢"},
        {"野兽伙伴", 1, 0, 100, 0, 0, true, "召唤野兽伙伴协助战斗"},
        {"自然治愈", 1, 0, 100, 0, 0, true, "利用自然力量治疗"}
    }},
    {Profession::ASSASSIN, {
        {"致命一击", 1, 0, 100, 35, 0, true, "对敌人造成致命伤害"},
        {"毒云", 1, 0, 100, 10, 0, true, "释放毒雾伤害周围敌人"},
        {"暗影步", 1, 0, 100, 0, 0, true, "瞬间移动到敌人背后"}
    }}
};

vector<Item> allItems = {
    // 基础装备
    {"木剑", "weapon", 50, 5, 0, {}},
    {"铁剑", "weapon", 150, 10, 0, {"铁锭", "木材"}},
    {"钢剑", "weapon", 300, 15, 0, {"钢锭", "铁锭"}},
    {"皮甲", "armor", 80, 0, 5, {"皮革"}},
    {"锁子甲", "armor", 200, 0, 10, {"铁锭", "皮革"}},
    {"板甲", "armor", 400, 0, 15, {"钢锭", "铁锭"}},
    
    // 消耗品
    {"治疗药水", "consumable", 30, 0, 0, {}},
    {"魔力药水", "consumable", 30, 0, 0, {}},
    
    // 材料
    {"铁锭", "material", 20, 0, 0, {}},
    {"钢锭", "material", 40, 0, 0, {}},
    {"皮革", "material", 15, 0, 0, {}},
    {"木材", "material", 10, 0, 0, {}},
    {"魔法水晶", "material", 100, 0, 0, {}},
    {"龙鳞", "material", 500, 0, 0, {}},
    {"死灵粉尘", "material", 400, 0, 0, {}},
    
    // 特殊装备
    {"传说之剑", "weapon", 1000, 30, 5, {"钢锭", "魔法水晶", "龙鳞"}},
    {"死灵法杖", "weapon", 900, 25, 0, {"魔法水晶", "死灵粉尘"}},
    
    // 技能书
    {"火球术技能书", "skillbook", 200, 0, 0, {}, "火球术"},
    {"治疗术技能书", "skillbook", 200, 0, 0, {}, "治疗术"},
    {"背刺技能书", "skillbook", 200, 0, 0, {}, "背刺"},
    {"多重箭技能书", "skillbook", 200, 0, 0, {}, "多重箭"},
    {"神圣打击技能书", "skillbook", 200, 0, 0, {}, "神圣打击"},
    
    // 转职道具
    {"魔龙之血", "special", 0, 0, 0, {}, "", "WARRIOR", "DRAGONKNIGHT"},
    {"死灵粉尘", "special", 0, 0, 0, {}, "", "MAGE", "NECROMANCER"},
    {"圣光结晶", "special", 0, 0, 0, {}, "", "WARRIOR|CLERIC", "PALADIN"},
    {"奥术精华", "special", 0, 0, 0, {}, "", "MAGE|WARRIOR", "SPELLSWORD"},
    {"战斗法师手册", "special", 0, 0, 0, {}, "", "MAGE", "BATTLEMAGE"},
    {"游侠徽章", "special", 0, 0, 0, {}, "", "ARCHER", "RANGER"},
    {"刺客信条", "special", 0, 0, 0, {}, "", "ROGUE", "ASSASSIN"}
};

vector<Monster> monsters = {
    {"哥布林", 30, 8, 5, 20, {"皮革", "木材"}, "森林", false},
    {"狼", 40, 12, 6, 25, {"皮革"}, "森林", false},
    {"骷髅兵", 35, 10, 8, 22, {"铁锭"}, "墓地", false},
    {"巨蜘蛛", 50, 15, 5, 30, {"皮革", "毒腺"}, "洞穴", false},
    {"沙漠蝎子", 45, 18, 7, 28, {"甲壳"}, "沙漠", false},
    {"海盗", 60, 20, 10, 35, {"铁锭", "金币"}, "海岸", false},
    {"海妖", 80, 25, 12, 45, {"魔法水晶"}, "海洋", false},
    {"魔龙", 200, 50, 25, 150, {"龙鳞", "魔法水晶", "魔龙之血"}, "魔龙山脉", true},
    {"巫妖王", 180, 45, 20, 140, {"死灵粉尘", "魔法水晶"}, "亡灵墓穴", true},
    {"圣殿骑士", 160, 40, 22, 130, {"圣光结晶", "钢锭"}, "神圣殿堂", true},
    {"奥术守护者", 170, 42, 18, 135, {"奥术精华", "魔法水晶"}, "奥术高塔", true},
    {"暗影刺客", 150, 48, 15, 125, {"刺客信条", "毒腺"}, "暗影密林", true}
};

vector<Region> regions = {
    {"新手村", "一个和平的小村庄,适合新手冒险者", {"哥布林", "狼"}, false, "", true},
    {"黑暗森林", "茂密的森林,充满了危险的生物", {"哥布林", "狼", "巨蜘蛛"}, false, "", true},
    {"荒芜墓地", "阴森恐怖的墓地,不死生物游荡", {"骷髅兵"}, true, "巫妖王", false},
    {"炽热沙漠", "一望无际的沙漠,极端的气候", {"沙漠蝎子"}, false, "", true},
    {"海盗海岸", "海盗出没的危险海岸线", {"海盗"}, false, "", true},
    {"神秘海洋", "深不可测的海洋,隐藏着巨大生物", {"海妖"}, false, "", true},
    {"魔龙山脉", "传说中龙居住的活火山", {}, true, "魔龙", false},
    {"神圣殿堂", "神圣骑士团的根据地", {}, true, "圣殿骑士", false},
    {"奥术高塔", "充满魔法能量的高塔", {}, true, "奥术守护者", false},
    {"暗影密林", "盗贼和刺客的聚集地", {}, true, "暗影刺客", false},
    {"远古战场", "古代战争的遗迹", {"骷髅兵", "幽灵"}, false, "", true},
    {"魔法学院废墟", "废弃的魔法学院", {"魔法傀儡", "怨灵"}, false, "", true}
};

TreasureChest commonChest = {
    {"铁锭", "皮革", "木材"}, // 普通掉落
    {"钢锭", "魔法水晶"},     // 稀有掉落
    {"治疗药水", "魔力药水"}, // 史诗掉落
    50, 100                  // 金币范围
};

TreasureChest bossChest = {
    {"钢锭", "魔法水晶"},     // 普通掉落
    {"龙鳞", "死灵粉尘"},     // 稀有掉落
    {"传说之剑材料", "死灵法杖材料"}, // 史诗掉落
    200, 500                 // 金币范围
};

// 函数前置声明
void unlockAchievement(const string& achId);
void showStatus();
void levelUp();
int useSkill(Skill& skill);
void battle(Monster& monster);
void openTreasureChest(const TreasureChest& chest);
void exploreRegion(const Region& region);
void visitTown();
void visitShop();
void visitBlacksmith();
void visitAdventurersGuild();
void craftItem();
void changeProfession(const Item& item);
void gameLoop();
void mainMenu();

// 解锁成就
void unlockAchievement(const string& achId) {
    if (find(gameState.unlockedAchievements.begin(), gameState.unlockedAchievements.end(), achId) != gameState.unlockedAchievements.end()) {
        return;
    }
    
    gameState.unlockedAchievements.push_back(achId);
    
    setColor(14);
    cout << "\n成就解锁: " << achievements[achId] << "!\n";
    setColor(7);
    pause();
}

// 显示状态
void showStatus() {
    clearScreen();
    setColor(11);
    cout << "========== 角色状态 ==========\n";
    setColor(7);
    
    cout << "名称: " << gameState.playerName << "\n";
    cout << "职业: " << professionNames[gameState.profession] << "\n";
    cout << "等级: " << gameState.level << "\n";
    cout << "经验: " << gameState.experience << "/" << gameState.maxExperience << "\n";
    cout << "生命: " << gameState.health << "/" << gameState.maxHealth << "\n";
    cout << "攻击: " << gameState.attack << "\n";
    cout << "防御: " << gameState.defense << "\n";
    cout << "金币: " << gameState.gold << "\n";
    cout << "当前位置: " << gameState.currentLocation << "\n";
    
    setColor(11);
    cout << "\n========== 技能 ==========\n";
    setColor(7);
    for (Skill& skill : gameState.skills) {
        cout << skill.name << " Lv." << skill.level << " (" << skill.experience << "/" << skill.maxExperience << ")";
        if (skill.baseDamage > 0) {
            cout << " 伤害: " << skill.baseDamage * skill.level;
        }
        cout << "\n   " << skill.description << "\n";
    }
    
    setColor(11);
    cout << "\n========== 装备 ==========\n";
    setColor(7);
    if (gameState.equipment.empty()) {
        cout << "无\n";
    } else {
        for (Item& item : gameState.equipment) {
            cout << item.name;
            if (item.attackBonus > 0) cout << " 攻击+" << item.attackBonus;
            if (item.defenseBonus > 0) cout << " 防御+" << item.defenseBonus;
            cout << "\n";
        }
    }
    
    setColor(11);
    cout << "\n========== 材料 ==========\n";
    setColor(7);
    if (gameState.materials.empty()) {
        cout << "无\n";
    } else {
        for (auto& material : gameState.materials) {
            cout << material.first << ": " << material.second << "\n";
        }
    }
    
    setColor(11);
    cout << "\n========== 成就 ==========\n";
    setColor(7);
    if (gameState.unlockedAchievements.empty()) {
        cout << "尚未获得成就\n";
    } else {
        for (const string& ach : gameState.unlockedAchievements) {
            cout << "- " << achievements[ach] << "\n";
        }
    }
    
    pause();
}

// 升级检查
void levelUp() {
    if (gameState.experience >= gameState.maxExperience) {
        gameState.level++;
        gameState.experience -= gameState.maxExperience;
        gameState.maxExperience = gameState.level * 100;
        gameState.maxHealth += 10;
        gameState.health = gameState.maxHealth;
        gameState.attack += 2;
        gameState.defense += 1;
        
        setColor(10);
        cout << "\n恭喜升级!现在是 " << gameState.level << " 级!\n";
        setColor(7);
        
        if (gameState.level == 10) unlockAchievement("level_10");
        if (gameState.level == 20) unlockAchievement("level_20");
        
        pause();
    }
}

// 使用技能
int useSkill(Skill& skill) {
    skill.uses++;
    skill.experience += 10;
    
    if (skill.experience >= skill.maxExperience) {
        skill.level++;
        skill.experience = 0;
        skill.maxExperience = skill.level * 100;
        
        setColor(10);
        cout << skill.name << " 升级到 Lv." << skill.level << "!\n";
        setColor(7);
        
        if (skill.level == 5) unlockAchievement("skill_master");
    }
    
    int damage = skill.baseDamage * skill.level;
    if (damage > 0) {
        setColor(12);
        cout << "使用了 " << skill.name << "!造成 " << damage << " 点伤害!\n";
        setColor(7);
    } else {
        setColor(11);
        cout << "使用了 " << skill.name << "!\n";
        setColor(7);
    }
    
    return damage;
}

// 打开宝箱
void openTreasureChest(const TreasureChest& chest) {
    setColor(14);
    cout << "\n发现了一个宝箱!\n";
    setColor(7);
    
    // 获得金币
    int goldFound = rand() % (chest.goldMax - chest.goldMin + 1) + chest.goldMin;
    gameState.gold += goldFound;
    cout << "获得了 " << goldFound << " 金币!\n";
    
    // 决定掉落品质
    int rarityRoll = rand() % 100;
    vector<string> drops;
    
    if (rarityRoll < 60) {
        // 普通掉落
        if (!chest.commonDrops.empty()) {
            string item = chest.commonDrops[rand() % chest.commonDrops.size()];
            gameState.materials[item]++;
            cout << "获得了材料: " << item << "!\n";
        }
    } else if (rarityRoll < 90) {
        // 稀有掉落
        if (!chest.rareDrops.empty()) {
            string item = chest.rareDrops[rand() % chest.rareDrops.size()];
            gameState.materials[item]++;
            cout << "获得了稀有材料: " << item << "!\n";
        }
    } else {
        // 史诗掉落
        if (!chest.epicDrops.empty()) {
            string item = chest.epicDrops[rand() % chest.epicDrops.size()];
            if (item.find("技能书") != string::npos) {
                // 是技能书
                bool alreadyKnown = false;
                for (Skill& skill : gameState.skills) {
                    if (skill.name == item.substr(0, item.find("技能书"))) {
                        alreadyKnown = true;
                        break;
                    }
                }
                
                if (!alreadyKnown) {
                    // 添加技能书到背包
                    bool found = false;
                    for (Item& invItem : gameState.inventory) {
                        if (invItem.name == item) {
                            invItem.value++; // 使用value字段存储数量
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        for (Item& templateItem : allItems) {
                            if (templateItem.name == item) {
                                templateItem.value = 1; // 第一个,数量设为1
                                gameState.inventory.push_back(templateItem);
                                break;
                            }
                        }
                    }
                    cout << "获得了 " << item << "!\n";
                    unlockAchievement("treasure_hunter");
                } else {
                    cout << "获得了技能书,但你已经学会了这个技能。\n";
                }
            } else {
                gameState.materials[item]++;
                cout << "获得了史诗材料: " << item << "!\n";
            }
        }
    }
    
    pause();
}

// 战斗系统
void battle(Monster& monster) {
    clearScreen();
    setColor(12);
    cout << "遭遇了 " << monster.name << "!\n";
    setColor(7);
    
    int monsterHealth = monster.health;
    bool playerTurn = true;
    bool ranAway = false;
    
    while (gameState.health > 0 && monsterHealth > 0) {
        if (playerTurn) {
            cout << "\n你的生命: " << gameState.health << "/" << gameState.maxHealth << "\n";
            cout << monster.name << " 生命: " << monsterHealth << "/" << monster.health << "\n\n";
            
            cout << "1. 攻击\n";
            for (size_t i = 0; i < gameState.skills.size(); i++) {
                cout << i + 2 << ". 使用 " << gameState.skills[i].name << " (Lv." << gameState.skills[i].level << ")\n";
            }
            cout << gameState.skills.size() + 2 << ". 逃跑\n";
            
            int choice;
            cout << "选择: ";
            cin >> choice;
            
            if (choice == 1) {
                int damage = max(1, gameState.attack - monster.defense / 2);
                monsterHealth -= damage;
                cout << "你造成了 " << damage << " 点伤害!\n";
            } 
            else if (choice > 1 && choice <= static_cast<int>(gameState.skills.size()) + 1) {
                Skill& skill = gameState.skills[choice - 2];
                int damage = useSkill(skill);
                if (damage > 0) {
                    damage = max(1, damage - monster.defense / 3);
                    monsterHealth -= damage;
                    cout << "对 " << monster.name << " 造成 " << damage << " 点伤害!\n";
                } else {
                    // 处理非伤害技能
                    if (skill.name == "治疗术") {
                        int heal = 15 * skill.level;
                        gameState.health = min(gameState.maxHealth, gameState.health + heal);
                        cout << "恢复了 " << heal << " 点生命值!\n";
                    } else if (skill.name == "魔法护盾") {
                        gameState.defense += 2 * skill.level;
                        cout << "防御力暂时提升了!\n";
                    }
                }
            }
            else if (choice == static_cast<int>(gameState.skills.size()) + 2) {
                if (rand() % 100 < 50) {
                    ranAway = true;
                    cout << "你成功逃跑了!\n";
                    break;
                } else {
                    cout << "逃跑失败!\n";
                }
            }
        } else {
            int damage = max(1, monster.attack - gameState.defense / 2);
            gameState.health -= damage;
            cout << monster.name << " 对你造成 " << damage << " 点伤害!\n";
        }
        
        playerTurn = !playerTurn;
        pause();
    }
    
    if (ranAway) {
        return;
    }
    
    if (gameState.health <= 0) {
        setColor(12);
        cout << "\n你被 " << monster.name << " 击败了!\n";
        cout << "你被送回城镇,但损失了一些金币。\n";
        setColor(7);
        gameState.health = gameState.maxHealth / 2;
        gameState.gold = max(0, gameState.gold - 50);
        gameState.currentLocation = "城镇";
        pause();
        return;
    }
    
    setColor(10);
    cout << "\n你击败了 " << monster.name << "!\n";
    cout << "获得 " << monster.experience << " 经验值!\n";
    setColor(7);
    
    gameState.experience += monster.experience;
    
    // 掉落物品
    if (!monster.drops.empty() && rand() % 100 < (monster.isBoss ? 100 : 70)) {
        string drop = monster.drops[rand() % monster.drops.size()];
        
        if (drop == "魔龙之血" || drop == "死灵粉尘" || drop == "圣光结晶" || 
            drop == "奥术精华" || drop == "战斗法师手册" || drop == "游侠徽章" || drop == "刺客信条") {
            // 转职道具
            bool found = false;
            for (Item& invItem : gameState.inventory) {
                if (invItem.name == drop) {
                    invItem.value++; // 使用value字段存储数量
                    found = true;
                    break;
                }
            }
            if (!found) {
                for (Item& templateItem : allItems) {
                    if (templateItem.name == drop) {
                        templateItem.value = 1; // 第一个,数量设为1
                        gameState.inventory.push_back(templateItem);
                        break;
                    }
                }
            }
            setColor(14);
            cout << "获得了特殊转职道具: " << drop << "!\n";
            setColor(7);
        } else {
            gameState.materials[drop]++;
            setColor(14);
            cout << "获得了材料: " << drop << "!\n";
            setColor(7);
        }
    }
    
    if (monster.isBoss) {
        unlockAchievement("boss_slayer");
        if (monster.name == "魔龙") {
            unlockAchievement("dragon_slayer");
        }
        
        // 打开boss宝箱
        openTreasureChest(bossChest);
    } else if (gameState.unlockedAchievements.empty()) {
        unlockAchievement("first_kill");
    }
    
    levelUp();
    pause();
}

// 探索区域
void exploreRegion(const Region& region) {
    clearScreen();
    setColor(11);
    cout << "========== " << region.name << " ==========\n";
    setColor(7);
    cout << region.description << "\n\n";
    
    while (true) {
        cout << "1. 探索\n";
        if (region.hasBoss && !gameState.hasDiscoveredBoss[distance(regions.begin(), find(regions.begin(), regions.end(), region))]) {
            cout << "2. 深入探索(可能遇到首领)\n";
        }
        cout << "3. 查看状态\n";
        cout << "4. 返回\n";
        
        int choice;
        cout << "选择: ";
        cin >> choice;
        
        if (choice == 1) {
            if (region.monsters.empty() && !region.hasBoss) {
                cout << "这里很安全,没有发现怪物。\n";
                pause();
                continue;
            }
            
            // 普通探索遇到普通怪物或宝箱
            if (region.hasTreasure && rand() % 100 < 30) {
                openTreasureChest(commonChest);
                break;
            } else {
                string monsterName = region.monsters[rand() % region.monsters.size()];
                for (Monster& monster : monsters) {
                    if (monster.name == monsterName && !monster.isBoss) {
                        battle(monster);
                        break;
                    }
                }
                break;
            }
        } else if (choice == 2 && region.hasBoss) {
            // 深入探索可能遇到boss
            gameState.hasDiscoveredBoss[distance(regions.begin(), find(regions.begin(), regions.end(), region))] = true;
            
            for (Monster& monster : monsters) {
                if (monster.name == region.bossName && monster.isBoss) {
                    battle(monster);
                    break;
                }
            }
            break;
        } else if (choice == 3) {
            showStatus();
        } else if (choice == 4) {
            break;
        }
    }
}

// 学习技能
void learnSkill(const string& skillName) {
    // 检查是否已学会
    for (Skill& skill : gameState.skills) {
        if (skill.name == skillName) {
            cout << "你已经学会了 " << skillName << "!\n";
            pause();
            return;
        }
    }
    
    // 查找技能模板
    Skill newSkill;
    bool found = false;
    
    for (auto& profSkills : professionSkills) {
        for (Skill skill : profSkills.second) {
            if (skill.name == skillName) {
                newSkill = skill;
                found = true;
                break;
            }
        }
        if (found) break;
    }
    
    if (found) {
        gameState.skills.push_back(newSkill);
        setColor(10);
        cout << "你学会了新技能: " << skillName << "!\n";
        setColor(7);
        
        // 从背包中移除技能书
        for (auto it = gameState.inventory.begin(); it != gameState.inventory.end(); ++it) {
            if (it->skillTaught == skillName) {
                if (it->value > 1) {
                    it->value--;
                } else {
                    gameState.inventory.erase(it);
                }
                break;
            }
        }
        
        unlockAchievement("skill_learner");
    } else {
        setColor(12);
        cout << "无效的技能书!\n";
        setColor(7);
    }
    
    pause();
}

// 转职
void changeProfession(const Item& item) {
    Profession newProfession;
    if (item.advancedProfession == "DRAGONKNIGHT") newProfession = Profession::DRAGONKNIGHT;
    else if (item.advancedProfession == "NECROMANCER") newProfession = Profession::NECROMANCER;
    else if (item.advancedProfession == "PALADIN") newProfession = Profession::PALADIN;
    else if (item.advancedProfession == "SPELLSWORD") newProfession = Profession::SPELLSWORD;
    else if (item.advancedProfession == "BATTLEMAGE") newProfession = Profession::BATTLEMAGE;
    else if (item.advancedProfession == "RANGER") newProfession = Profession::RANGER;
    else if (item.advancedProfession == "ASSASSIN") newProfession = Profession::ASSASSIN;
    else {
        cout << "无效的职业转换!\n";
        pause();
        return;
    }
    
    setColor(14);
    cout << "你正在从 " << professionNames[gameState.profession] << " 转职为 " << professionNames[newProfession] << "!\n";
    cout << "这将保留你原有的部分技能,并学习新的职业专属技能。\n";
    setColor(7);
    
    cout << "确定要转职吗?(1. 是 2. 否): ";
    int choice;
    cin >> choice;
    
    if (choice == 1) {
        // 保留原有职业的部分技能
        vector<Skill> keptSkills;
        for (Skill& skill : gameState.skills) {
            if (skill.level >= 3) { // 保留等级达到3级以上的技能
                keptSkills.push_back(skill);
            }
        }
        
        gameState.previousProfession = gameState.profession;
        gameState.profession = newProfession;
        
        // 学习新职业的基础技能
        gameState.skills = professionSkills[newProfession];
        
        // 添加保留的技能
        for (Skill& skill : keptSkills) {
            bool alreadyExists = false;
            for (Skill& newSkill : gameState.skills) {
                if (newSkill.name == skill.name) {
                    alreadyExists = true;
                    break;
                }
            }
            if (!alreadyExists) {
                gameState.skills.push_back(skill);
            }
        }
        
        // 调整属性
        switch (newProfession) {
            case Profession::DRAGONKNIGHT:
                gameState.maxHealth += 30;
                gameState.attack += 10;
                gameState.defense += 5;
                break;
            case Profession::NECROMANCER:
                gameState.maxHealth += 10;
                gameState.attack += 5;
                break;
            case Profession::PALADIN:
                gameState.maxHealth += 20;
                gameState.attack += 5;
                gameState.defense += 10;
                break;
            case Profession::SPELLSWORD:
                gameState.maxHealth += 15;
                gameState.attack += 8;
                gameState.defense += 5;
                break;
            case Profession::BATTLEMAGE:
                gameState.maxHealth += 10;
                gameState.attack += 12;
                break;
            case Profession::RANGER:
                gameState.maxHealth += 10;
                gameState.attack += 15;
                break;
            case Profession::ASSASSIN:
                gameState.maxHealth += 5;
                gameState.attack += 20;
                break;
            default:
                break;
        }
        
        gameState.health = gameState.maxHealth;
        
        setColor(10);
        cout << "转职成功!你现在是一名 " << professionNames[newProfession] << "!\n";
        setColor(7);
        
        unlockAchievement("class_master");
        
        // 从背包中移除转职道具
        for (auto it = gameState.inventory.begin(); it != gameState.inventory.end(); ++it) {
            if (it->name == item.name) {
                if (it->value > 1) {
                    it->value--;
                } else {
                    gameState.inventory.erase(it);
                }
                break;
            }
        }
    }
    
    pause();
}

// 访问城镇
void visitTown() {
    gameState.currentLocation = "城镇";
    
    while (true) {
        clearScreen();
        setColor(11);
        cout << "========== 城镇 ==========\n";
        setColor(7);
        cout << "一个繁华的城镇,冒险者们聚集的地方。\n\n";
        
        cout << "1. 商店\n";
        cout << "2. 铁匠铺\n";
        cout << "3. 冒险者公会\n";
        cout << "4. 旅馆(休息)\n";
        cout << "5. 使用物品\n";
        cout << "6. 查看状态\n";
        cout << "7. 离开城镇\n";
        
        int choice;
        cout << "选择: ";
        cin >> choice;
        
        switch (choice) {
            case 1:
                visitShop();
                break;
            case 2:
                visitBlacksmith();
                break;
            case 3:
                visitAdventurersGuild();
                break;
            case 4:
                gameState.health = gameState.maxHealth;
                gameState.daysPassed++;
                cout << "你休息了一晚,生命值完全恢复了。\n";
                pause();
                break;
            case 5:
                // 使用物品
                if (gameState.inventory.empty()) {
                    cout << "背包中没有物品!\n";
                    pause();
                    break;
                }
                
                clearScreen();
                setColor(11);
                cout << "========== 背包物品 ==========\n";
                setColor(7);
                
                for (size_t i = 0; i < gameState.inventory.size(); i++) {
                    cout << i + 1 << ". " << gameState.inventory[i].name;
                    if (gameState.inventory[i].value > 1) {
                        cout << " x" << gameState.inventory[i].value;
                    }
                    cout << "\n";
                }
                cout << gameState.inventory.size() + 1 << ". 返回\n";
                
                int itemChoice;
                cout << "选择要使用的物品: ";
                cin >> itemChoice;
                
                if (itemChoice > 0 && itemChoice <= static_cast<int>(gameState.inventory.size())) {
                    Item& item = gameState.inventory[itemChoice - 1];
                    
                    if (item.type == "consumable") {
                        if (item.name == "治疗药水") {
                            gameState.health = min(gameState.maxHealth, gameState.health + 50);
                            cout << "使用了治疗药水,恢复了50点生命值!\n";
                        } else if (item.name == "魔力药水") {
                            // 假设魔力药水恢复技能使用次数
                            for (Skill& skill : gameState.skills) {
                                skill.uses = max(0, skill.uses - 2); // 减少使用次数,相当于恢复
                            }
                            cout << "使用了魔力药水,技能使用次数恢复了!\n";
                        }
                        
                        if (item.value > 1) {
                            item.value--;
                        } else {
                            gameState.inventory.erase(gameState.inventory.begin() + itemChoice - 1);
                        }
                    } 
                    else if (item.type == "skillbook") {
                        learnSkill(item.skillTaught);
                    }
                    else if (item.type == "special") {
                        // 检查是否符合转职条件
                        bool canChange = false;
                        string requiredProf = item.requiredProfession;
                        
                        if (requiredProf.find("|") != string::npos) {
                            // 多个职业条件
                            size_t pos = 0;
                            while ((pos = requiredProf.find("|")) != string::npos) {
                                string token = requiredProf.substr(0, pos);
                                if (professionNames[gameState.profession] == token) {
                                    canChange = true;
                                    break;
                                }
                                requiredProf.erase(0, pos + 1);
                            }
                            if (professionNames[gameState.profession] == requiredProf) {
                                canChange = true;
                            }
                        } else {
                            // 单个职业条件
                            if (professionNames[gameState.profession] == requiredProf) {
                                canChange = true;
                            }
                        }
                        
                        if (canChange) {
                            changeProfession(item);
                        } else {
                            setColor(12);
                            cout << "你的职业不符合转职条件!\n";
                            setColor(7);
                            pause();
                        }
                    } else {
                        cout << "这个物品不能直接使用!\n";
                        pause();
                    }
                }
                break;
            case 6:
                showStatus();
                break;
            case 7:
                return;
        }
    }
}

// 访问商店
void visitShop() {
    while (true) {
        clearScreen();
        setColor(11);
        cout << "========== 商店 ==========\n";
        setColor(7);
        cout << "金币: " << gameState.gold << "\n\n";
        
        vector<Item> shopItems;
        for (Item item : allItems) {
            if (item.type == "consumable" || item.type == "material" || item.type == "skillbook") {
                shopItems.push_back(item);
            }
        }
        
        for (size_t i = 0; i < shopItems.size(); i++) {
            cout << i + 1 << ". " << shopItems[i].name << " - " << shopItems[i].value << "金币";
            if (shopItems[i].type == "consumable") {
                cout << " (消耗品)";
            } else if (shopItems[i].type == "skillbook") {
                cout << " (技能书)";
            } else {
                cout << " (材料)";
            }
            cout << "\n";
        }
        cout << shopItems.size() + 1 << ". 卖出材料\n";
        cout << shopItems.size() + 2 << ". 离开\n";
        
        int choice;
        cout << "选择: ";
        cin >> choice;
        
        if (choice > 0 && choice <= static_cast<int>(shopItems.size())) {
            Item item = shopItems[choice - 1];
            if (gameState.gold >= item.value) {
                gameState.gold -= item.value;
                if (item.type == "consumable") {
                    bool found = false;
                    for (Item& invItem : gameState.inventory) {
                        if (invItem.name == item.name) {
                            invItem.value++; // 使用value字段存储数量
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        item.value = 1; // 第一个,数量设为1
                        gameState.inventory.push_back(item);
                    }
                    cout << "购买了 " << item.name << "!\n";
                } else if (item.type == "skillbook") {
                    bool found = false;
                    for (Item& invItem : gameState.inventory) {
                        if (invItem.name == item.name) {
                            invItem.value++; // 使用value字段存储数量
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        item.value = 1; // 第一个,数量设为1
                        gameState.inventory.push_back(item);
                    }
                    cout << "购买了 " << item.name << "!\n";
                } else {
                    gameState.materials[item.name]++;
                    cout << "购买了 " << item.name << "!\n";
                }
            } else {
                cout << "金币不足!\n";
            }
            pause();
        } else if (choice == static_cast<int>(shopItems.size()) + 1) {
            // 卖出材料
            if (gameState.materials.empty()) {
                cout << "没有可卖出的材料!\n";
                pause();
                continue;
            }
            
            clearScreen();
            setColor(11);
            cout << "========== 卖出材料 ==========\n";
            setColor(7);
            cout << "金币: " << gameState.gold << "\n\n";
            
            int index = 1;
            map<int, string> materialIndex;
            for (auto& material : gameState.materials) {
                // 查找物品价值
                int value = 0;
                for (Item& item : allItems) {
                    if (item.name == material.first) {
                        value = item.value;
                        break;
                    }
                }
                cout << index << ". " << material.first << " x" << material.second << " - " << value << "金币/个\n";
                materialIndex[index] = material.first;
                index++;
            }
            cout << index << ". 返回\n";
            
            int sellChoice;
            cout << "选择要卖出的材料: ";
            cin >> sellChoice;
            
            if (sellChoice > 0 && sellChoice < index) {
                string materialName = materialIndex[sellChoice];
                int quantity;
                cout << "卖出多少 " << materialName << "? (当前有 " << gameState.materials[materialName] << " 个): ";
                cin >> quantity;
                
                if (quantity > 0 && quantity <= gameState.materials[materialName]) {
                    int totalValue = 0;
                    for (Item& item : allItems) {
                        if (item.name == materialName) {
                            totalValue = item.value * quantity;
                            break;
                        }
                    }
                    
                    gameState.materials[materialName] -= quantity;
                    gameState.gold += totalValue;
                    cout << "卖出了 " << quantity << " 个 " << materialName << ",获得 " << totalValue << " 金币!\n";
                    
                    if (gameState.gold >= 5000) unlockAchievement("rich");
                } else {
                    cout << "无效的数量!\n";
                }
                pause();
            }
        } else if (choice == static_cast<int>(shopItems.size()) + 2) {
            return;
        }
    }
}

// 访问铁匠铺
void visitBlacksmith() {
    while (true) {
        clearScreen();
        setColor(11);
        cout << "========== 铁匠铺 ==========\n";
        setColor(7);
        cout << "金币: " << gameState.gold << "\n\n";
        
        cout << "1. 锻造装备\n";
        cout << "2. 强化装备\n";
        cout << "3. 离开\n";
        
        int choice;
        cout << "选择: ";
        cin >> choice;
        
        if (choice == 1) {
            craftItem();
        } else if (choice == 2) {
            // 强化装备逻辑
            if (gameState.equipment.empty()) {
                cout << "没有可强化的装备!\n";
                pause();
                continue;
            }
            
            clearScreen();
            setColor(11);
            cout << "========== 强化装备 ==========\n";
            setColor(7);
            
            for (size_t i = 0; i < gameState.equipment.size(); i++) {
                cout << i + 1 << ". " << gameState.equipment[i].name;
                if (gameState.equipment[i].attackBonus > 0) cout << " 攻击+" << gameState.equipment[i].attackBonus;
                if (gameState.equipment[i].defenseBonus > 0) cout << " 防御+" << gameState.equipment[i].defenseBonus;
                cout << "\n";
            }
            cout << gameState.equipment.size() + 1 << ". 返回\n";
            
            int equipChoice;
            cout << "选择要强化的装备: ";
            cin >> equipChoice;
            
            if (equipChoice > 0 && equipChoice <= static_cast<int>(gameState.equipment.size())) {
                Item& item = gameState.equipment[equipChoice - 1];
                
                // 检查是否有足够的材料
                if (gameState.materials["铁锭"] < 2 && gameState.materials["钢锭"] < 1) {
                    cout << "材料不足!需要铁锭x2或钢锭x1\n";
                    pause();
                    continue;
                }
                
                // 选择材料
                cout << "1. 使用铁锭x2\n";
                if (gameState.materials["钢锭"] >= 1) {
                    cout << "2. 使用钢锭x1 (效果更好)\n";
                }
                cout << "3. 取消\n";
                
                int matChoice;
                cout << "选择: ";
                cin >> matChoice;
                
                if (matChoice == 1 && gameState.materials["铁锭"] >= 2) {
                    gameState.materials["铁锭"] -= 2;
                    item.attackBonus += 1;
                    item.defenseBonus += 1;
                    cout << item.name << " 被强化了!攻击+1,防御+1\n";
                } else if (matChoice == 2 && gameState.materials["钢锭"] >= 1) {
                    gameState.materials["钢锭"] -= 1;
                    item.attackBonus += 2;
                    item.defenseBonus += 2;
                    cout << item.name << " 被强化了!攻击+2,防御+2\n";
                } else {
                    cout << "强化取消\n";
                }
                
                // 更新角色属性
                gameState.attack = 10 + 2 * (gameState.level - 1);
                gameState.defense = 5 + (gameState.level - 1);
                for (Item& eq : gameState.equipment) {
                    gameState.attack += eq.attackBonus;
                    gameState.defense += eq.defenseBonus;
                }
                
                pause();
            }
        } else if (choice == 3) {
            return;
        }
    }
}

// 锻造物品
void craftItem() {
    vector<Item> craftableItems;
    for (Item item : allItems) {
        if (!item.materials.empty() && (item.type == "weapon" || item.type == "armor")) {
            craftableItems.push_back(item);
        }
    }
    
    while (true) {
        clearScreen();
        setColor(11);
        cout << "========== 可锻造物品 ==========\n";
        setColor(7);
        
        for (size_t i = 0; i < craftableItems.size(); i++) {
            cout << i + 1 << ". " << craftableItems[i].name;
            cout << " (攻击+" << craftableItems[i].attackBonus << " 防御+" << craftableItems[i].defenseBonus << ") - 需要: ";
            for (size_t j = 0; j < craftableItems[i].materials.size(); j++) {
                if (j != 0) cout << ", ";
                cout << craftableItems[i].materials[j] << " x1";
            }
            cout << "\n";
        }
        cout << craftableItems.size() + 1 << ". 返回\n";
        
        int choice;
        cout << "选择要锻造的物品: ";
        cin >> choice;
        
        if (choice > 0 && choice <= static_cast<int>(craftableItems.size())) {
            Item item = craftableItems[choice - 1];
            bool hasMaterials = true;
            
            for (string material : item.materials) {
                if (gameState.materials[material] < 1) {
                    hasMaterials = false;
                    break;
                }
            }
            
            if (hasMaterials) {
                for (string material : item.materials) {
                    gameState.materials[material]--;
                }
                
                // 检查是否是传说之剑
                if (item.name == "传说之剑") {
                    unlockAchievement("legendary_craftsman");
                } else if (craftableItems.size() >= 3 && choice <= 3) {
                    unlockAchievement("craftsman");
                }
                
                // 添加到装备
                bool equipped = false;
                for (Item& eq : gameState.equipment) {
                    if (eq.type == item.type) {
                        eq = item; // 替换同类型装备
                        equipped = true;
                        break;
                    }
                }
                if (!equipped) {
                    gameState.equipment.push_back(item);
                }
                
                // 更新角色属性
                gameState.attack = 10 + 2 * (gameState.level - 1);
                gameState.defense = 5 + (gameState.level - 1);
                for (Item& eq : gameState.equipment) {
                    gameState.attack += eq.attackBonus;
                    gameState.defense += eq.defenseBonus;
                }
                
                setColor(10);
                cout << "成功锻造了 " << item.name << "!\n";
                setColor(7);
            } else {
                setColor(12);
                cout << "材料不足!\n";
                setColor(7);
            }
            pause();
        } else if (choice == static_cast<int>(craftableItems.size()) + 1) {
            return;
        }
    }
}

// 访问冒险者公会
void visitAdventurersGuild() {
    while (true) {
        clearScreen();
        setColor(11);
        cout << "========== 冒险者公会 ==========\n";
        setColor(7);
        
        cout << "1. 查看可探索区域\n";
        cout << "2. 查看成就\n";
        cout << "3. 查看转职信息\n";
        cout << "4. 离开\n";
        
        int choice;
        cout << "选择: ";
        cin >> choice;
        
        if (choice == 1) {
            while (true) {
                clearScreen();
                setColor(11);
                cout << "========== 可探索区域 ==========\n";
                setColor(7);
                
                for (size_t i = 0; i < regions.size(); i++) {
                    cout << i + 1 << ". " << regions[i].name << "\n";
                    cout << "   " << regions[i].description << "\n";
                    cout << "   可能遇到的怪物: ";
                    for (size_t j = 0; j < regions[i].monsters.size(); j++) {
                        if (j != 0) cout << ", ";
                        cout << regions[i].monsters[j];
                    }
                    if (regions[i].hasBoss) {
                        cout << "\n   首领: " << regions[i].bossName;
                        if (gameState.hasDiscoveredBoss[i]) {
                            cout << " (已发现)";
                        }
                    }
                    cout << "\n\n";
                }
                cout << regions.size() + 1 << ". 返回\n";
                
                int regionChoice;
                cout << "选择要探索的区域: ";
                cin >> regionChoice;
                
                if (regionChoice > 0 && regionChoice <= static_cast<int>(regions.size())) {
                    exploreRegion(regions[regionChoice - 1]);
                    break;
                } else if (regionChoice == static_cast<int>(regions.size()) + 1) {
                    break;
                }
            }
        } else if (choice == 2) {
            clearScreen();
            setColor(11);
            cout << "========== 成就 ==========\n";
            setColor(7);
            
            if (gameState.unlockedAchievements.empty()) {
                cout << "尚未获得任何成就\n";
            } else {
                for (const string& ach : gameState.unlockedAchievements) {
                    cout << "- " << achievements[ach] << "\n";
                }
            }
            
            cout << "\n未获得成就:\n";
            bool allUnlocked = true;
            for (auto& ach : achievements) {
                if (find(gameState.unlockedAchievements.begin(), gameState.unlockedAchievements.end(), ach.first) == gameState.unlockedAchievements.end()) {
                    cout << "- ???\n"; // 隐藏未获得成就的具体信息
                    allUnlocked = false;
                }
            }
            
            if (allUnlocked) {
                setColor(14);
                cout << "你已经获得了所有成就!\n";
                setColor(7);
            }
            
            pause();
        } else if (choice == 3) {
            clearScreen();
            setColor(11);
            cout << "========== 转职信息 ==========\n";
            setColor(7);
            
            cout << "当前职业: " << professionNames[gameState.profession] << "\n\n";
            
            cout << "可转职职业:\n";
            cout << "1. 龙骑士 - 需要: 战士, 魔龙之血 (魔龙山脉击败魔龙获得)\n";
            cout << "2. 死灵法师 - 需要: 法师, 死灵粉尘 (亡灵墓穴击败巫妖王获得)\n";
            cout << "3. 圣骑士 - 需要: 战士或牧师, 圣光结晶 (神圣殿堂击败圣殿骑士获得)\n";
            cout << "4. 魔剑士 - 需要: 战士或法师, 奥术精华 (奥术高塔击败奥术守护者获得)\n";
            cout << "5. 战斗法师 - 需要: 法师, 战斗法师手册 (魔法学院废墟宝箱获得)\n";
            cout << "6. 游侠 - 需要: 弓箭手, 游侠徽章 (暗影密林击败暗影刺客获得)\n";
            cout << "7. 刺客 - 需要: 盗贼, 刺客信条 (暗影密林击败暗影刺客获得)\n\n";
            
            cout << "转职后将保留原有部分技能并获得新职业技能\n";
            
            pause();
        } else if (choice == 4) {
            return;
        }
    }
}

// 主游戏循环
void gameLoop() {
    while (true) {
        clearScreen();
        setColor(11);
        cout << "========== 主菜单 ==========\n";
        setColor(7);
        cout << "天数: " << gameState.daysPassed << "\n\n";
        
        cout << "1. 前往城镇\n";
        cout << "2. 探索\n";
        cout << "3. 查看状态\n";
        cout << "4. 保存游戏\n";
        cout << "5. 退出游戏\n";
        
        int choice;
        cout << "选择: ";
        cin >> choice;
        
        switch (choice) {
            case 1:
                visitTown();
                break;
            case 2:
                if (regions.empty()) {
                    cout << "尚未解锁任何区域,请先访问冒险者公会!\n";
                    pause();
                } else {
                    exploreRegion(regions[rand() % regions.size()]);
                }
                break;
            case 3:
                showStatus();
                break;
            case 4:
                // 保存游戏功能
                cout << "保存游戏功能开发中...\n";
                pause();
                break;
            case 5:
                return;
        }
    }
}

// 主菜单
void mainMenu() {
    while (true) {
        clearScreen();
        setColor(11);
        cout << "========== 异世界冒险者 ==========\n";
        setColor(7);
        cout << "1. 开始新游戏\n";
        cout << "2. 加载游戏\n";
        cout << "3. 退出\n";
        
        int choice;
        cout << "选择: ";
        cin >> choice;
        
        if (choice == 1) {
            clearScreen();
            cout << "请输入你的名字: ";
            getline(cin, gameState.playerName);
            getline(cin, gameState.playerName);
            
            cout << "\n选择初始职业:\n";
            cout << "1. 战士 - 高生命值,平衡的攻击与防御\n";
            cout << "2. 法师 - 强大的魔法攻击,但生命值较低\n";
            cout << "3. 弓箭手 - 高攻击力,擅长远程战斗\n";
            cout << "4. 盗贼 - 暴击伤害高,技能致命\n";
            cout << "5. 牧师 - 治疗能力,团队支持\n";
            
            int profChoice;
            cout << "选择职业(1-5): ";
            cin >> profChoice;
            
            switch (profChoice) {
                case 1:
                    gameState.profession = Profession::WARRIOR;
                    break;
                case 2:
                    gameState.profession = Profession::MAGE;
                    break;
                case 3:
                    gameState.profession = Profession::ARCHER;
                    break;
                case 4:
                    gameState.profession = Profession::ROGUE;
                    break;
                case 5:
                    gameState.profession = Profession::CLERIC;
                    break;
                default:
                    gameState.profession = Profession::WARRIOR;
            }
            
            // 初始化玩家状态
            gameState.level = 1;
            gameState.experience = 0;
            gameState.maxExperience = 100;
            gameState.health = 100;
            gameState.maxHealth = 100;
            gameState.attack = 10;
            gameState.defense = 5;
            gameState.gold = 50;
            gameState.skills = professionSkills[gameState.profession];
            gameState.currentLocation = "城镇";
            gameState.daysPassed = 1;
            gameState.previousProfession = gameState.profession;
            
            // 初始化boss发现状态
            for (int i = 0; i < 12; i++) {
                gameState.hasDiscoveredBoss[i] = false;
            }
            
            // 初始装备
            Item starterWeapon;
            switch (gameState.profession) {
                case Profession::WARRIOR:
                    starterWeapon = {"木剑", "weapon", 0, 3, 0, {}};
                    break;
                case Profession::MAGE:
                    starterWeapon = {"学徒法杖", "weapon", 0, 2, 0, {}};
                    break;
                case Profession::ARCHER:
                    starterWeapon = {"短弓", "weapon", 0, 4, 0, {}};
                    break;
                case Profession::ROGUE:
                    starterWeapon = {"匕首", "weapon", 0, 5, 0, {}};
                    break;
                case Profession::CLERIC:
                    starterWeapon = {"圣徽", "weapon", 0, 2, 1, {}};
                    break;
                default:
                    starterWeapon = {"木剑", "weapon", 0, 3, 0, {}};
            }
            gameState.equipment.push_back(starterWeapon);
            gameState.attack += starterWeapon.attackBonus;
            gameState.defense += starterWeapon.defenseBonus;
            
            cout << "\n欢迎来到异世界, " << gameState.playerName << "!\n";
            cout << "你是一名 " << professionNames[gameState.profession] << ",开始你的冒险吧!\n";
            pause();
            
            gameLoop();
        } else if (choice == 2) {
            // 加载游戏逻辑
            cout << "加载游戏功能开发中...\n";
            pause();
        } else if (choice == 3) {
            return;
        }
    }
}

int main() {
    srand(time(0)); // 初始化随机数种子
    mainMenu();
    return 0;
}

应该能复制吧

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值