C++传说:神明之剑0.4.5装备机制彻底完成

装备品质分化为白色品质,绿色品质,蓝色品质,紫色品质,金色品质,红色品质(未升星),红色品质1阶,红色品质2阶,红色品质3阶,红色品质4阶,粉色品质5阶,橙色品质神装

玩家可通过锻造的渠道来升级红色品质装备,其中红色品质1阶到橙色品质神装无法以击败怪物为渠道获得,需要用大量材料去合成

新地图正在制作中拭目以待

剧情将与新地图一同上架(预计0.6版本)

代码如下:

cpp 复制代码
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <windows.h>
#include <conio.h>
#include <algorithm>
#include <iomanip>
#include <sstream>

using namespace std;

enum Color {
    BLACK = 0,
    BLUE = 1,
    GREEN = 2,
    CYAN = 3,
    RED = 4,
    MAGENTA = 5,
    YELLOW = 6,
    WHITE = 7,
    GRAY = 8,
    LIGHT_BLUE = 9,
    LIGHT_GREEN = 10,
    LIGHT_CYAN = 11,
    LIGHT_RED = 12,
    LIGHT_MAGENTA = 13,
    LIGHT_YELLOW = 14,
    BRIGHT_WHITE = 15,
    ORANGE = 202  // 橙色
};

void SetColor(int foreground, int background = BLACK) {
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    if (foreground == ORANGE) {
        // 橙色需要特殊处理
        SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
    }
    else {
        SetConsoleTextAttribute(hConsole, foreground | (background << 4));
    }
}

void SetCursorPosition(int x, int y) {
    COORD coord = { static_cast<SHORT>(x), static_cast<SHORT>(y) };
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

enum class Rarity {
    WHITE,
    GREEN,
    BLUE,
    PURPLE,
    GOLD,
    RED,
    PINK,
    ORANGE  // 新增橙色品质
};

enum class EquipmentType {
    HELMET,
    ARMOR,
    BOOTS,
    WEAPON,
    SHIELD
};

class Equipment {
public:
    string name;
    EquipmentType type;
    Rarity rarity;
    int hpBonus;
    int minAttackBonus;
    int maxAttackBonus;
    int starLevel;      // 星数 (0-10)
    int upgradeLevel;   // 进阶等级 (0-5, 5为max)
    bool isUpgraded;    // 是否已进阶
    bool isEquipped;    // 是否已装备

    Equipment(string n, EquipmentType t, Rarity r, int hp, int minAtk, int maxAtk,
        int star = 0, int upgrade = 0, bool upgraded = false, bool equipped = false)
        : name(n), type(t), rarity(r), hpBonus(hp), minAttackBonus(minAtk), maxAttackBonus(maxAtk),
        starLevel(star), upgradeLevel(upgrade), isUpgraded(upgraded), isEquipped(equipped) {
        // 应用星数和进阶加成
        if (starLevel > 0) {
            float multiplier = 1.0f + starLevel * 0.25f;
            hpBonus = static_cast<int>(hpBonus * multiplier);
            minAttackBonus = static_cast<int>(minAttackBonus * multiplier);
            maxAttackBonus = static_cast<int>(maxAttackBonus * multiplier);
        }
        if (upgradeLevel > 0 && upgradeLevel < 5) {
            float multiplier = 1.0f + upgradeLevel * 0.25f;
            hpBonus = static_cast<int>(hpBonus * multiplier);
            minAttackBonus = static_cast<int>(minAttackBonus * multiplier);
            maxAttackBonus = static_cast<int>(maxAttackBonus * multiplier);
        }
        // 粉色装备5阶有额外加成
        if (rarity == Rarity::PINK && upgradeLevel == 5) {
            float multiplier = 2.0f;
            hpBonus = static_cast<int>(hpBonus * multiplier);
            minAttackBonus = static_cast<int>(minAttackBonus * multiplier);
            maxAttackBonus = static_cast<int>(maxAttackBonus * multiplier);
        }
        // 橙色装备有额外加成
        if (rarity == Rarity::ORANGE) {
            float multiplier = 3.0f;
            hpBonus = static_cast<int>(hpBonus * multiplier);
            minAttackBonus = static_cast<int>(minAttackBonus * multiplier);
            maxAttackBonus = static_cast<int>(maxAttackBonus * multiplier);
        }
    }

    void display() const {
        int color;
        switch (rarity) {
        case Rarity::WHITE: color = WHITE; break;
        case Rarity::GREEN: color = GREEN; break;
        case Rarity::BLUE: color = BLUE; break;
        case Rarity::PURPLE: color = MAGENTA; break;
        case Rarity::GOLD: color = YELLOW; break;
        case Rarity::RED: color = RED; break;
        case Rarity::PINK: color = LIGHT_MAGENTA; break;
        case Rarity::ORANGE: color = ORANGE; break;
        default: color = WHITE;
        }

        SetColor(color);
        cout << name;
        if (starLevel > 0) {
            cout << " ★" << starLevel;
        }
        if (upgradeLevel > 0) {
            if (upgradeLevel == 5 && rarity == Rarity::ORANGE) {
                cout << " ↗max";
            }
            else if (upgradeLevel == 5) {
                cout << " ↗5";
            }
            else {
                cout << " ↗" << upgradeLevel;
            }
        }
        if (isEquipped) {
            cout << " [已装备]";
        }
        SetColor(WHITE);
    }

    // 获取装备战力值
    int getPowerValue() const {
        int basePower = 0;
        switch (rarity) {
        case Rarity::WHITE: basePower = 50; break;
        case Rarity::GREEN: basePower = 100; break;
        case Rarity::BLUE: basePower = 250; break;
        case Rarity::PURPLE: basePower = 500; break;
        case Rarity::GOLD: basePower = 1000; break;
        case Rarity::RED: basePower = 2500; break;
        case Rarity::PINK: basePower = 12000; break;
        case Rarity::ORANGE: basePower = 50000; break;
        default: basePower = 0;
        }

        // 星数加成
        basePower += starLevel * 10000;

        // 进阶加成
        basePower += upgradeLevel * 10000;

        // 橙色装备额外加成
        if (rarity == Rarity::ORANGE) {
            basePower *= 2;
        }

        return basePower;
    }

    // 获取装备售价
    int getSellPrice() const {
        switch (rarity) {
        case Rarity::WHITE: return 5;
        case Rarity::GREEN: return 15;
        case Rarity::BLUE: return 35;
        case Rarity::PURPLE: return 50;
        case Rarity::GOLD: return 100;
        case Rarity::RED: return 500;
        case Rarity::PINK: return 5000;
        case Rarity::ORANGE: return 50000;
        default: return 0;
        }
    }

    // 获取装备购买价
    int getBuyPrice() const {
        switch (rarity) {
        case Rarity::WHITE: return 10;
        case Rarity::GREEN: return 20;
        case Rarity::BLUE: return 45;
        case Rarity::PURPLE: return 60;
        case Rarity::GOLD: return -1;  // 不可购买
        case Rarity::RED: return -1;   // 不可购买
        case Rarity::PINK: return -1;  // 不可购买
        case Rarity::ORANGE: return -1; // 不可购买
        default: return -1;
        }
    }

    // 获取分解收益
    pair<int, int> getDecomposeReward() const {
        switch (rarity) {
        case Rarity::WHITE: return { 10, 0 };      // 传说币, 传说结晶
        case Rarity::GREEN: return { 20, 1 };
        case Rarity::BLUE: return { 30, 3 };
        case Rarity::PURPLE: return { 50, 5 };
        case Rarity::GOLD: return { 75, 7 };
        case Rarity::RED: return { 120, 10 };
        case Rarity::PINK: return { 500, 100 };
        case Rarity::ORANGE: return { 5000, 1000 };
        default: return { 0, 0 };
        }
    }

    // 检查是否可以升星
    bool canUpgradeStar(int playerCrystals) const {
        // 首先检查是否已达到最大星级
        if (!canUpgradeStarCondition()) {
            return false;
        }

        if (rarity == Rarity::RED && upgradeLevel == 0) {
            // 未进阶的红色装备
            if (starLevel == 0) return playerCrystals >= 10;
            if (starLevel == 1) return playerCrystals >= 20;
            if (starLevel == 2) return playerCrystals >= 40;
            return false;
        }
        else if (rarity == Rarity::RED && upgradeLevel == 1) {
            // 1阶红色装备
            if (starLevel == 1) return playerCrystals >= 25;
            if (starLevel == 2) return playerCrystals >= 50;
            return false;
        }
        else if (rarity == Rarity::RED && upgradeLevel == 2) {
            // 2阶红色装备
            if (starLevel == 1) return playerCrystals >= 30;
            if (starLevel == 2) return playerCrystals >= 55;
            return false;
        }
        else if (rarity == Rarity::RED && upgradeLevel == 3) {
            // 3阶红色装备
            if (starLevel == 1) return playerCrystals >= 30;
            if (starLevel == 2) return playerCrystals >= 60;
            return false;
        }
        else if (rarity == Rarity::RED && upgradeLevel == 4) {
            // 4阶红色装备
            if (starLevel == 1) return playerCrystals >= 35;
            if (starLevel == 2) return playerCrystals >= 70;
            return false;
        }
        else if (rarity == Rarity::PINK && upgradeLevel == 5) {
            // 5阶粉色装备
            switch (starLevel) {
            case 0: return true;  // 进阶后自动变为1星
            case 1: return playerCrystals >= 50;
            case 2: return playerCrystals >= 100;
            case 3: return playerCrystals >= 120;
            case 4: return playerCrystals >= 150;
            case 5: return playerCrystals >= 180;
            case 6: return playerCrystals >= 200;
            case 7: return playerCrystals >= 225;
            case 8: return playerCrystals >= 250;
            case 9: return playerCrystals >= 350;
            default: return false;
            }
        }
        else if (rarity == Rarity::ORANGE && upgradeLevel == 5) {
            // 橙色神装
            if (starLevel < 10) {
                int required = 100 + (starLevel - 1) * 20; // 二星100,三星120,四星140...
                return playerCrystals >= required;
            }
            else if (starLevel < 20) {
                int required = 350 + (starLevel - 9) * 50; // 10星之后每星增加50
                return playerCrystals >= required;
            }
            return false;
        }
        return false;
    }

    // 获取升星所需传说结晶
    int getStarUpgradeCost() const {
        if (rarity == Rarity::RED && upgradeLevel == 0) {
            if (starLevel == 0) return 10;
            if (starLevel == 1) return 20;
            if (starLevel == 2) return 40;
        }
        else if (rarity == Rarity::RED && upgradeLevel == 1) {
            if (starLevel == 1) return 25;
            if (starLevel == 2) return 50;
        }
        else if (rarity == Rarity::RED && upgradeLevel == 2) {
            if (starLevel == 1) return 30;
            if (starLevel == 2) return 55;
        }
        else if (rarity == Rarity::RED && upgradeLevel == 3) {
            if (starLevel == 1) return 30;
            if (starLevel == 2) return 60;
        }
        else if (rarity == Rarity::RED && upgradeLevel == 4) {
            if (starLevel == 1) return 35;
            if (starLevel == 2) return 70;
        }
        else if (rarity == Rarity::PINK && upgradeLevel == 5) {
            switch (starLevel) {
            case 1: return 50;
            case 2: return 100;
            case 3: return 120;
            case 4: return 150;
            case 5: return 180;
            case 6: return 200;
            case 7: return 225;
            case 8: return 250;
            case 9: return 350;
            default: return 0;
            }
        }
        else if (rarity == Rarity::ORANGE && upgradeLevel == 5) {
            if (starLevel >= 1 && starLevel < 10) {
                return 100 + (starLevel - 1) * 20;
            }
            else if (starLevel >= 10 && starLevel < 20) {
                return 350 + (starLevel - 9) * 50; // 10星之后每星增加50
            }
        }
        return 0;
    }

    // 检查是否可以进阶
    bool canUpgradeTier(int playerCoins, int playerCrystals) const {
        if (rarity == Rarity::RED) {
            // 红色装备进阶需要达到3星
            if (starLevel < 3) return false;

            auto cost = getUpgradeCost();
            // 检查是否有足够的资源
            bool canAfford = playerCoins >= cost.first && playerCrystals >= cost.second;
            // 检查是否达到最大进阶等级
            bool canUpgrade = upgradeLevel < 5;
            return canAfford && canUpgrade;
        }
        else if (rarity == Rarity::PINK && upgradeLevel == 5 && starLevel >= 10) {
            // 5阶粉色装备10星后可进化为橙色
            return playerCrystals >= 1000;
        }
        return false;
    }

    // 检查是否可以升星(仅检查条件,不检查资源)
    bool canUpgradeStarCondition() const {
        if (rarity == Rarity::RED) {
            if (upgradeLevel == 0) return starLevel < 3;  // 未进阶红色最多3星
            else if (upgradeLevel < 5) return starLevel < 3;  // 进阶红色也最多3星
            else if (upgradeLevel == 5 && rarity == Rarity::PINK) {
                return starLevel < 10;  // 5阶粉色最多10星
            }
        }
        else if (rarity == Rarity::PINK && upgradeLevel == 5) {
            return starLevel < 10;  // 粉色装备最多10星
        }
        else if (rarity == Rarity::ORANGE) {
            return starLevel < 20;  // 橙色装备最多20星
        }
        return false;
    }

    // 检查是否可以进阶(仅检查条件,不检查资源)
    bool canUpgradeTierCondition() const {
        if (rarity == Rarity::RED) {
            // 红色装备需要达到3星并且未达到最大进阶等级
            return starLevel >= 3 && upgradeLevel < 5;
        }
        else if (rarity == Rarity::PINK && upgradeLevel == 5) {
            // 5阶粉色装备需要达到10星
            return starLevel >= 10;
        }
        return false;
    }

    // 获取进阶所需资源
    pair<int, int> getUpgradeCost() const {
        if (rarity != Rarity::RED) return { 0, 0 };

        switch (upgradeLevel) {
        case 0: return { 250, 10 };    // 传说币, 传说结晶
        case 1: return { 500, 20 };
        case 2: return { 800, 30 };
        case 3: return { 1500, 55 };
        case 4: return { 7500, 500 };
        default: return { 0, 0 };
        }
    }

    // 生成进阶后的装备
    Equipment getUpgradedEquipment() const {
        if (rarity == Rarity::PINK && upgradeLevel == 5 && starLevel >= 10) {
            // 5阶粉色10星进化为橙色
            string newName;
            switch (type) {
            case EquipmentType::HELMET: newName = "传奇的神之盔"; break;
            case EquipmentType::ARMOR: newName = "传奇的神之铠"; break;
            case EquipmentType::BOOTS: newName = "传奇的神之靴"; break;
            case EquipmentType::WEAPON: newName = "传奇的神明之剑"; break;
            case EquipmentType::SHIELD: newName = "传奇的神明之盾"; break;
            }

            // 计算基础属性
            int baseHp = hpBonus;
            int baseMinAtk = minAttackBonus;
            int baseMaxAtk = maxAttackBonus;

            // 移除粉色5阶加成
            float pinkMultiplier = 1.0f / 2.0f;
            baseHp = static_cast<int>(baseHp * pinkMultiplier);
            baseMinAtk = static_cast<int>(baseMinAtk * pinkMultiplier);
            baseMaxAtk = static_cast<int>(baseMaxAtk * pinkMultiplier);

            // 移除星数加成
            if (starLevel > 0) {
                float starMultiplier = 1.0f / (1.0f + starLevel * 0.25f);
                baseHp = static_cast<int>(baseHp * starMultiplier);
                baseMinAtk = static_cast<int>(baseMinAtk * starMultiplier);
                baseMaxAtk = static_cast<int>(baseMaxAtk * starMultiplier);
            }

            return Equipment(newName, type, Rarity::ORANGE, baseHp, baseMinAtk, baseMaxAtk,
                1, 5, true, isEquipped); // 橙色装备初始1星,5阶
        }

        if (rarity != Rarity::RED) return *this;

        string newName = name;
        int newUpgradeLevel = upgradeLevel + 1;
        Rarity newRarity = (newUpgradeLevel == 5) ? Rarity::PINK : Rarity::RED;

        // 根据进阶等级设置新名称
        if (newUpgradeLevel == 1) {
            switch (type) {
            case EquipmentType::HELMET: newName = "守望之窥"; break;
            case EquipmentType::ARMOR: newName = "守望护身甲"; break;
            case EquipmentType::BOOTS: newName = "守望之靴"; break;
            case EquipmentType::WEAPON: newName = "叱咤天煞剑"; break;
            case EquipmentType::SHIELD: newName = "螟蛉护身盾"; break;
            }
        }
        else if (newUpgradeLevel == 2) {
            switch (type) {
            case EquipmentType::HELMET: newName = "天灾魔神盔"; break;
            case EquipmentType::ARMOR: newName = "天灾魔神甲"; break;
            case EquipmentType::BOOTS: newName = "天灾魔神靴"; break;
            case EquipmentType::WEAPON: newName = "魔神斩杀刃"; break;
            case EquipmentType::SHIELD: newName = "恶鬼皆灭盾"; break;
            }
        }
        else if (newUpgradeLevel == 3) {
            switch (type) {
            case EquipmentType::HELMET: newName = "维圣之盔"; break;
            case EquipmentType::ARMOR: newName = "维圣神甲"; break;
            case EquipmentType::BOOTS: newName = "维圣神靴"; break;
            case EquipmentType::WEAPON: newName = "维护天意之剑"; break;
            case EquipmentType::SHIELD: newName = "维护自身之盾"; break;
            }
        }
        else if (newUpgradeLevel == 4) {
            switch (type) {
            case EquipmentType::HELMET: newName = "源天煞蔑视"; break;
            case EquipmentType::ARMOR: newName = "源虚空之体"; break;
            case EquipmentType::BOOTS: newName = "源凋零之遂"; break;
            case EquipmentType::WEAPON: newName = "源魔魂之斩杀"; break;
            case EquipmentType::SHIELD: newName = "源天地之庇护"; break;
            }
        }
        else if (newUpgradeLevel == 5) {
            switch (type) {
            case EquipmentType::HELMET: newName = "化神明之圣盔"; break;
            case EquipmentType::ARMOR: newName = "化神明之圣甲"; break;
            case EquipmentType::BOOTS: newName = "化神明之圣靴"; break;
            case EquipmentType::WEAPON: newName = "万神皆可灭之神剑"; break;
            case EquipmentType::SHIELD: newName = "万物皆可防之盾"; break;
            }
        }

        // 计算基础属性(移除现有加成)
        int baseHp = hpBonus;
        int baseMinAtk = minAttackBonus;
        int baseMaxAtk = maxAttackBonus;

        if (starLevel > 0) {
            float starMultiplier = 1.0f / (1.0f + starLevel * 0.25f);
            baseHp = static_cast<int>(baseHp * starMultiplier);
            baseMinAtk = static_cast<int>(baseMinAtk * starMultiplier);
            baseMaxAtk = static_cast<int>(baseMaxAtk * starMultiplier);
        }

        if (upgradeLevel > 0) {
            float upgradeMultiplier = 1.0f / (1.0f + upgradeLevel * 0.25f);
            baseHp = static_cast<int>(baseHp * upgradeMultiplier);
            baseMinAtk = static_cast<int>(baseMinAtk * upgradeMultiplier);
            baseMaxAtk = static_cast<int>(baseMaxAtk * upgradeMultiplier);
        }

        return Equipment(newName, type, newRarity, baseHp, baseMinAtk, baseMaxAtk,
            1, newUpgradeLevel, true, isEquipped); // 进阶后变为1星
    }
};

class Monster {
public:
    string name;
    int x, y;
    int maxHp;
    int currentHp;
    int maxAttack;
    bool isBoss;
    bool alive;

    Monster(string n, int posX, int posY, int hp, int atk, bool boss = false)
        : name(n), x(posX), y(posY), maxHp(hp), currentHp(hp), maxAttack(atk), isBoss(boss), alive(true) {
    }

    void takeDamage(int damage) {
        currentHp -= damage;
        if (currentHp <= 0) {
            currentHp = 0;
            alive = false;
        }
    }

    int attack() const {
        return rand() % maxAttack + 1;
    }

    void display() const {
        if (isBoss) {
            SetColor(RED);
            cout << "龙";
        }
        else {
            SetColor(GREEN);
            cout << "$";
        }
        SetColor(WHITE);
    }

    // 显示怪物血条
    void displayHealthBar(int x, int y) const {
        SetCursorPosition(x, y);
        cout << name << ": ";

        // 计算血条长度
        int barLength = 20;
        int filledLength = (currentHp * barLength) / maxHp;

        // 根据血量比例设置颜色
        float healthPercent = (float)currentHp / maxHp;
        if (healthPercent > 0.6) SetColor(GREEN);
        else if (healthPercent > 0.3) SetColor(YELLOW);
        else SetColor(RED);

        // 绘制血条
        cout << "[";
        for (int i = 0; i < barLength; i++) {
            if (i < filledLength) cout << "█";
            else cout << " ";
        }
        cout << "]";

        // 显示具体数值
        SetColor(WHITE);
        cout << " " << currentHp << "/" << maxHp;
    }
};

class Player {
public:
    string name;
    int x, y;
    int level;
    int maxHp;
    int currentHp;
    int maxAttack;
    int minAttack;
    int totalPower;  // 总战力
    int legendCoins;  // 传说币
    int legendCrystals; // 传说结晶
    vector<Equipment> inventory;
    vector<pair<string, int>> items; // 杂物列表
    Equipment* helmet;
    Equipment* armor;
    Equipment* boots;
    Equipment* weapon;
    Equipment* shield;
    string currentMap;
    int monstersDefeated;  // 已击败怪物数量
    Monster* lastAttackedMonster; // 最后攻击的怪物

    Player(string n)
        : name(n), x(1), y(1), level(1), maxHp(4000), currentHp(4000),
        maxAttack(500), minAttack(150), totalPower(0), legendCoins(0), legendCrystals(0), helmet(nullptr), armor(nullptr),
        boots(nullptr), weapon(nullptr), shield(nullptr), currentMap("皇城"), monstersDefeated(0),
        lastAttackedMonster(nullptr) {
        // 初始化杂物列表
        items.push_back({ "传说币", 0 });
        items.push_back({ "传说结晶", 0 });
        updatePower();  // 初始化战力
    }

    ~Player() {
        if (helmet) delete helmet;
        if (armor) delete armor;
        if (boots) delete boots;
        if (weapon) delete weapon;
        if (shield) delete shield;
    }

    void respawn() {
        x = 1;
        y = 1;
        currentHp = maxHp;
        currentMap = "皇城";
        lastAttackedMonster = nullptr;
    }

    // 每击败2个怪物提升1级,等级上限200级
    void addMonsterDefeated() {
        monstersDefeated++;
        if (monstersDefeated % 2 == 0) {
            if (level < 200) {
                levelUp();
            }
        }
    }

    void levelUp() {
        if (level >= 200) return;

        level++;
        maxHp += 25;
        currentHp = maxHp;
        maxAttack += 15;
        minAttack += 10;

        updatePower();
    }

    void equip(Equipment* item) {
        Equipment* oldItem = nullptr;

        switch (item->type) {
        case EquipmentType::HELMET:
            oldItem = helmet;
            helmet = item;
            if (oldItem) oldItem->isEquipped = false;
            item->isEquipped = true;
            break;
        case EquipmentType::ARMOR:
            oldItem = armor;
            armor = item;
            if (oldItem) oldItem->isEquipped = false;
            item->isEquipped = true;
            break;
        case EquipmentType::BOOTS:
            oldItem = boots;
            boots = item;
            if (oldItem) oldItem->isEquipped = false;
            item->isEquipped = true;
            break;
        case EquipmentType::WEAPON:
            oldItem = weapon;
            weapon = item;
            if (oldItem) oldItem->isEquipped = false;
            item->isEquipped = true;
            break;
        case EquipmentType::SHIELD:
            oldItem = shield;
            shield = item;
            if (oldItem) oldItem->isEquipped = false;
            item->isEquipped = true;
            break;
        }

        if (oldItem) {
            maxHp -= oldItem->hpBonus;
            maxAttack -= oldItem->maxAttackBonus;
            minAttack -= oldItem->minAttackBonus;

            inventory.push_back(*oldItem);
            delete oldItem;
        }

        maxHp += item->hpBonus;
        maxAttack += item->maxAttackBonus;
        minAttack += item->minAttackBonus;
        currentHp = min(currentHp, maxHp);

        updatePower();
    }

    // 更新战力和玩家颜色
    void updatePower() {
        totalPower = level * 100;  // 基础战力:每级100点

        if (helmet) totalPower += helmet->getPowerValue();
        if (armor) totalPower += armor->getPowerValue();
        if (boots) totalPower += boots->getPowerValue();
        if (weapon) totalPower += weapon->getPowerValue();
        if (shield) totalPower += shield->getPowerValue();
    }

    // 获取玩家颜色(根据全套装备品质)
    int getPlayerColor() const {
        if (!helmet || !armor || !boots || !weapon || !shield) {
            return WHITE;  // 缺装备时显示白色
        }

        // 检查是否全套同品质装备
        Rarity helmetRarity = helmet->rarity;
        if (armor->rarity == helmetRarity &&
            boots->rarity == helmetRarity &&
            weapon->rarity == helmetRarity &&
            shield->rarity == helmetRarity) {

            switch (helmetRarity) {
            case Rarity::WHITE: return WHITE;
            case Rarity::GREEN: return GREEN;
            case Rarity::BLUE: return BLUE;
            case Rarity::PURPLE: return MAGENTA;
            case Rarity::GOLD: return YELLOW;
            case Rarity::RED: return RED;
            case Rarity::PINK: return LIGHT_MAGENTA;
            case Rarity::ORANGE: return ORANGE;
            default: return WHITE;
            }
        }

        return WHITE;  // 不是全套同品质装备时显示白色
    }

    int attack() const {
        return rand() % (maxAttack - minAttack + 1) + minAttack;
    }

    void takeDamage(int damage) {
        currentHp -= damage;
        if (currentHp < 0) currentHp = 0;
    }

    void heal(int amount) {
        currentHp += amount;
        if (currentHp > maxHp) currentHp = maxHp;
    }

    // 增加传说币
    void addLegendCoins(int amount) {
        legendCoins += amount;
        // 更新杂物列表
        for (auto& item : items) {
            if (item.first == "传说币") {
                item.second = legendCoins;
                break;
            }
        }
    }

    // 增加传说结晶
    void addLegendCrystals(int amount) {
        legendCrystals += amount;
        // 更新杂物列表
        for (auto& item : items) {
            if (item.first == "传说结晶") {
                item.second = legendCrystals;
                break;
            }
        }
    }

    // 减少传说币(购买物品)
    bool spendLegendCoins(int amount) {
        if (legendCoins >= amount) {
            legendCoins -= amount;
            // 更新杂物列表
            for (auto& item : items) {
                if (item.first == "传说币") {
                    item.second = legendCoins;
                    break;
                }
            }
            return true;
        }
        return false;
    }

    // 减少传说结晶
    bool spendLegendCrystals(int amount) {
        if (legendCrystals >= amount) {
            legendCrystals -= amount;
            // 更新杂物列表
            for (auto& item : items) {
                if (item.first == "传说结晶") {
                    item.second = legendCrystals;
                    break;
                }
            }
            return true;
        }
        return false;
    }

    void displayStats(int x, int y) const {
        SetCursorPosition(x, y++);
        cout << "玩家: " << name;
        SetCursorPosition(x, y++);
        cout << "等级: " << level << " (击败怪物: " << monstersDefeated << "/" << (level * 2) << ")";
        SetCursorPosition(x, y++);
        cout << "战力: " << totalPower;
        SetCursorPosition(x, y++);
        cout << "生命: " << currentHp << "/" << maxHp;
        SetCursorPosition(x, y++);
        cout << "攻击: " << minAttack << "-" << maxAttack;
        SetCursorPosition(x, y++);
        cout << "头盔: ";
        if (helmet) helmet->display();
        else cout << "无";
        SetCursorPosition(x, y++);
        cout << "护甲: ";
        if (armor) armor->display();
        else cout << "无";
        SetCursorPosition(x, y++);
        cout << "鞋子: ";
        if (boots) boots->display();
        else cout << "无";
        SetCursorPosition(x, y++);
        cout << "武器: ";
        if (weapon) weapon->display();
        else cout << "无";
        SetCursorPosition(x, y++);
        cout << "盾牌: ";
        if (shield) shield->display();
        else cout << "无";
        SetCursorPosition(x, y++);
        cout << "传说币: " << legendCoins;
        SetCursorPosition(x, y++);
        cout << "传说结晶: " << legendCrystals;
    }

    // 丢弃背包中的物品
    bool discardItem(int index) {
        if (index < 0 || index >= inventory.size()) {
            return false;
        }
        inventory.erase(inventory.begin() + index);
        return true;
    }

    // 分解背包中的物品
    bool decomposeItem(int index) {
        if (index < 0 || index >= inventory.size()) {
            return false;
        }
        auto reward = inventory[index].getDecomposeReward();
        legendCoins += reward.first;
        legendCrystals += reward.second;

        // 更新杂物列表
        for (auto& item : items) {
            if (item.first == "传说币") {
                item.second = legendCoins;
            }
            else if (item.first == "传说结晶") {
                item.second = legendCrystals;
            }
        }

        inventory.erase(inventory.begin() + index);
        return true;
    }

    // 获取所有装备列表(包括背包和已装备的)
    vector<Equipment*> getAllEquipment() {
        vector<Equipment*> allEquip;

        // 添加已装备的装备
        if (helmet) allEquip.push_back(helmet);
        if (armor) allEquip.push_back(armor);
        if (boots) allEquip.push_back(boots);
        if (weapon) allEquip.push_back(weapon);
        if (shield) allEquip.push_back(shield);

        // 添加背包中的装备(确保不重复添加已装备的装备)
        for (auto& eq : inventory) {
            bool isEquipped = false;

            // 检查这个装备是否已经通过指针添加到列表中
            if (helmet && eq.name == helmet->name && eq.starLevel == helmet->starLevel && eq.upgradeLevel == helmet->upgradeLevel) {
                isEquipped = true;
            }
            else if (armor && eq.name == armor->name && eq.starLevel == armor->starLevel && eq.upgradeLevel == armor->upgradeLevel) {
                isEquipped = true;
            }
            else if (boots && eq.name == boots->name && eq.starLevel == boots->starLevel && eq.upgradeLevel == boots->upgradeLevel) {
                isEquipped = true;
            }
            else if (weapon && eq.name == weapon->name && eq.starLevel == weapon->starLevel && eq.upgradeLevel == weapon->upgradeLevel) {
                isEquipped = true;
            }
            else if (shield && eq.name == shield->name && eq.starLevel == shield->starLevel && eq.upgradeLevel == shield->upgradeLevel) {
                isEquipped = true;
            }

            if (!isEquipped) {
                allEquip.push_back(&eq);
            }
        }

        return allEquip;
    }

    // 升星装备(支持已装备的装备)
    bool upgradeStar(int index) {
        auto allEquip = getAllEquipment();
        if (index < 0 || index >= allEquip.size()) {
            return false;
        }

        Equipment* equipment = allEquip[index];
        if (!equipment->canUpgradeStar(legendCrystals)) {
            return false;
        }

        // 检查资源
        int cost = equipment->getStarUpgradeCost();
        if (cost > 0 && !spendLegendCrystals(cost)) {
            return false;
        }

        // 更新装备属性
        equipment->starLevel++;
        float multiplier = 1.25f; // 25%提升

        // 计算基础属性
        int baseHp = equipment->hpBonus;
        int baseMinAtk = equipment->minAttackBonus;
        int baseMaxAtk = equipment->maxAttackBonus;

        // 移除旧的加成
        if (equipment->starLevel > 1) {
            float oldMultiplier = 1.0f / (1.0f + (equipment->starLevel - 1) * 0.25f);
            baseHp = static_cast<int>(baseHp * oldMultiplier);
            baseMinAtk = static_cast<int>(baseMinAtk * oldMultiplier);
            baseMaxAtk = static_cast<int>(baseMaxAtk * oldMultiplier);
        }

        // 应用新的加成
        equipment->hpBonus = static_cast<int>(baseHp * multiplier);
        equipment->minAttackBonus = static_cast<int>(baseMinAtk * multiplier);
        equipment->maxAttackBonus = static_cast<int>(baseMaxAtk * multiplier);

        // 如果装备已装备,更新玩家属性
        if (equipment->isEquipped) {
            // 重新计算玩家属性
            maxHp = 4000 + (level - 1) * 25;
            minAttack = 150 + (level - 1) * 10;
            maxAttack = 500 + (level - 1) * 15;

            if (helmet) {
                maxHp += helmet->hpBonus;
                minAttack += helmet->minAttackBonus;
                maxAttack += helmet->maxAttackBonus;
            }
            if (armor) {
                maxHp += armor->hpBonus;
                minAttack += armor->minAttackBonus;
                maxAttack += armor->maxAttackBonus;
            }
            if (boots) {
                maxHp += boots->hpBonus;
                minAttack += boots->minAttackBonus;
                maxAttack += boots->maxAttackBonus;
            }
            if (weapon) {
                maxHp += weapon->hpBonus;
                minAttack += weapon->minAttackBonus;
                maxAttack += weapon->maxAttackBonus;
            }
            if (shield) {
                maxHp += shield->hpBonus;
                minAttack += shield->minAttackBonus;
                maxAttack += shield->maxAttackBonus;
            }

            currentHp = min(currentHp, maxHp);
            updatePower();
        }

        return true;
    }

    // 进阶装备(支持已装备的装备)
    bool upgradeTier(int index) {
        auto allEquip = getAllEquipment();
        if (index < 0 || index >= allEquip.size()) {
            return false;
        }

        Equipment* equipment = allEquip[index];
        if (!equipment->canUpgradeTier(legendCoins, legendCrystals)) {
            return false;
        }

        if (equipment->rarity == Rarity::RED) {
            // 红色装备进阶
            auto cost = equipment->getUpgradeCost();
            if (!spendLegendCoins(cost.first) || !spendLegendCrystals(cost.second)) {
                return false;
            }

            // 进阶装备
            Equipment upgraded = equipment->getUpgradedEquipment();
            if (equipment->isEquipped) {
                // 如果是已装备的装备,直接替换
                switch (equipment->type) {
                case EquipmentType::HELMET:
                    delete helmet;
                    helmet = new Equipment(upgraded);
                    break;
                case EquipmentType::ARMOR:
                    delete armor;
                    armor = new Equipment(upgraded);
                    break;
                case EquipmentType::BOOTS:
                    delete boots;
                    boots = new Equipment(upgraded);
                    break;
                case EquipmentType::WEAPON:
                    delete weapon;
                    weapon = new Equipment(upgraded);
                    break;
                case EquipmentType::SHIELD:
                    delete shield;
                    shield = new Equipment(upgraded);
                    break;
                }

                // 更新玩家属性
                maxHp = 4000 + (level - 1) * 25;
                minAttack = 150 + (level - 1) * 10;
                maxAttack = 500 + (level - 1) * 15;

                if (helmet) {
                    maxHp += helmet->hpBonus;
                    minAttack += helmet->minAttackBonus;
                    maxAttack += helmet->maxAttackBonus;
                }
                if (armor) {
                    maxHp += armor->hpBonus;
                    minAttack += armor->minAttackBonus;
                    maxAttack += armor->maxAttackBonus;
                }
                if (boots) {
                    maxHp += boots->hpBonus;
                    minAttack += boots->minAttackBonus;
                    maxAttack += boots->maxAttackBonus;
                }
                if (weapon) {
                    maxHp += weapon->hpBonus;
                    minAttack += weapon->minAttackBonus;
                    maxAttack += weapon->maxAttackBonus;
                }
                if (shield) {
                    maxHp += shield->hpBonus;
                    minAttack += shield->minAttackBonus;
                    maxAttack += shield->maxAttackBonus;
                }

                currentHp = min(currentHp, maxHp);
                updatePower();
            }
            else {
                // 如果是背包中的装备,在背包中替换
                for (auto& eq : inventory) {
                    if (&eq == equipment) {
                        eq = upgraded;
                        break;
                    }
                }
            }
        }
        else if (equipment->rarity == Rarity::PINK && equipment->upgradeLevel == 5 && equipment->starLevel >= 10) {
            // 粉色5阶10星进化为橙色
            if (!spendLegendCrystals(1000)) {
                return false;
            }

            Equipment upgraded = equipment->getUpgradedEquipment();
            if (equipment->isEquipped) {
                // 如果是已装备的装备,直接替换
                switch (equipment->type) {
                case EquipmentType::HELMET:
                    delete helmet;
                    helmet = new Equipment(upgraded);
                    break;
                case EquipmentType::ARMOR:
                    delete armor;
                    armor = new Equipment(upgraded);
                    break;
                case EquipmentType::BOOTS:
                    delete boots;
                    boots = new Equipment(upgraded);
                    break;
                case EquipmentType::WEAPON:
                    delete weapon;
                    weapon = new Equipment(upgraded);
                    break;
                case EquipmentType::SHIELD:
                    delete shield;
                    shield = new Equipment(upgraded);
                    break;
                }

                // 更新玩家属性
                maxHp = 4000 + (level - 1) * 25;
                minAttack = 150 + (level - 1) * 10;
                maxAttack = 500 + (level - 1) * 15;

                if (helmet) {
                    maxHp += helmet->hpBonus;
                    minAttack += helmet->minAttackBonus;
                    maxAttack += helmet->maxAttackBonus;
                }
                if (armor) {
                    maxHp += armor->hpBonus;
                    minAttack += armor->minAttackBonus;
                    maxAttack += armor->maxAttackBonus;
                }
                if (boots) {
                    maxHp += boots->hpBonus;
                    minAttack += boots->minAttackBonus;
                    maxAttack += boots->maxAttackBonus;
                }
                if (weapon) {
                    maxHp += weapon->hpBonus;
                    minAttack += weapon->minAttackBonus;
                    maxAttack += weapon->maxAttackBonus;
                }
                if (shield) {
                    maxHp += shield->hpBonus;
                    minAttack += shield->minAttackBonus;
                    maxAttack += shield->maxAttackBonus;
                }

                currentHp = min(currentHp, maxHp);
                updatePower();
            }
            else {
                // 如果是背包中的装备,在背包中替换
                for (auto& eq : inventory) {
                    if (&eq == equipment) {
                        eq = upgraded;
                        break;
                    }
                }
            }
        }

        return true;
    }
};

class Game {
private:
    Player* player;
    vector<Monster> monsters;
    bool gameRunning;
    bool inInventory;
    bool inCharacterSelection;
    bool inShop;  // 是否在商店界面
    bool inForge; // 是否在锻造界面
    bool sellingItems;
    bool buyingItems;
    bool forgingItems; // 锻造子菜单
    bool upgradingStar; // 装备升星
    bool upgradingTier; // 装备进阶
    bool decomposingItems; // 装备分解
    bool viewingItems;    // 查看物品
    bool viewingEquipment;// 查看装备
    int selectedInventoryItem;
    int selectedShopItem;
    int selectedBuyItem;
    int selectedForgeItem; // 锻造选项选择
    int selectedEquipmentItem; // 装备选择
    vector<string> characterNames;
    int selectedCharacter;
    bool bossSpawned;
    int screenWidth;
    int screenHeight;
    int normalMonstersDefeated;
    int bossesDefeated;
    int monstersDefeatedCount;

    // 商店可购买的装备列表
    vector<Equipment> shopItems;

    void SetFullScreen() {
        HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        SMALL_RECT rect = { 0, 0, 119, 49 };
        SetConsoleWindowInfo(hConsole, TRUE, &rect);

        COORD size = { 120, 500 };
        SetConsoleScreenBufferSize(hConsole, size);

        CONSOLE_SCREEN_BUFFER_INFO csbi;
        GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
        screenWidth = csbi.srWindow.Right - csbi.srWindow.Left + 1;
        screenHeight = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
    }

    Equipment* generateRandomEquipment(Rarity rarity) {
        string name;
        EquipmentType type = static_cast<EquipmentType>(rand() % 5);
        int hpBonus = 0, minAtkBonus = 0, maxAtkBonus = 0;

        switch (rarity) {
        case Rarity::WHITE:
            switch (type) {
            case EquipmentType::HELMET: name = "草帽"; hpBonus = 50; break;
            case EquipmentType::ARMOR: name = "布衣"; hpBonus = 100; break;
            case EquipmentType::BOOTS: name = "草鞋"; hpBonus = 15; break;
            case EquipmentType::WEAPON: name = "匕首"; maxAtkBonus = 25; minAtkBonus = 5; break;
            case EquipmentType::SHIELD: name = "木盾"; hpBonus = 15; break;
            } break;
        case Rarity::GREEN:
            switch (type) {
            case EquipmentType::HELMET: name = "铜质头盔"; hpBonus = 75; break;
            case EquipmentType::ARMOR: name = "铜质盔甲"; hpBonus = 125; break;
            case EquipmentType::BOOTS: name = "铜质护靴"; hpBonus = 45; break;
            case EquipmentType::WEAPON: name = "铜剑"; maxAtkBonus = 40; minAtkBonus = 10; break;
            case EquipmentType::SHIELD: name = "铜质盾牌"; hpBonus = 35; break;
            } break;
        case Rarity::BLUE:
            switch (type) {
            case EquipmentType::HELMET: name = "乌金护额"; hpBonus = 100; break;
            case EquipmentType::ARMOR: name = "乌金护甲"; hpBonus = 140; break;
            case EquipmentType::BOOTS: name = "乌金战靴"; hpBonus = 70; break;
            case EquipmentType::WEAPON: name = "乌金剑"; maxAtkBonus = 65; minAtkBonus = 20; break;
            case EquipmentType::SHIELD: name = "乌金盾"; hpBonus = 60; break;
            } break;
        case Rarity::PURPLE:
            switch (type) {
            case EquipmentType::HELMET: name = "精钢头盔"; hpBonus = 125; break;
            case EquipmentType::ARMOR: name = "精钢护甲"; hpBonus = 165; break;
            case EquipmentType::BOOTS: name = "精钢战靴"; hpBonus = 100; break;
            case EquipmentType::WEAPON: name = "精钢之剑"; maxAtkBonus = 100; minAtkBonus = 50; break;
            case EquipmentType::SHIELD: name = "护身之盾"; hpBonus = 100; break;
            } break;
        case Rarity::GOLD:
            switch (type) {
            case EquipmentType::HELMET: name = "魔神战盔"; hpBonus = 180; break;
            case EquipmentType::ARMOR: name = "魔神铠甲"; hpBonus = 250; break;
            case EquipmentType::BOOTS: name = "魔神战靴"; hpBonus = 180; break;
            case EquipmentType::WEAPON: name = "赤血魔神剑"; maxAtkBonus = 150; minAtkBonus = 85; break;
            case EquipmentType::SHIELD: name = "护身的魔神盾"; hpBonus = 150; break;
            } break;
        case Rarity::RED:
            switch (type) {
            case EquipmentType::HELMET: name = "龙魂头盔"; hpBonus = 225; break;
            case EquipmentType::ARMOR: name = "龙魂战铠"; hpBonus = 275; break;
            case EquipmentType::BOOTS: name = "龙魂战靴"; hpBonus = 225; break;
            case EquipmentType::WEAPON: name = "龙魂双刃剑"; maxAtkBonus = 200; minAtkBonus = 100; break;
            case EquipmentType::SHIELD: name = "神圣的龙魂盾"; hpBonus = 225; break;
            } break;
        default:
            // 默认返回白色装备
            name = "草帽"; hpBonus = 50; break;
        }

        return new Equipment(name, type, rarity, hpBonus, minAtkBonus, maxAtkBonus);
    }

    bool isValidPosition(int x, int y) {
        if (x <= 0 || x >= 99 || y <= 0 || y >= 49) return false;

        if (player->currentMap == "皇城") {
            vector<pair<int, int>> houses = {
                {2,2}, {2,4}, {2,5}, {2,7}, {2,8},
                {4,2}, {4,4}, {4,5}, {4,7}, {4,8},
                {5,2}, {5,4}, {5,5}, {5,7}, {5,8},
                {7,2}, {7,4}, {7,5}, {7,7}, {7,8}
            };
            for (auto& house : houses) {
                if (x == house.first && y == house.second) return false;
            }
        }

        for (auto& monster : monsters) {
            if (monster.alive && monster.x == x && monster.y == y) return false;
        }

        if (player->x == x && player->y == y) return false;

        return true;
    }

    void generateMonsters() {
        monsters.clear();
        bossSpawned = false;
        monstersDefeatedCount = 0;

        if (player->currentMap == "虚空领域") {
            int monstersGenerated = 0;
            while (monstersGenerated < 15) {
                int x = rand() % 96 + 2;
                int y = rand() % 46 + 2;
                if (isValidPosition(x, y)) {
                    monsters.emplace_back("虚空使者", x, y, 4000, 500);
                    monstersGenerated++;
                }
            }
        }
    }

    void generateBoss() {
        if (player->currentMap == "虚空领域" && !bossSpawned) {
            int x, y;
            do {
                x = rand() % 96 + 2;
                y = rand() % 46 + 2;
            } while (!isValidPosition(x, y));

            monsters.emplace_back("魔龙领主", x, y, 12000, 800, true);
            bossSpawned = true;

            SetCursorPosition(0, 52);
            cout << "警告!魔龙领主降临了!";
        }
    }

    // 初始化商店物品
    void initializeShop() {
        shopItems.clear();

        // 添加白色品质装备
        shopItems.push_back(Equipment("草帽", EquipmentType::HELMET, Rarity::WHITE, 50, 0, 0));
        shopItems.push_back(Equipment("布衣", EquipmentType::ARMOR, Rarity::WHITE, 100, 0, 0));
        shopItems.push_back(Equipment("草鞋", EquipmentType::BOOTS, Rarity::WHITE, 15, 0, 0));
        shopItems.push_back(Equipment("匕首", EquipmentType::WEAPON, Rarity::WHITE, 0, 5, 25));
        shopItems.push_back(Equipment("木盾", EquipmentType::SHIELD, Rarity::WHITE, 15, 0, 0));

        // 添加绿色品质装备
        shopItems.push_back(Equipment("铜质头盔", EquipmentType::HELMET, Rarity::GREEN, 75, 0, 0));
        shopItems.push_back(Equipment("铜质盔甲", EquipmentType::ARMOR, Rarity::GREEN, 125, 0, 0));
        shopItems.push_back(Equipment("铜质护靴", EquipmentType::BOOTS, Rarity::GREEN, 45, 0, 0));
        shopItems.push_back(Equipment("铜剑", EquipmentType::WEAPON, Rarity::GREEN, 0, 10, 40));
        shopItems.push_back(Equipment("铜质盾牌", EquipmentType::SHIELD, Rarity::GREEN, 35, 0, 0));

        // 添加蓝色品质装备
        shopItems.push_back(Equipment("乌金护额", EquipmentType::HELMET, Rarity::BLUE, 100, 0, 0));
        shopItems.push_back(Equipment("乌金护甲", EquipmentType::ARMOR, Rarity::BLUE, 140, 0, 0));
        shopItems.push_back(Equipment("乌金战靴", EquipmentType::BOOTS, Rarity::BLUE, 70, 0, 0));
        shopItems.push_back(Equipment("乌金剑", EquipmentType::WEAPON, Rarity::BLUE, 0, 20, 65));
        shopItems.push_back(Equipment("乌金盾", EquipmentType::SHIELD, Rarity::BLUE, 60, 0, 0));

        // 添加紫色品质装备
        shopItems.push_back(Equipment("精钢头盔", EquipmentType::HELMET, Rarity::PURPLE, 125, 0, 0));
        shopItems.push_back(Equipment("精钢护甲", EquipmentType::ARMOR, Rarity::PURPLE, 165, 0, 0));
        shopItems.push_back(Equipment("精钢战靴", EquipmentType::BOOTS, Rarity::PURPLE, 100, 0, 0));
        shopItems.push_back(Equipment("精钢之剑", EquipmentType::WEAPON, Rarity::PURPLE, 0, 50, 100));
        shopItems.push_back(Equipment("护身之盾", EquipmentType::SHIELD, Rarity::PURPLE, 100, 0, 0));
    }

    void drawGame() {
        system("cls");

        for (int y = 0; y < 50; y++) {
            for (int x = 0; x < 100; x++) {
                if (x == 0 || x == 99 || y == 0 || y == 49) {
                    SetCursorPosition(x, y);
                    cout << "#";
                }
            }
        }

        if (player->currentMap == "皇城") {
            vector<pair<int, int>> houses = {
                {2,2}, {2,4}, {2,5}, {2,7}, {2,8},
                {4,2}, {4,4}, {4,5}, {4,7}, {4,8},
                {5,2}, {5,4}, {5,5}, {5,7}, {5,8},
                {7,2}, {7,4}, {7,5}, {7,7}, {7,8}
            };
            for (auto& house : houses) {
                SetCursorPosition(house.first, house.second);
                cout << "^";
            }
        }

        for (auto& monster : monsters) {
            if (monster.alive) {
                SetCursorPosition(monster.x, monster.y);
                monster.display();
            }
        }

        SetCursorPosition(player->x, player->y);
        // 根据装备品质设置玩家颜色
        SetColor(player->getPlayerColor());
        cout << "乂";
        SetColor(WHITE);

        int statsX = 101;
        int statsY = 0;
        player->displayStats(statsX, statsY);

        // 显示最后攻击的怪物血条
        if (player->lastAttackedMonster && player->lastAttackedMonster->alive) {
            player->lastAttackedMonster->displayHealthBar(101, 20);
        }

        SetCursorPosition(0, 50);
    }

    // 绘制背包界面
    void drawInventoryMenu() {
        system("cls");

        int startX = 40;
        int startY = 10;

        SetCursorPosition(startX, startY);
        cout << "===== 背 包 =====";

        SetCursorPosition(startX, startY + 2);
        cout << "传说币: " << player->legendCoins << "  传说结晶: " << player->legendCrystals;

        SetCursorPosition(startX, startY + 4);
        if (selectedShopItem == 0) {
            cout << "> ";
        }
        else {
            cout << "  ";
        }
        cout << "装备";

        SetCursorPosition(startX, startY + 5);
        if (selectedShopItem == 1) {
            cout << "> ";
        }
        else {
            cout << "  ";
        }
        cout << "物品";

        SetCursorPosition(startX, startY + 6);
        if (selectedShopItem == 2) {
            cout << "> ";
        }
        else {
            cout << "  ";
        }
        cout << "离开背包";

        SetCursorPosition(startX, startY + 8);
        cout << "使用W/S选择,回车确认";
        SetCursorPosition(startX, startY + 9);
        cout << "ESC返回游戏";
    }

    // 绘制装备列表
    void drawEquipmentList() {
        system("cls");

        int startX = 30;
        int startY = 5;

        SetCursorPosition(startX, startY);
        cout << "===== 装 备 列 表 =====";

        SetCursorPosition(startX, startY + 2);
        cout << "背包装备:";

        for (int i = 0; i < player->inventory.size(); i++) {
            SetCursorPosition(startX, startY + 4 + i);
            if (i == selectedInventoryItem) {
                cout << "> ";
            }
            else {
                cout << "  ";
            }
            player->inventory[i].display();
        }

        if (player->inventory.empty()) {
            SetCursorPosition(startX, startY + 4);
            cout << "  (背包为空)";
        }

        SetCursorPosition(startX, startY + 6 + player->inventory.size());
        cout << "------------------------";
        SetCursorPosition(startX, startY + 7 + player->inventory.size());
        cout << "回车: 装备物品";
        SetCursorPosition(startX, startY + 8 + player->inventory.size());
        cout << "X: 丢弃物品";
        SetCursorPosition(startX, startY + 9 + player->inventory.size());
        cout << "ESC: 返回背包";
    }

    // 绘制物品列表
    void drawItemList() {
        system("cls");

        int startX = 40;
        int startY = 10;

        SetCursorPosition(startX, startY);
        cout << "===== 物 品 列 表 =====";

        int yOffset = startY + 2;
        for (const auto& item : player->items) {
            if (item.second > 0) {  // 只显示数量大于0的物品
                SetCursorPosition(startX, yOffset++);
                cout << item.first << ": " << item.second;
            }
        }

        SetCursorPosition(startX, yOffset + 2);
        cout << "按ESC返回背包";
    }

    // 绘制锻造界面
    void drawForgeMenu() {
        system("cls");

        int startX = 40;
        int startY = 10;

        SetCursorPosition(startX, startY);
        cout << "===== 锻 造 工 坊 =====";

        SetCursorPosition(startX, startY + 2);
        cout << "传说币: " << player->legendCoins << "  传说结晶: " << player->legendCrystals;

        SetCursorPosition(startX, startY + 4);
        if (selectedForgeItem == 0) {
            cout << "> ";
        }
        else {
            cout << "  ";
        }
        cout << "装备升星";

        SetCursorPosition(startX, startY + 5);
        if (selectedForgeItem == 1) {
            cout << "> ";
        }
        else {
            cout << "  ";
        }
        cout << "装备进阶";

        SetCursorPosition(startX, startY + 6);
        if (selectedForgeItem == 2) {
            cout << "> ";
        }
        else {
            cout << "  ";
        }
        cout << "装备分解";

        SetCursorPosition(startX, startY + 7);
        if (selectedForgeItem == 3) {
            cout << "> ";
        }
        else {
            cout << "  ";
        }
        cout << "离开锻造";

        SetCursorPosition(startX, startY + 9);
        cout << "使用W/S选择,回车确认";
        SetCursorPosition(startX, startY + 10);
        cout << "ESC返回游戏";
    }

    // 绘制升星界面
    void drawStarUpgrade() {
        system("cls");

        int startX = 30;
        int startY = 5;

        SetCursorPosition(startX, startY);
        cout << "===== 装 备 升 星 =====";

        SetCursorPosition(startX, startY + 2);
        cout << "传说结晶: " << player->legendCrystals;
        SetCursorPosition(startX, startY + 3);
        cout << "所有装备 (包括已装备的):";

        // 获取所有装备(包括已装备的)
        auto allEquip = player->getAllEquipment();

        // 显示可升星的装备
        vector<int> upgradableItems;
        for (int i = 0; i < allEquip.size(); i++) {
            if (allEquip[i]->canUpgradeStarCondition()) {
                upgradableItems.push_back(i);
            }
        }

        for (int i = 0; i < upgradableItems.size(); i++) {
            int idx = upgradableItems[i];
            SetCursorPosition(startX, startY + 5 + i);
            if (i == selectedEquipmentItem) {
                cout << "> ";
            }
            else {
                cout << "  ";
            }
            allEquip[idx]->display();

            // 显示升星消耗
            int cost = allEquip[idx]->getStarUpgradeCost();
            if (cost > 0) {
                cout << " (消耗: " << cost << "传说结晶)";
            }
        }

        if (upgradableItems.empty()) {
            SetCursorPosition(startX, startY + 5);
            cout << "  (无可升星装备)";
        }

        SetCursorPosition(startX, startY + 7 + upgradableItems.size());
        cout << "------------------------";
        SetCursorPosition(startX, startY + 8 + upgradableItems.size());
        cout << "回车: 升星选中装备";
        SetCursorPosition(startX, startY + 9 + upgradableItems.size());
        cout << "ESC: 返回锻造";
    }

    // 绘制进阶界面
    void drawTierUpgrade() {
        system("cls");

        int startX = 30;
        int startY = 5;

        SetCursorPosition(startX, startY);
        cout << "===== 装 备 进 阶 =====";

        SetCursorPosition(startX, startY + 2);
        cout << "传说币: " << player->legendCoins << "  传说结晶: " << player->legendCrystals;
        SetCursorPosition(startX, startY + 3);
        cout << "所有装备 (包括已装备的):";

        // 获取所有装备(包括已装备的)
        auto allEquip = player->getAllEquipment();

        // 显示可进阶的装备
        vector<int> upgradableItems;
        for (int i = 0; i < allEquip.size(); i++) {
            if (allEquip[i]->canUpgradeTierCondition()) {
                upgradableItems.push_back(i);
            }
        }

        for (int i = 0; i < upgradableItems.size(); i++) {
            int idx = upgradableItems[i];
            SetCursorPosition(startX, startY + 5 + i);
            if (i == selectedEquipmentItem) {
                cout << "> ";
            }
            else {
                cout << "  ";
            }
            allEquip[idx]->display();

            // 显示进阶信息
            if (allEquip[idx]->rarity == Rarity::RED) {
                auto cost = allEquip[idx]->getUpgradeCost();
                cout << " -> ";
                Equipment nextLevel = allEquip[idx]->getUpgradedEquipment();
                nextLevel.display();
                cout << " (消耗: " << cost.first << "传说币, " << cost.second << "传说结晶)";
            }
            else if (allEquip[idx]->rarity == Rarity::PINK &&
                allEquip[idx]->upgradeLevel == 5 &&
                allEquip[idx]->starLevel >= 10) {
                cout << " -> ";
                Equipment nextLevel = allEquip[idx]->getUpgradedEquipment();
                nextLevel.display();
                cout << " (消耗: 1000传说结晶)";
            }
        }

        if (upgradableItems.empty()) {
            SetCursorPosition(startX, startY + 5);
            cout << "  (无可进阶装备)";
        }

        SetCursorPosition(startX, startY + 7 + upgradableItems.size());
        cout << "------------------------";
        SetCursorPosition(startX, startY + 8 + upgradableItems.size());
        cout << "回车: 进阶选中装备";
        SetCursorPosition(startX, startY + 9 + upgradableItems.size());
        cout << "ESC: 返回锻造";
    }

    // 绘制分解界面
    void drawDecomposeItems() {
        system("cls");

        int startX = 30;
        int startY = 5;

        SetCursorPosition(startX, startY);
        cout << "===== 装 备 分 解 =====";

        SetCursorPosition(startX, startY + 2);
        cout << "传说币: " << player->legendCoins << "  传说结晶: " << player->legendCrystals;

        SetCursorPosition(startX, startY + 4);
        cout << "背包装备:";

        for (int i = 0; i < player->inventory.size(); i++) {
            SetCursorPosition(startX, startY + 6 + i);
            if (i == selectedInventoryItem) {
                cout << "> ";
            }
            else {
                cout << "  ";
            }
            player->inventory[i].display();

            // 显示分解收益
            auto reward = player->inventory[i].getDecomposeReward();
            if (reward.first > 0 || reward.second > 0) {
                cout << " (分解可得: ";
                if (reward.first > 0) {
                    cout << reward.first << "传说币";
                }
                if (reward.second > 0) {
                    if (reward.first > 0) cout << ", ";
                    cout << reward.second << "传说结晶";
                }
                cout << ")";
            }
        }

        if (player->inventory.empty()) {
            SetCursorPosition(startX, startY + 6);
            cout << "  (背包为空)";
        }

        SetCursorPosition(startX, startY + 8 + player->inventory.size());
        cout << "------------------------";
        SetCursorPosition(startX, startY + 9 + player->inventory.size());
        cout << "回车: 分解选中装备";
        SetCursorPosition(startX, startY + 10 + player->inventory.size());
        cout << "ESC: 返回锻造";
    }

    // 绘制商店主菜单
    void drawShopMenu() {
        system("cls");

        int startX = 40;
        int startY = 10;

        SetCursorPosition(startX, startY);
        cout << "===== 商 店 =====";

        SetCursorPosition(startX, startY + 2);
        cout << "传说币: " << player->legendCoins;

        SetCursorPosition(startX, startY + 4);
        if (selectedShopItem == 0) {
            cout << "> ";
        }
        else {
            cout << "  ";
        }
        cout << "购买装备";

        SetCursorPosition(startX, startY + 5);
        if (selectedShopItem == 1) {
            cout << "> ";
        }
        else {
            cout << "  ";
        }
        cout << "出售装备";

        SetCursorPosition(startX, startY + 6);
        if (selectedShopItem == 2) {
            cout << "> ";
        }
        else {
            cout << "  ";
        }
        cout << "离开商店";

        SetCursorPosition(startX, startY + 8);
        cout << "使用W/S选择,回车确认";
        SetCursorPosition(startX, startY + 9);
        cout << "ESC返回游戏";
    }

    // 绘制购买界面
    void drawBuyItems() {
        system("cls");

        int startX = 30;
        int startY = 5;

        SetCursorPosition(startX, startY);
        cout << "===== 购 买 装 备 =====";

        SetCursorPosition(startX, startY + 2);
        cout << "传说币: " << player->legendCoins;

        SetCursorPosition(startX, startY + 4);
        cout << "商店物品:";

        for (int i = 0; i < shopItems.size(); i++) {
            SetCursorPosition(startX, startY + 6 + i);
            if (i == selectedBuyItem) {
                cout << "> ";
            }
            else {
                cout << "  ";
            }
            shopItems[i].display();
            cout << " - 价格: " << shopItems[i].getBuyPrice() << "传说币";
        }

        SetCursorPosition(startX, startY + 8 + shopItems.size());
        cout << "------------------------";
        SetCursorPosition(startX, startY + 9 + shopItems.size());
        cout << "回车: 购买选中装备";
        SetCursorPosition(startX, startY + 10 + shopItems.size());
        cout << "ESC: 返回商店";
    }

    // 绘制出售界面
    void drawSellItems() {
        system("cls");

        int startX = 30;
        int startY = 5;

        SetCursorPosition(startX, startY);
        cout << "===== 出 售 装 备 =====";

        SetCursorPosition(startX, startY + 2);
        cout << "传说币: " << player->legendCoins;

        SetCursorPosition(startX, startY + 4);
        cout << "背包装备:";

        for (int i = 0; i < player->inventory.size(); i++) {
            SetCursorPosition(startX, startY + 6 + i);
            if (i == selectedInventoryItem) {
                cout << "> ";
            }
            else {
                cout << "  ";
            }
            player->inventory[i].display();
            cout << " - 售价: " << player->inventory[i].getSellPrice() << "传说币";
        }

        if (player->inventory.empty()) {
            SetCursorPosition(startX, startY + 6);
            cout << "  (背包为空)";
        }

        SetCursorPosition(startX, startY + 8 + player->inventory.size());
        cout << "------------------------";
        SetCursorPosition(startX, startY + 9 + player->inventory.size());
        cout << "回车: 出售选中装备";
        SetCursorPosition(startX, startY + 10 + player->inventory.size());
        cout << "ESC: 返回商店";
    }

    void drawCharacterSelection() {
        system("cls");
        cout << "选择角色:" << endl << endl;

        for (int i = 0; i < characterNames.size(); i++) {
            if (i == selectedCharacter) {
                cout << "<" << characterNames[i] << ">" << endl;
            }
            else {
                cout << " " << characterNames[i] << " " << endl;
            }
        }

        cout << endl << "使用W/S选择,回车确认" << endl;
        cout << "按N创建新角色";
    }

    void drawStartScreen() {
        system("cls");

        SetCursorPosition(50, 10);
        cout << "    /|";
        SetCursorPosition(50, 11);
        cout << "   / |";
        SetCursorPosition(50, 12);
        cout << "  /  |";
        SetCursorPosition(50, 13);
        cout << " /   |";
        SetCursorPosition(50, 14);
        cout << "/____|";
        SetCursorPosition(50, 15);
        cout << "  ||";
        SetCursorPosition(50, 16);
        cout << "  ||";
        SetCursorPosition(50, 17);
        cout << "  ||";
        SetCursorPosition(50, 18);
        cout << "  ||";

        SetCursorPosition(45, 20);
        cout << "传说:神明之剑0.4.5";

        SetCursorPosition(45, 22);
        cout << "按回车开始游戏";
    }

    void drawLoadingScreen() {
        system("cls");

        for (int i = 1; i <= 100; i++) {
            SetCursorPosition(50, 15);
            cout << i << "/100";
            Sleep(50);
        }
    }

    void createNewCharacter() {
        system("cls");
        cout << "输入角色名称: ";
        string name;
        getline(cin, name);

        if (!name.empty()) {
            characterNames.push_back(name);
            saveCharacters();
        }
    }

    void saveCharacters() {
        ofstream outFile("characters.txt");
        if (outFile) {
            for (const auto& name : characterNames) {
                outFile << name << endl;
            }
        }
    }

    void loadCharacters() {
        ifstream inFile("characters.txt");
        characterNames.clear();
        string name;
        while (getline(inFile, name)) {
            if (!name.empty()) {
                characterNames.push_back(name);
            }
        }
    }

    void saveGame() {
        ofstream outFile("save_" + player->name + ".txt");
        if (outFile) {
            outFile << player->name << endl;
            outFile << player->level << endl;
            outFile << player->maxHp << endl;
            outFile << player->currentHp << endl;
            outFile << player->maxAttack << endl;
            outFile << player->minAttack << endl;
            outFile << player->totalPower << endl;
            outFile << player->legendCoins << endl;
            outFile << player->legendCrystals << endl;
            outFile << player->monstersDefeated << endl;
            outFile << player->currentMap << endl;

            if (player->helmet) outFile << "HELMET " << player->helmet->name << " " << player->helmet->starLevel << " " << player->helmet->upgradeLevel << endl;
            if (player->armor) outFile << "ARMOR " << player->armor->name << " " << player->armor->starLevel << " " << player->armor->upgradeLevel << endl;
            if (player->boots) outFile << "BOOTS " << player->boots->name << " " << player->boots->starLevel << " " << player->boots->upgradeLevel << endl;
            if (player->weapon) outFile << "WEAPON " << player->weapon->name << " " << player->weapon->starLevel << " " << player->weapon->upgradeLevel << endl;
            if (player->shield) outFile << "SHIELD " << player->shield->name << " " << player->shield->starLevel << " " << player->shield->upgradeLevel << endl;

            outFile << "INVENTORY " << player->inventory.size() << endl;
            for (const auto& item : player->inventory) {
                outFile << item.name << " " << item.starLevel << " " << item.upgradeLevel << endl;
            }
        }
    }

    bool loadGame(const string& name) {
        ifstream inFile("save_" + name + ".txt");
        if (!inFile) return false;

        player = new Player(name);

        string line;
        getline(inFile, line);

        inFile >> player->level;
        inFile >> player->maxHp;
        inFile >> player->currentHp;
        inFile >> player->maxAttack;
        inFile >> player->minAttack;
        inFile >> player->totalPower;
        inFile >> player->legendCoins;
        inFile >> player->legendCrystals;
        inFile >> player->monstersDefeated;
        inFile.ignore();
        getline(inFile, player->currentMap);

        // 更新杂物列表
        for (auto& item : player->items) {
            if (item.first == "传说币") {
                item.second = player->legendCoins;
            }
            else if (item.first == "传说结晶") {
                item.second = player->legendCrystals;
            }
        }

        int baseMaxHp = 4000 + (player->level - 1) * 25;
        int baseMinAttack = 150 + (player->level - 1) * 10;
        int baseMaxAttack = 500 + (player->level - 1) * 15;

        if (player->helmet) delete player->helmet;
        if (player->armor) delete player->armor;
        if (player->boots) delete player->boots;
        if (player->weapon) delete player->weapon;
        if (player->shield) delete player->shield;

        player->helmet = nullptr;
        player->armor = nullptr;
        player->boots = nullptr;
        player->weapon = nullptr;
        player->shield = nullptr;

        player->inventory.clear();

        int totalHpBonus = 0;
        int totalMinAttackBonus = 0;
        int totalMaxAttackBonus = 0;

        while (getline(inFile, line)) {
            if (line.find("INVENTORY") != string::npos) break;

            istringstream iss(line);
            string type, itemName;
            int starLevel, upgradeLevel;
            iss >> type >> itemName >> starLevel >> upgradeLevel;

            Equipment* eq = nullptr;
            if (type == "HELMET") {
                if (itemName == "草帽") eq = new Equipment("草帽", EquipmentType::HELMET, Rarity::WHITE, 50, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "铜质头盔") eq = new Equipment("铜质头盔", EquipmentType::HELMET, Rarity::GREEN, 75, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "乌金护额") eq = new Equipment("乌金护额", EquipmentType::HELMET, Rarity::BLUE, 100, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "精钢头盔") eq = new Equipment("精钢头盔", EquipmentType::HELMET, Rarity::PURPLE, 125, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "魔神战盔") eq = new Equipment("魔神战盔", EquipmentType::HELMET, Rarity::GOLD, 180, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "龙魂头盔") eq = new Equipment("龙魂头盔", EquipmentType::HELMET, Rarity::RED, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "守望之窥") eq = new Equipment("守望之窥", EquipmentType::HELMET, Rarity::RED, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "天灾魔神盔") eq = new Equipment("天灾魔神盔", EquipmentType::HELMET, Rarity::RED, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "维圣之盔") eq = new Equipment("维圣之盔", EquipmentType::HELMET, Rarity::RED, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "源天煞蔑视") eq = new Equipment("源天煞蔑视", EquipmentType::HELMET, Rarity::RED, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "化神明之圣盔") eq = new Equipment("化神明之圣盔", EquipmentType::HELMET, Rarity::PINK, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "传奇的神之盔") eq = new Equipment("传奇的神之盔", EquipmentType::HELMET, Rarity::ORANGE, 225, 0, 0, starLevel, upgradeLevel);
                if (eq) {
                    player->helmet = eq;
                    totalHpBonus += eq->hpBonus;
                }
            }
            else if (type == "ARMOR") {
                if (itemName == "布衣") eq = new Equipment("布衣", EquipmentType::ARMOR, Rarity::WHITE, 100, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "铜质盔甲") eq = new Equipment("铜质盔甲", EquipmentType::ARMOR, Rarity::GREEN, 125, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "乌金护甲") eq = new Equipment("乌金护甲", EquipmentType::ARMOR, Rarity::BLUE, 140, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "精钢护甲") eq = new Equipment("精钢护甲", EquipmentType::ARMOR, Rarity::PURPLE, 165, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "魔神铠甲") eq = new Equipment("魔神铠甲", EquipmentType::ARMOR, Rarity::GOLD, 250, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "龙魂战铠") eq = new Equipment("龙魂战铠", EquipmentType::ARMOR, Rarity::RED, 275, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "守望护身甲") eq = new Equipment("守望护身甲", EquipmentType::ARMOR, Rarity::RED, 275, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "天灾魔神甲") eq = new Equipment("天灾魔神甲", EquipmentType::ARMOR, Rarity::RED, 275, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "维圣神甲") eq = new Equipment("维圣神甲", EquipmentType::ARMOR, Rarity::RED, 275, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "源虚空之体") eq = new Equipment("源虚空之体", EquipmentType::ARMOR, Rarity::RED, 275, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "化神明之圣甲") eq = new Equipment("化神明之圣甲", EquipmentType::ARMOR, Rarity::PINK, 275, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "传奇的神之铠") eq = new Equipment("传奇的神之铠", EquipmentType::ARMOR, Rarity::ORANGE, 275, 0, 0, starLevel, upgradeLevel);
                if (eq) {
                    player->armor = eq;
                    totalHpBonus += eq->hpBonus;
                }
            }
            else if (type == "BOOTS") {
                if (itemName == "草鞋") eq = new Equipment("草鞋", EquipmentType::BOOTS, Rarity::WHITE, 15, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "铜质护靴") eq = new Equipment("铜质护靴", EquipmentType::BOOTS, Rarity::GREEN, 45, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "乌金战靴") eq = new Equipment("乌金战靴", EquipmentType::BOOTS, Rarity::BLUE, 70, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "精钢战靴") eq = new Equipment("精钢战靴", EquipmentType::BOOTS, Rarity::PURPLE, 100, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "魔神战靴") eq = new Equipment("魔神战靴", EquipmentType::BOOTS, Rarity::GOLD, 180, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "龙魂战靴") eq = new Equipment("龙魂战靴", EquipmentType::BOOTS, Rarity::RED, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "守望之靴") eq = new Equipment("守望之靴", EquipmentType::BOOTS, Rarity::RED, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "天灾魔神靴") eq = new Equipment("天灾魔神靴", EquipmentType::BOOTS, Rarity::RED, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "维圣神靴") eq = new Equipment("维圣神靴", EquipmentType::BOOTS, Rarity::RED, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "源凋零之遂") eq = new Equipment("源凋零之遂", EquipmentType::BOOTS, Rarity::RED, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "化神明之圣靴") eq = new Equipment("化神明之圣靴", EquipmentType::BOOTS, Rarity::PINK, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "传奇的神之靴") eq = new Equipment("传奇的神之靴", EquipmentType::BOOTS, Rarity::ORANGE, 225, 0, 0, starLevel, upgradeLevel);
                if (eq) {
                    player->boots = eq;
                    totalHpBonus += eq->hpBonus;
                }
            }
            else if (type == "WEAPON") {
                if (itemName == "匕首") eq = new Equipment("匕首", EquipmentType::WEAPON, Rarity::WHITE, 0, 5, 25, starLevel, upgradeLevel);
                else if (itemName == "铜剑") eq = new Equipment("铜剑", EquipmentType::WEAPON, Rarity::GREEN, 0, 10, 40, starLevel, upgradeLevel);
                else if (itemName == "乌金剑") eq = new Equipment("乌金剑", EquipmentType::WEAPON, Rarity::BLUE, 0, 20, 65, starLevel, upgradeLevel);
                else if (itemName == "精钢之剑") eq = new Equipment("精钢之剑", EquipmentType::WEAPON, Rarity::PURPLE, 0, 50, 100, starLevel, upgradeLevel);
                else if (itemName == "赤血魔神剑") eq = new Equipment("赤血魔神剑", EquipmentType::WEAPON, Rarity::GOLD, 0, 85, 150, starLevel, upgradeLevel);
                else if (itemName == "龙魂双刃剑") eq = new Equipment("龙魂双刃剑", EquipmentType::WEAPON, Rarity::RED, 0, 100, 200, starLevel, upgradeLevel);
                else if (itemName == "叱咤天煞剑") eq = new Equipment("叱咤天煞剑", EquipmentType::WEAPON, Rarity::RED, 0, 100, 200, starLevel, upgradeLevel);
                else if (itemName == "魔神斩杀刃") eq = new Equipment("魔神斩杀刃", EquipmentType::WEAPON, Rarity::RED, 0, 100, 200, starLevel, upgradeLevel);
                else if (itemName == "维护天意之剑") eq = new Equipment("维护天意之剑", EquipmentType::WEAPON, Rarity::RED, 0, 100, 200, starLevel, upgradeLevel);
                else if (itemName == "源魔魂之斩杀") eq = new Equipment("源魔魂之斩杀", EquipmentType::WEAPON, Rarity::RED, 0, 100, 200, starLevel, upgradeLevel);
                else if (itemName == "万神皆可灭之神剑") eq = new Equipment("万神皆可灭之神剑", EquipmentType::WEAPON, Rarity::PINK, 0, 100, 200, starLevel, upgradeLevel);
                else if (itemName == "传奇的神明之剑") eq = new Equipment("传奇的神明之剑", EquipmentType::WEAPON, Rarity::ORANGE, 0, 100, 200, starLevel, upgradeLevel);
                if (eq) {
                    player->weapon = eq;
                    totalMinAttackBonus += eq->minAttackBonus;
                    totalMaxAttackBonus += eq->maxAttackBonus;
                }
            }
            else if (type == "SHIELD") {
                if (itemName == "木盾") eq = new Equipment("木盾", EquipmentType::SHIELD, Rarity::WHITE, 15, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "铜质盾牌") eq = new Equipment("铜质盾牌", EquipmentType::SHIELD, Rarity::GREEN, 35, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "乌金盾") eq = new Equipment("乌金盾", EquipmentType::SHIELD, Rarity::BLUE, 60, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "护身之盾") eq = new Equipment("护身之盾", EquipmentType::SHIELD, Rarity::PURPLE, 100, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "护身的魔神盾") eq = new Equipment("护身的魔神盾", EquipmentType::SHIELD, Rarity::GOLD, 150, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "神圣的龙魂盾") eq = new Equipment("神圣的龙魂盾", EquipmentType::SHIELD, Rarity::RED, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "螟蛉护身盾") eq = new Equipment("螟蛉护身盾", EquipmentType::SHIELD, Rarity::RED, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "恶鬼皆灭盾") eq = new Equipment("恶鬼皆灭盾", EquipmentType::SHIELD, Rarity::RED, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "维护自身之盾") eq = new Equipment("维护自身之盾", EquipmentType::SHIELD, Rarity::RED, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "源天地之庇护") eq = new Equipment("源天地之庇护", EquipmentType::SHIELD, Rarity::RED, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "万物皆可防之盾") eq = new Equipment("万物皆可防之盾", EquipmentType::SHIELD, Rarity::PINK, 225, 0, 0, starLevel, upgradeLevel);
                else if (itemName == "传奇的神明之盾") eq = new Equipment("传奇的神明之盾", EquipmentType::SHIELD, Rarity::ORANGE, 225, 0, 0, starLevel, upgradeLevel);
                if (eq) {
                    player->shield = eq;
                    totalHpBonus += eq->hpBonus;
                }
            }
        }

        player->maxHp = baseMaxHp + totalHpBonus;
        player->minAttack = baseMinAttack + totalMinAttackBonus;
        player->maxAttack = baseMaxAttack + totalMaxAttackBonus;

        if (player->currentHp > player->maxHp) {
            player->currentHp = player->maxHp;
        }

        if (line.find("INVENTORY") != string::npos) {
            int count;
            istringstream iss(line);
            string dummy;
            iss >> dummy >> count;
            for (int i = 0; i < count; i++) {
                getline(inFile, line);
                istringstream itemIss(line);
                string itemName;
                int star, upgrade;
                itemIss >> itemName >> star >> upgrade;

                // 这里需要根据itemName创建对应的装备
                if (itemName == "草帽") player->inventory.push_back(Equipment("草帽", EquipmentType::HELMET, Rarity::WHITE, 50, 0, 0, star, upgrade));
                else if (itemName == "布衣") player->inventory.push_back(Equipment("布衣", EquipmentType::ARMOR, Rarity::WHITE, 100, 0, 0, star, upgrade));
                else if (itemName == "草鞋") player->inventory.push_back(Equipment("草鞋", EquipmentType::BOOTS, Rarity::WHITE, 15, 0, 0, star, upgrade));
                else if (itemName == "匕首") player->inventory.push_back(Equipment("匕首", EquipmentType::WEAPON, Rarity::WHITE, 0, 5, 25, star, upgrade));
                else if (itemName == "木盾") player->inventory.push_back(Equipment("木盾", EquipmentType::SHIELD, Rarity::WHITE, 15, 0, 0, star, upgrade));
                else if (itemName == "铜质头盔") player->inventory.push_back(Equipment("铜质头盔", EquipmentType::HELMET, Rarity::GREEN, 75, 0, 0, star, upgrade));
                else if (itemName == "铜质盔甲") player->inventory.push_back(Equipment("铜质盔甲", EquipmentType::ARMOR, Rarity::GREEN, 125, 0, 0, star, upgrade));
                else if (itemName == "铜质护靴") player->inventory.push_back(Equipment("铜质护靴", EquipmentType::BOOTS, Rarity::GREEN, 45, 0, 0, star, upgrade));
                else if (itemName == "铜剑") player->inventory.push_back(Equipment("铜剑", EquipmentType::WEAPON, Rarity::GREEN, 0, 10, 40, star, upgrade));
                else if (itemName == "铜质盾牌") player->inventory.push_back(Equipment("铜质盾牌", EquipmentType::SHIELD, Rarity::GREEN, 35, 0, 0, star, upgrade));
                // ... 其他装备类似处理,这里省略了部分代码以保持简洁
            }
        }

        player->updatePower();

        return true;
    }

    Monster* getAttackedMonster() {
        for (auto& monster : monsters) {
            if (monster.alive && abs(monster.x - player->x) <= 2 && abs(monster.y - player->y) <= 2) {
                return &monster;
            }
        }
        return nullptr;
    }

    void handleAttack() {
        Monster* monster = getAttackedMonster();
        if (monster) {
            player->lastAttackedMonster = monster;

            int damage = player->attack();
            monster->takeDamage(damage);

            int healAmount = rand() % 401 + 100;
            player->heal(healAmount);

            SetCursorPosition(0, 51);
            cout << "你对" << monster->name << "造成了" << damage << "点伤害!";
            SetCursorPosition(0, 52);
            cout << "你恢复了" << healAmount << "点生命值!";

            if (!monster->alive) {
                SetCursorPosition(0, 53);
                if (monster->isBoss) {
                    cout << "你击败了强大的魔龙领主!";

                    // 获得传说币和传说结晶
                    player->addLegendCoins(50);
                    player->addLegendCrystals(5);

                    // 击败魔龙领主增加怪物击败计数
                    player->addMonsterDefeated();

                    // 必得金色装备,20%概率额外获得红色装备(基础装备,不是进阶装备)
                    Equipment* goldEq = generateRandomEquipment(Rarity::GOLD);
                    player->inventory.push_back(*goldEq);
                    delete goldEq;

                    SetCursorPosition(0, 54);
                    cout << "获得了50传说币、5传说结晶和";
                    player->inventory.back().display();
                    cout << "!";

                    // 20%概率获得红色装备(基础红色装备,不能是进阶装备)
                    if (rand() % 100 < 20) {
                        // 只生成基础红色装备,不能是进阶装备
                        Equipment* redEq = generateRandomEquipment(Rarity::RED);
                        player->inventory.push_back(*redEq);
                        delete redEq;

                        SetCursorPosition(0, 55);
                        cout << "幸运!额外获得了";
                        player->inventory.back().display();
                        cout << "!";
                    }
                }
                else {
                    cout << "你击败了" << monster->name << "!";

                    // 获得传说币
                    player->addLegendCoins(10);

                    // 击败虚空使者增加怪物击败计数
                    player->addMonsterDefeated();

                    monstersDefeatedCount++;
                    SetCursorPosition(0, 54);
                    cout << "获得了10传说币!";
                    SetCursorPosition(0, 55);
                    cout << "已击败怪物: " << monstersDefeatedCount << "/10";

                    if (monstersDefeatedCount >= 10) {
                        generateBoss();
                        monstersDefeatedCount = 0;
                    }

                    // 虚空使者必定掉落装备
                    vector<Rarity> possibleDrops;
                    if (rand() % 100 < 50) possibleDrops.push_back(Rarity::WHITE);
                    if (rand() % 100 < 45) possibleDrops.push_back(Rarity::GREEN);
                    if (rand() % 100 < 25) possibleDrops.push_back(Rarity::BLUE);
                    if (rand() % 100 < 20) possibleDrops.push_back(Rarity::PURPLE);

                    if (possibleDrops.empty()) {
                        possibleDrops.push_back(Rarity::WHITE);
                    }

                    Rarity selectedRarity = possibleDrops[rand() % possibleDrops.size()];
                    Equipment* eq = generateRandomEquipment(selectedRarity);
                    player->inventory.push_back(*eq);
                    delete eq;

                    SetCursorPosition(0, 56);
                    cout << "获得了";
                    player->inventory.back().display();
                    cout << "!";
                }
            }
            else {
                int monsterDamage = monster->attack();
                player->takeDamage(monsterDamage);
                SetCursorPosition(0, 55);
                cout << monster->name << "对你造成了" << monsterDamage << "点伤害!";

                if (player->currentHp <= 0) {
                    SetCursorPosition(0, 56);
                    cout << "你已死亡!将在皇城复活...";
                    Sleep(2000);
                    player->respawn();
                    generateMonsters();
                    player->lastAttackedMonster = nullptr;
                }
            }
        }
    }

    void checkMapTransition() {
        if (player->currentMap == "皇城" && player->x >= 98) {
            player->currentMap = "虚空领域";
            player->x = 1;
            generateMonsters();
            player->lastAttackedMonster = nullptr;
            SetCursorPosition(0, 56);
            cout << "你已进入虚空领域!";
            Sleep(2000);
        }
        else if (player->currentMap == "虚空领域" && player->x <= 1) {
            player->currentMap = "皇城";
            player->x = 98;
            monsters.clear();
            player->lastAttackedMonster = nullptr;
            SetCursorPosition(0, 56);
            cout << "你已返回皇城!";
            Sleep(2000);
        }
    }

    void checkLevelUp() {
        // 等级系统现在通过addMonsterDefeated()方法处理
    }

public:
    Game() : player(nullptr), gameRunning(false), inInventory(false),
        inCharacterSelection(false), inShop(false), inForge(false),
        sellingItems(false), buyingItems(false), forgingItems(false),
        upgradingStar(false), upgradingTier(false), decomposingItems(false),
        viewingItems(false), viewingEquipment(false),
        selectedInventoryItem(0), selectedShopItem(0), selectedBuyItem(0),
        selectedForgeItem(0), selectedEquipmentItem(0), selectedCharacter(0),
        bossSpawned(false), screenWidth(120), screenHeight(50),
        normalMonstersDefeated(0), bossesDefeated(0), monstersDefeatedCount(0) {
        srand(static_cast<unsigned int>(time(nullptr)));
        initializeShop();
    }

    ~Game() {
        if (player) delete player;
    }

    void run() {
        gameRunning = true;
        SetFullScreen();

        drawStartScreen();
        while (gameRunning && _getch() != 13);

        drawLoadingScreen();

        loadCharacters();
        inCharacterSelection = true;
        while (gameRunning && inCharacterSelection) {
            drawCharacterSelection();

            int key = _getch();
            switch (key) {
            case 'w':
            case 'W':
                selectedCharacter = (selectedCharacter - 1 + characterNames.size()) % characterNames.size();
                break;
            case 's':
            case 'S':
                selectedCharacter = (selectedCharacter + 1) % characterNames.size();
                break;
            case 'n':
            case 'N':
                createNewCharacter();
                break;
            case 13:
                if (!characterNames.empty()) {
                    if (loadGame(characterNames[selectedCharacter])) {
                        inCharacterSelection = false;
                    }
                    else {
                        player = new Player(characterNames[selectedCharacter]);
                        inCharacterSelection = false;
                    }
                }
                break;
            case 27:
                gameRunning = false;
                break;
            }
        }

        generateMonsters();
        while (gameRunning) {
            if (inShop) {
                if (buyingItems) {
                    drawBuyItems();
                    int key = _getch();
                    switch (key) {
                    case 'w':
                    case 'W':
                        selectedBuyItem = max(0, selectedBuyItem - 1);
                        break;
                    case 's':
                    case 'S':
                        selectedBuyItem = min(selectedBuyItem + 1, max(0, (int)shopItems.size() - 1));
                        break;
                    case 13:
                        if (selectedBuyItem >= 0 && selectedBuyItem < shopItems.size()) {
                            Equipment item = shopItems[selectedBuyItem];
                            int price = item.getBuyPrice();
                            if (price > 0 && player->spendLegendCoins(price)) {
                                player->inventory.push_back(item);
                                system("cls");
                                SetCursorPosition(40, 10);
                                cout << "购买成功!";
                                Sleep(1000);
                            }
                            else if (price == -1) {
                                system("cls");
                                SetCursorPosition(40, 10);
                                cout << "此装备无法购买!";
                                Sleep(1000);
                            }
                            else {
                                system("cls");
                                SetCursorPosition(40, 10);
                                cout << "传说币不足!";
                                Sleep(1000);
                            }
                        }
                        break;
                    case 27:
                        buyingItems = false;
                        selectedBuyItem = 0;
                        break;
                    }
                }
                else if (sellingItems) {
                    drawSellItems();
                    int key = _getch();
                    switch (key) {
                    case 'w':
                    case 'W':
                        selectedInventoryItem = max(0, selectedInventoryItem - 1);
                        break;
                    case 's':
                    case 'S':
                        selectedInventoryItem = min(selectedInventoryItem + 1, max(0, (int)player->inventory.size() - 1));
                        break;
                    case 13:
                        if (!player->inventory.empty() && selectedInventoryItem < player->inventory.size()) {
                            int sellPrice = player->inventory[selectedInventoryItem].getSellPrice();
                            player->addLegendCoins(sellPrice);
                            player->inventory.erase(player->inventory.begin() + selectedInventoryItem);
                            selectedInventoryItem = min(selectedInventoryItem, max(0, (int)player->inventory.size() - 1));

                            system("cls");
                            SetCursorPosition(40, 10);
                            cout << "出售成功!获得" << sellPrice << "传说币";
                            Sleep(1000);
                        }
                        break;
                    case 27:
                        sellingItems = false;
                        selectedInventoryItem = 0;
                        break;
                    }
                }
                else {
                    drawShopMenu();
                    int key = _getch();
                    switch (key) {
                    case 'w':
                    case 'W':
                        selectedShopItem = (selectedShopItem - 1 + 3) % 3;
                        break;
                    case 's':
                    case 'S':
                        selectedShopItem = (selectedShopItem + 1) % 3;
                        break;
                    case 13:
                        if (selectedShopItem == 0) {
                            buyingItems = true;
                            selectedBuyItem = 0;
                        }
                        else if (selectedShopItem == 1) {
                            sellingItems = true;
                            selectedInventoryItem = 0;
                        }
                        else if (selectedShopItem == 2) {
                            inShop = false;
                        }
                        break;
                    case 27:
                        inShop = false;
                        break;
                    }
                }
            }
            else if (inForge) {
                if (upgradingStar) {
                    drawStarUpgrade();
                    int key = _getch();
                    switch (key) {
                    case 'w':
                    case 'W':
                        selectedEquipmentItem = max(0, selectedEquipmentItem - 1);
                        break;
                    case 's':
                    case 'S':
                        selectedEquipmentItem = min(selectedEquipmentItem + 1, max(0, (int)player->getAllEquipment().size() - 1));
                        break;
                    case 13:
                        if (player->upgradeStar(selectedEquipmentItem)) {
                            system("cls");
                            SetCursorPosition(40, 10);
                            cout << "升星成功!";
                            Sleep(1000);
                        }
                        else {
                            system("cls");
                            SetCursorPosition(40, 10);
                            cout << "升星失败!传说结晶不足或已达到最大星级";
                            Sleep(1000);
                        }
                        break;
                    case 27:
                        upgradingStar = false;
                        selectedEquipmentItem = 0;
                        break;
                    }
                }
                else if (upgradingTier) {
                    drawTierUpgrade();
                    int key = _getch();
                    switch (key) {
                    case 'w':
                    case 'W':
                        selectedEquipmentItem = max(0, selectedEquipmentItem - 1);
                        break;
                    case 's':
                    case 'S':
                        selectedEquipmentItem = min(selectedEquipmentItem + 1, max(0, (int)player->getAllEquipment().size() - 1));
                        break;
                    case 13:
                        if (player->upgradeTier(selectedEquipmentItem)) {
                            system("cls");
                            SetCursorPosition(40, 10);
                            cout << "进阶成功!";
                            Sleep(1000);
                        }
                        else {
                            system("cls");
                            SetCursorPosition(40, 10);
                            cout << "进阶失败!资源不足或条件不满足";
                            Sleep(1000);
                        }
                        break;
                    case 27:
                        upgradingTier = false;
                        selectedEquipmentItem = 0;
                        break;
                    }
                }
                else if (decomposingItems) {
                    drawDecomposeItems();
                    int key = _getch();
                    switch (key) {
                    case 'w':
                    case 'W':
                        selectedInventoryItem = max(0, selectedInventoryItem - 1);
                        break;
                    case 's':
                    case 'S':
                        selectedInventoryItem = min(selectedInventoryItem + 1, max(0, (int)player->inventory.size() - 1));
                        break;
                    case 13:
                        if (player->decomposeItem(selectedInventoryItem)) {
                            system("cls");
                            SetCursorPosition(40, 10);
                            cout << "分解成功!";
                            Sleep(1000);
                        }
                        break;
                    case 27:
                        decomposingItems = false;
                        selectedInventoryItem = 0;
                        break;
                    }
                }
                else {
                    drawForgeMenu();
                    int key = _getch();
                    switch (key) {
                    case 'w':
                    case 'W':
                        selectedForgeItem = (selectedForgeItem - 1 + 4) % 4;
                        break;
                    case 's':
                    case 'S':
                        selectedForgeItem = (selectedForgeItem + 1) % 4;
                        break;
                    case 13:
                        if (selectedForgeItem == 0) {
                            upgradingStar = true;
                            selectedEquipmentItem = 0;
                        }
                        else if (selectedForgeItem == 1) {
                            upgradingTier = true;
                            selectedEquipmentItem = 0;
                        }
                        else if (selectedForgeItem == 2) {
                            decomposingItems = true;
                            selectedInventoryItem = 0;
                        }
                        else if (selectedForgeItem == 3) {
                            inForge = false;
                        }
                        break;
                    case 27:
                        inForge = false;
                        break;
                    }
                }
            }
            else if (inInventory) {
                if (viewingEquipment) {
                    drawEquipmentList();
                    int key = _getch();
                    switch (key) {
                    case 'w':
                    case 'W':
                        selectedInventoryItem = max(0, selectedInventoryItem - 1);
                        break;
                    case 's':
                    case 'S':
                        selectedInventoryItem = min(selectedInventoryItem + 1, max(0, (int)player->inventory.size() - 1));
                        break;
                    case 13:
                        if (!player->inventory.empty()) {
                            Equipment item = player->inventory[selectedInventoryItem];
                            player->inventory.erase(player->inventory.begin() + selectedInventoryItem);
                            player->equip(new Equipment(item));
                            selectedInventoryItem = min(selectedInventoryItem, max(0, (int)player->inventory.size() - 1));
                        }
                        break;
                    case 'x':
                    case 'X':
                        if (!player->inventory.empty()) {
                            if (player->discardItem(selectedInventoryItem)) {
                                selectedInventoryItem = min(selectedInventoryItem, max(0, (int)player->inventory.size() - 1));
                            }
                        }
                        break;
                    case 27:
                        viewingEquipment = false;
                        selectedInventoryItem = 0;
                        break;
                    }
                }
                else if (viewingItems) {
                    drawItemList();
                    int key = _getch();
                    if (key == 27) {
                        viewingItems = false;
                    }
                }
                else {
                    drawInventoryMenu();
                    int key = _getch();
                    switch (key) {
                    case 'w':
                    case 'W':
                        selectedShopItem = (selectedShopItem - 1 + 3) % 3;
                        break;
                    case 's':
                    case 'S':
                        selectedShopItem = (selectedShopItem + 1) % 3;
                        break;
                    case 13:
                        if (selectedShopItem == 0) {
                            viewingEquipment = true;
                            selectedInventoryItem = 0;
                        }
                        else if (selectedShopItem == 1) {
                            viewingItems = true;
                        }
                        else if (selectedShopItem == 2) {
                            inInventory = false;
                        }
                        break;
                    case 27:
                        inInventory = false;
                        break;
                    }
                }
            }
            else {
                drawGame();
                int key = _getch();
                switch (key) {
                case 'w':
                case 'W':
                    if (player->y > 1) {
                        player->y--;
                        drawGame();
                    }
                    break;
                case 'a':
                case 'A':
                    if (player->x > 1) {
                        player->x--;
                        drawGame();
                        checkMapTransition();
                    }
                    break;
                case 's':
                case 'S':
                    if (player->y < 48) {
                        player->y++;
                        drawGame();
                    }
                    break;
                case 'd':
                case 'D':
                    if (player->x < 98) {
                        player->x++;
                        drawGame();
                        checkMapTransition();
                    }
                    break;
                case 'b':
                case 'B':
                    inInventory = true;
                    selectedShopItem = 0;
                    break;
                case 'l':
                case 'L':
                    inShop = true;
                    selectedShopItem = 0;
                    break;
                case 't':
                case 'T':  // 按T键进入锻造
                    inForge = true;
                    selectedForgeItem = 0;
                    break;
                case 27:
                    gameRunning = false;
                    break;
                case 0xE0:
                    key = _getch();
                    switch (key) {
                    case 72:
                        handleAttack();
                        drawGame();
                        break;
                    case 75:
                        handleAttack();
                        drawGame();
                        break;
                    case 77:
                        handleAttack();
                        drawGame();
                        break;
                    case 80:
                        handleAttack();
                        drawGame();
                        break;
                    }
                    break;
                }
            }

            checkLevelUp();
            saveGame();
        }
    }
};

int main() {
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_CURSOR_INFO cursorInfo;
    GetConsoleCursorInfo(hConsole, &cursorInfo);
    cursorInfo.bVisible = false;
    SetConsoleCursorInfo(hConsole, &cursorInfo);

    Game game;
    game.run();

    return 0;
}
相关推荐
王老师青少年编程2 小时前
信奥赛C++提高组csp-s之KMP算法详解
c++·kmp·字符串匹配·csp·信奥赛·csp-s·提高组
秦jh_2 小时前
【Qt】系统相关(下)
开发语言·qt
东木月2 小时前
使用python获取Windows产品标签
开发语言·windows·python
pumpkin845142 小时前
Go 基础语法全景
开发语言·后端·golang
hqwest2 小时前
码上通QT实战18--监控页面10-获取设备数据
开发语言·qt·湿度·modbus功能码·寄存器地址·从站数据·0103
不会写代码的ys2 小时前
日志库封装(项目通用)
c++
星火开发设计2 小时前
C++ multiset 全面解析与实战指南
开发语言·数据结构·c++·学习·set·知识
一眼万里*e2 小时前
MavLink消息协议
c++
lsx2024063 小时前
Eclipse 添加书签
开发语言