跳到正文

休闲·娱乐

造物主 c++小游戏

YIN_YANG约 132 分钟
原文
文章信息与版本

文章信息

发布
2025年8月18日
收录
2025年12月12日
更新
2026年11月17日
篇幅
约 132 分钟

版本

  1. v1当前

太难了

C++
//c++14
#include <bits/stdc++.h>

using namespace std;

// 随机数生成器
random_device rd;
mt19937 gen(rd());

// 工具函数
int randomInt(int min, int max) {
    uniform_int_distribution<> dis(min, max);
    return dis(gen);
}

double randomDouble(double min, double max) {
    uniform_real_distribution<> dis(min, max);
    return dis(gen);
}

string getTimeString(int day) {
    if (day == 0) return "创世之初";
    if (day == 1) return "创世第1天";
    return "创世第" + to_string(day) + "天";
}

// 颜色输出宏定义
#define RESET   "\033[0m"
#define RED     "\033[31m"
#define GREEN   "\033[32m"
#define YELLOW  "\033[33m"
#define BLUE    "\033[34m"
#define MAGENTA "\033[35m"
#define CYAN    "\033[36m"
#define WHITE   "\033[37m"

// 前向声明
class Element;
class Terrain;
class Creature;
class Civilization;
class Event;
class World;
class Game;

// 元素类 - 世界的基本构成单位
class Element {
private:
    string name;
    string description;
    int stability; // 稳定性 0-100
    int energy;    // 能量值 0-100
    bool isBasic;  // 是否为基本元素
    
public:
    Element(string n, string desc, int stab, int en, bool basic = false)
        : name(n), description(desc), stability(stab), energy(en), isBasic(basic) {}
    
    // 获取属性
    string getName() const { return name; }
    string getDescription() const { return description; }
    int getStability() const { return stability; }
    int getEnergy() const { return energy; }
    bool isBasicElement() const { return isBasic; }
    
    // 显示元素信息
    void showInfo() const {
        cout << CYAN << name << RESET << endl;
        cout << "  描述: " << description << endl;
        cout << "  稳定性: " << stability << "/100" << endl;
        cout << "  能量值: " << energy << "/100" << endl;
        cout << "  类型: " << (isBasic ? "基本元素" : "复合元素") << endl;
    }
};

// 地形类 - 由元素构成的地理特征
class Terrain {
private:
    string name;
    string type; // 山脉、海洋、森林等
    pair<int, int> coordinates; // 坐标位置
    vector<Element*> elements;  // 构成元素
    int size;     // 大小 1-100
    int fertility;// 肥沃度 0-100,影响生物生存
    bool hasLife; // 是否有生命存在
    
public:
    Terrain(string n, string t, int x, int y, int s)
        : name(n), type(t), coordinates({x, y}), size(s), 
          fertility(randomInt(30, 70)), hasLife(false) {}
    
    // 添加构成元素
    void addElement(Element* elem) {
        elements.push_back(elem);
    }
    
    // 获取属性
    string getName() const { return name; }
    string getType() const { return type; }
    pair<int, int> getCoordinates() const { return coordinates; }
    vector<Element*> getElements() const { return elements; }
    int getSize() const { return size; }
    int getFertility() const { return fertility; }
    bool getHasLife() const { return hasLife; }
    
    // 设置属性
    void setFertility(int f) { fertility = max(0, min(100, f)); }
    void setHasLife(bool life) { hasLife = life; }
    
    // 显示地形信息
    void showInfo() const {
        cout << GREEN << name << RESET << " (" << type << ")" << endl;
        cout << "  位置: (" << coordinates.first << "," << coordinates.second << ")" << endl;
        cout << "  大小: " << size << endl;
        cout << "  肥沃度: " << fertility << "/100" << endl;
        cout << "  构成元素: ";
        for (size_t i = 0; i < elements.size(); ++i) {
            if (i > 0) cout << ", ";
            cout << elements[i]->getName();
        }
        cout << endl;
        cout << "  生命存在: " << (hasLife ? "是" : "否") << endl;
    }
};

// 生物类 - 生活在世界中的生命体
class Creature {
private:
    string name;
    string species; // 物种
    Terrain* habitat; // 栖息地
    int population; // 种群数量
    int intelligence; // 智力 0-100
    int adaptability; // 适应力 0-100
    bool isSentient; // 是否有智慧
    vector<Element*> requiredElements; // 生存所需元素
    
public:
    Creature(string n, string s, Terrain* h, int pop, int intel, int adapt)
        : name(n), species(s), habitat(h), population(pop), 
          intelligence(intel), adaptability(adapt), 
          isSentient(intel >= 70) {
        if (habitat) {
            habitat->setHasLife(true);
        }
    }
    
    // 添加所需元素
    void addRequiredElement(Element* elem) {
        requiredElements.push_back(elem);
    }
    
    // 获取属性
    string getName() const { return name; }
    string getSpecies() const { return species; }
    Terrain* getHabitat() const { return habitat; }
    int getPopulation() const { return population; }
    int getIntelligence() const { return intelligence; }
    int getAdaptability() const { return adaptability; }
    bool getIsSentient() const { return isSentient; }
    
    // 设置属性
    void setPopulation(int pop) { population = max(0, pop); }
    void setHabitat(Terrain* h) { habitat = h; }
    void increaseIntelligence(int amount) { 
        intelligence = min(100, intelligence + amount); 
        isSentient = intelligence >= 70;
    }
    
    // 种群增长
    void grow() {
        // 增长受栖息地肥沃度和适应力影响
        int growthFactor = (habitat->getFertility() + adaptability) / 200.0 * 10;
        int newPopulation = population * (100 + growthFactor) / 100;
        setPopulation(newPopulation);
    }
    
    // 迁移到新栖息地
    bool migrate(Terrain* newHabitat) {
        // 检查新栖息地是否适合生存
        bool suitable = true;
        for (auto elem : requiredElements) {
            bool found = false;
            for (auto helem : newHabitat->getElements()) {
                if (elem->getName() == helem->getName()) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                suitable = false;
                break;
            }
        }
        
        if (suitable) {
            habitat->setHasLife(false); // 检查原栖息地是否还有其他生物
            habitat = newHabitat;
            habitat->setHasLife(true);
            return true;
        }
        return false;
    }
    
    // 显示生物信息
    void showInfo() const {
        cout << YELLOW << name << RESET << " (" << species << ")" << endl;
        cout << "  栖息地: " << habitat->getName() << endl;
        cout << "  种群数量: " << population << endl;
        cout << "  智力: " << intelligence << "/100" << endl;
        cout << "  适应力: " << adaptability << "/100" << endl;
        cout << "  状态: " << (isSentient ? "智慧生物" : "普通生物") << endl;
        cout << "  生存需求: ";
        for (size_t i = 0; i < requiredElements.size(); ++i) {
            if (i > 0) cout << ", ";
            cout << requiredElements[i]->getName();
        }
        cout << endl;
    }
};

// 文明类 - 由智慧生物建立的文明
class Civilization {
private:
    string name;
    Creature* founder; // 建立文明的生物
    Terrain* capital;  // 首都所在地
    vector<Terrain*> territories; // 领土
    int population;    // 人口
    int technology;    // 科技水平 0-1000
    int culture;       // 文化水平 0-1000
    int resources;     // 资源储备 0-10000
    int stability;     // 稳定性 0-100
    vector<string> inventions; // 发明创造
    string era;        // 时代
    
public:
    Civilization(string n, Creature* f, Terrain* c)
        : name(n), founder(f), capital(c), population(f->getPopulation()),
          technology(0), culture(0), resources(100), stability(70) {
        territories.push_back(capital);
        updateEra();
    }
    
    // 获取属性
    string getName() const { return name; }
    Creature* getFounder() const { return founder; }
    Terrain* getCapital() const { return capital; }
    vector<Terrain*> getTerritories() const { return territories; }
    int getPopulation() const { return population; }
    int getTechnology() const { return technology; }
    int getCulture() const { return culture; }
    int getResources() const { return resources; }
    int getStability() const { return stability; }
    vector<string> getInventions() const { return inventions; }
    string getEra() const { return era; }
    
    // 设置属性
    void setPopulation(int pop) { population = max(0, pop); }
    void setTechnology(int tech) { technology = max(0, tech); }
    void setCulture(int cult) { culture = max(0, cult); }
    void setResources(int res) { resources = max(0, res); }
    void setStability(int stab) { stability = max(0, min(100, stab)); }
    
    // 扩张领土
    bool expand(Terrain* newTerritory) {
        // 检查是否与现有领土相邻(简化版)
        auto capCoords = capital->getCoordinates();
        auto newCoords = newTerritory->getCoordinates();
        
        // 简单距离检查
        int distance = abs(capCoords.first - newCoords.first) + 
                      abs(capCoords.second - newCoords.second);
        
        if (distance <= 3) { // 距离足够近
            territories.push_back(newTerritory);
            return true;
        }
        return false;
    }
    
    // 发展
    void develop() {
        // 基于人口和资源的发展
        int baseGrowth = population / 100;
        int techGrowth = baseGrowth * (randomInt(50, 150) / 100.0);
        int cultGrowth = baseGrowth * (randomInt(30, 170) / 100.0);
        
        technology += techGrowth;
        culture += cultGrowth;
        
        // 资源变化
        int resourceChange = (territories.size() * 5) - (population / 20);
        resources += resourceChange;
        
        // 稳定性变化
        int stabilityChange = randomInt(-5, 5);
        if (resources < 50) stabilityChange -= 10;
        if (resources > 500) stabilityChange += 5;
        setStability(stability + stabilityChange);
        
        // 人口增长
        int popGrowth = (population / 100) * (stability / 100.0) * randomInt(80, 120) / 100.0;
        setPopulation(population + popGrowth);
        
        // 可能的新发明
        if (randomInt(0, 99) < technology / 10) {
            vector<string> possibleInventions = {
                "轮子", "文字", "金属冶炼", "农业", "畜牧业",
                "建筑术", "陶艺", "织布", "历法", "货币",
                "数学", "医学", "航海术", "灌溉系统", "音乐"
            };
            
            string newInvention = possibleInventions[randomInt(0, possibleInventions.size() - 1)];
            // 检查是否已发明
            if (find(inventions.begin(), inventions.end(), newInvention) == inventions.end()) {
                inventions.push_back(newInvention);
                cout << GREEN << name << "发明了" << newInvention << "!" << RESET << endl;
                technology += 20;
            }
        }
        
        updateEra();
    }
    
    // 更新时代
    void updateEra() {
        if (technology < 50) era = "石器时代";
        else if (technology < 150) era = "青铜时代";
        else if (technology < 300) era = "铁器时代";
        else if (technology < 500) era = "古典时代";
        else if (technology < 700) era = "中世纪";
        else era = "文艺复兴";
    }
    
    // 显示文明信息
    void showInfo() const {
        cout << MAGENTA << name << RESET << " (" << era << ")" << endl;
        cout << "  建立者: " << founder->getName() << endl;
        cout << "  首都: " << capital->getName() << endl;
        cout << "  领土: " << territories.size() << "块" << endl;
        cout << "  人口: " << population << endl;
        cout << "  科技水平: " << technology << endl;
        cout << "  文化水平: " << culture << endl;
        cout << "  资源储备: " << resources << endl;
        cout << "  稳定性: " << stability << "/100" << endl;
        
        if (!inventions.empty()) {
            cout << "  重要发明: ";
            for (size_t i = 0; i < min(5, (int)inventions.size()); ++i) {
                if (i > 0) cout << ", ";
                cout << inventions[i];
            }
            if (inventions.size() > 5) cout << " 等" << inventions.size() << "项";
            cout << endl;
        }
    }
};

// 事件类 - 影响世界的随机事件
class Event {
private:
    string name;
    string description;
    int severity; // 事件严重程度 1-10
    bool isPositive; // 是否为正面事件
    
public:
    Event(string n, string desc, int sev, bool positive)
        : name(n), description(desc), severity(sev), isPositive(positive) {}
    
    // 触发事件
    void trigger(World* world);
    
    // 获取属性
    bool getIsPositive() const { return isPositive; }
    
    // 显示事件信息
    void showInfo() const {
        if (isPositive) {
            cout << GREEN << "[事件] " << name << RESET << endl;
        } else {
            cout << RED << "[事件] " << name << RESET << endl;
        }
        cout << "  " << description << endl;
        cout << "  影响程度: " << severity << "/10" << endl;
    }
};

// 世界类 - 包含所有游戏对象
class World {
private:
    string name; // 世界名称
    int age;     // 世界年龄(天)
    vector<Element*> elements; // 所有元素
    vector<Terrain*> terrains; // 所有地形
    vector<Creature*> creatures; // 所有生物
    vector<Civilization*> civilizations; // 所有文明
    vector<Event*> events; // 可能发生的事件
    double balance; // 世界平衡度 0-100,影响事件生成
    
public:
    World(string n) : name(n), age(0), balance(50) {
        initializeEvents();
    }
    
    ~World() {
        for (auto elem : elements) delete elem;
        for (auto terrain : terrains) delete terrain;
        for (auto creature : creatures) delete creature;
        for (auto civ : civilizations) delete civ;
        for (auto event : events) delete event;
    }
    
    // 初始化事件库
    void initializeEvents();
    
    // 获取属性
    string getName() const { return name; }
    int getAge() const { return age; }
    vector<Element*> getElements() const { return elements; }
    vector<Terrain*> getTerrains() const { return terrains; }
    vector<Creature*> getCreatures() const { return creatures; }
    vector<Civilization*> getCivilizations() const { return civilizations; }
    vector<Event*> getEvents() const { return events; }
    double getBalance() const { return balance; }
    
    // 设置属性
    void setName(string n) { name = n; }
    void setBalance(double b) { balance = max(0.0, min(100.0, b)); }
    
    // 添加元素
    void addElement(Element* elem) {
        elements.push_back(elem);
        // 元素添加影响世界平衡
        setBalance(balance + (elem->getStability() - 50) * 0.1);
    }
    
    // 添加地形
    void addTerrain(Terrain* terrain) {
        terrains.push_back(terrain);
    }
    
    // 添加生物
    void addCreature(Creature* creature) {
        creatures.push_back(creature);
    }
    
    // 添加文明
    void addCivilization(Civilization* civ) {
        civilizations.push_back(civ);
    }
    
    // 查找元素
    Element* findElement(string name) const {
        for (auto elem : elements) {
            if (elem->getName() == name) {
                return elem;
            }
        }
        return nullptr;
    }
    
    // 查找地形
    Terrain* findTerrain(string name) const {
        for (auto terrain : terrains) {
            if (terrain->getName() == name) {
                return terrain;
            }
        }
        return nullptr;
    }
    
    // 查找生物
    Creature* findCreature(string name) const {
        for (auto creature : creatures) {
            if (creature->getName() == name) {
                return creature;
            }
        }
        return nullptr;
    }
    
    // 查找文明
    Civilization* findCivilization(string name) const {
        for (auto civ : civilizations) {
            if (civ->getName() == name) {
                return civ;
            }
        }
        return nullptr;
    }
    
    // 尝试组合元素创造新元素
    Element* combineElements(Element* e1, Element* e2);
    
    // 推进时间
    void advanceDay();
    
    // 随机发生事件
    void randomEvent();
    
    // 显示世界状态
    void showStatus() const {
        cout << "\n===== " << getName() << " (" << getTimeString(age) << ") =====" << endl;
        cout << "  世界平衡度: " << (int)balance << "/100" << endl;
        cout << "  元素数量: " << elements.size() << endl;
        cout << "  地形数量: " << terrains.size() << endl;
        cout << "  生物种类: " << creatures.size() << endl;
        cout << "  文明数量: " << civilizations.size() << endl;
    }
    
    // 显示所有元素
    void showAllElements() const {
        cout << "\n===== 世界元素 =====" << endl;
        if (elements.empty()) {
            cout << "世界中还没有元素。" << endl;
            return;
        }
        
        for (size_t i = 0; i < elements.size(); ++i) {
            cout << i + 1 << ". ";
            elements[i]->showInfo();
            if (i != elements.size() - 1) cout << endl;
        }
    }
    
    // 显示所有地形
    void showAllTerrains() const {
        cout << "\n===== 世界地形 =====" << endl;
        if (terrains.empty()) {
            cout << "世界中还没有地形。" << endl;
            return;
        }
        
        for (size_t i = 0; i < terrains.size(); ++i) {
            cout << i + 1 << ". ";
            terrains[i]->showInfo();
            if (i != terrains.size() - 1) cout << endl;
        }
    }
    
    // 显示所有生物
    void showAllCreatures() const {
        cout << "\n===== 世界生物 =====" << endl;
        if (creatures.empty()) {
            cout << "世界中还没有生物。" << endl;
            return;
        }
        
        for (size_t i = 0; i < creatures.size(); ++i) {
            cout << i + 1 << ". ";
            creatures[i]->showInfo();
            if (i != creatures.size() - 1) cout << endl;
        }
    }
    
    // 显示所有文明
    void showAllCivilizations() const {
        cout << "\n===== 世界文明 =====" << endl;
        if (civilizations.empty()) {
            cout << "世界中还没有文明。" << endl;
            return;
        }
        
        for (size_t i = 0; i < civilizations.size(); ++i) {
            cout << i + 1 << ". ";
            civilizations[i]->showInfo();
            if (i != civilizations.size() - 1) cout << endl;
        }
    }
};

// 实现World类的initializeEvents方法
void World::initializeEvents() {
    // 自然事件
    events.push_back(new Event("地震", "大地剧烈震动,改变了地形", 7, false));
    events.push_back(new Event("洪水", "大规模洪水淹没了低洼地区", 6, false));
    events.push_back(new Event("火山喷发", "火山喷发,喷出大量岩浆和灰烬", 8, false));
    events.push_back(new Event("暴风雨", "强烈的风暴席卷大地", 5, false));
    events.push_back(new Event("陨石撞击", "一颗陨石撞击了世界", 9, false));
    events.push_back(new Event("甘霖", "及时雨滋润了干旱的土地", 4, true));
    events.push_back(new Event("资源丰富", "发现了丰富的自然资源", 5, true));
    events.push_back(new Event("气候宜人", "气候变得非常适合生物生存", 3, true));
    
    // 生物事件
    events.push_back(new Event("物种大爆发", "大量新物种突然出现", 6, true));
    events.push_back(new Event("瘟疫", "致命的瘟疫在生物间传播", 7, false));
    events.push_back(new Event("生物进化", "某些生物发生了显著进化", 5, true));
    events.push_back(new Event("迁徙浪潮", "大规模生物迁徙开始了", 4, true));
    events.push_back(new Event("物种灭绝", "一个或多个物种灭绝了", 6, false));
    
    // 文明事件
    events.push_back(new Event("科技突破", "某个文明取得了重大科技突破", 5, true));
    events.push_back(new Event("文化繁荣", "文化艺术达到了新的高峰", 4, true));
    events.push_back(new Event("战争爆发", "文明之间爆发了战争", 7, false));
    events.push_back(new Event("和平条约", "敌对文明签订了和平条约", 5, true));
    events.push_back(new Event("革命", "某个文明发生了革命", 6, false));
    events.push_back(new Event("黄金时代", "一个文明进入了黄金时代", 8, true));
    events.push_back(new Event("饥荒", "严重的饥荒影响了文明发展", 7, false));
    events.push_back(new Event("伟大领袖", "一个伟大的领袖出现了", 6, true));
}

// 实现World类的combineElements方法
Element* World::combineElements(Element* e1, Element* e2) {
    if (!e1 || !e2) return nullptr;
    if (e1 == e2) return nullptr;
    
    // 元素组合规则
    map<pair<string, string>, pair<string, pair<string, pair<int, int>>>> combinations = {
        {{"土", "水"}, {"泥", {"土和水混合形成的半固体", {70, 40}}}},
        {{"水", "土"}, {"泥", {"土和水混合形成的半固体", {70, 40}}}},
        {{"土", "火"}, {"石", {"土被火加热形成的坚硬物质", {90, 50}}}},
        {{"火", "土"}, {"石", {"土被火加热形成的坚硬物质", {90, 50}}}},
        {{"土", "气"}, {"沙", {"土被气流侵蚀形成的细小颗粒", {50, 60}}}},
        {{"气", "土"}, {"沙", {"土被气流侵蚀形成的细小颗粒", {50, 60}}}},
        {{"水", "火"}, {"蒸汽", {"水被火加热形成的气体", {30, 80}}}},
        {{"火", "水"}, {"蒸汽", {"水被火加热形成的气体", {30, 80}}}},
        {{"水", "气"}, {"云", {"水与空气混合形成的漂浮物", {40, 60}}}},
        {{"气", "水"}, {"云", {"水与空气混合形成的漂浮物", {40, 60}}}},
        {{"火", "气"}, {"闪电", {"火与气混合产生的电能", {10, 100}}}},
        {{"气", "火"}, {"闪电", {"火与气混合产生的电能", {10, 100}}}},
        {{"泥", "火"}, {"陶", {"泥土烧制而成的坚硬材料", {85, 45}}}},
        {{"火", "泥"}, {"陶", {"泥土烧制而成的坚硬材料", {85, 45}}}},
        {{"石", "火"}, {"金属", {"石头被高温熔炼出的金属", {95, 70}}}},
        {{"火", "石"}, {"金属", {"石头被高温熔炼出的金属", {95, 70}}}},
        {{"云", "冷"}, {"冰", {"云冷却形成的固态水", {80, 20}}}},
        {{"冷", "云"}, {"冰", {"云冷却形成的固态水", {80, 20}}}},
        {{"水", "冷"}, {"冰", {"水冷却形成的固态", {80, 20}}}},
        {{"冷", "水"}, {"冰", {"水冷却形成的固态", {80, 20}}}},
        {{"闪电", "水"}, {"生命能量", {"闪电击中水产生的神秘能量", {20, 95}}}},
        {{"水", "闪电"}, {"生命能量", {"闪电击中水产生的神秘能量", {20, 95}}}}
    };
    
    // 检查是否有组合配方
    auto key = make_pair(e1->getName(), e2->getName());
    if (combinations.find(key) != combinations.end()) {
        auto result = combinations[key];
        string newName = result.first;
        string newDesc = result.second.first;
        int newStab = result.second.second.first;
        int newEnergy = result.second.second.second;
        
        // 检查新元素是否已存在
        if (findElement(newName)) {
            cout << YELLOW << "这个元素已经存在于世界中了。" << RESET << endl;
            return findElement(newName);
        }
        
        // 创建新元素
        Element* newElem = new Element(newName, newDesc, newStab, newEnergy);
        addElement(newElem);
        cout << GREEN << "成功创造了新元素: " << newName << RESET << endl;
        return newElem;
    } else {
        // 组合失败
        cout << RED << "这两种元素无法组合形成新元素。" << RESET << endl;
        // 组合失败影响世界平衡
        setBalance(balance - 5);
        return nullptr;
    }
}

// 实现World类的advanceDay方法
void World::advanceDay() {
    age++;
    cout << "\n" << getTimeString(age) << endl;
    
    // 生物自然生长
    for (auto creature : creatures) {
        // 有一定概率自然增长
        if (randomInt(0, 3) == 0) { // 25%概率
            creature->grow();
            
            // 有小概率进化
            if (randomInt(0, 99) < 5) { // 5%概率
                int intelGain = randomInt(1, 5);
                creature->increaseIntelligence(intelGain);
                cout << YELLOW << creature->getName() << "发生了进化,智力提升了" << intelGain << "点!" << RESET << endl;
                
                // 如果进化成智慧生物,可能建立文明
                if (creature->getIsSentient() && randomInt(0, 19) == 0) { // 5%概率
                    // 检查是否已有以该生物建立的文明
                    bool hasCiv = false;
                    for (auto civ : civilizations) {
                        if (civ->getFounder() == creature) {
                            hasCiv = true;
                            break;
                        }
                    }
                    
                    if (!hasCiv) {
                        string civName = creature->getName() + "文明";
                        Civilization* newCiv = new Civilization(civName, creature, creature->getHabitat());
                        addCivilization(newCiv);
                        cout << MAGENTA << "历史性时刻! " << creature->getName() << "建立了" << civName << "!" << RESET << endl;
                    }
                }
            }
        }
        
        // 有小概率迁移
        if (randomInt(0, 19) == 0 && terrains.size() > 1) { // 5%概率
            Terrain* newHabitat = terrains[randomInt(0, terrains.size() - 1)];
            if (newHabitat != creature->getHabitat() && creature->migrate(newHabitat)) {
                cout << YELLOW << creature->getName() << "迁移到了" << newHabitat->getName() << RESET << endl;
            }
        }
    }
    
    // 文明发展
    for (auto civ : civilizations) {
        civ->develop();
        
        // 有概率扩张
        if (randomInt(0, 9) == 0 && terrains.size() > civ->getTerritories().size()) { // 10%概率
            // 随机选择一个未被占领的地形
            vector<Terrain*> availableTerrains;
            for (auto t : terrains) {
                bool isOwned = false;
                for (auto ct : civ->getTerritories()) {
                    if (t == ct) {
                        isOwned = true;
                        break;
                    }
                }
                if (!isOwned) availableTerrains.push_back(t);
            }
            
            if (!availableTerrains.empty()) {
                Terrain* target = availableTerrains[randomInt(0, availableTerrains.size() - 1)];
                if (civ->expand(target)) {
                    cout << MAGENTA << civ->getName() << "扩张到了" << target->getName() << RESET << endl;
                }
            }
        }
    }
    
    // 每天有30%概率发生随机事件
    if (randomInt(0, 9) < 3) {
        randomEvent();
    }
    
    // 世界平衡自动调整
    setBalance(balance + randomDouble(-2, 2));
}

// 实现World类的randomEvent方法
void World::randomEvent() {
    // 根据世界平衡度选择事件类型,平衡度低则负面事件概率高
    double negativeProb = (100 - balance) / 100.0;
    
    vector<Event*> possibleEvents;
    
    if (randomDouble(0, 1) < negativeProb) {
        // 选择负面事件
        for (auto e : events) {
            if (!e->getIsPositive()) {
                possibleEvents.push_back(e);
            }
        }
    } else {
        // 选择正面事件
        for (auto e : events) {
            if (e->getIsPositive()) {
                possibleEvents.push_back(e);
            }
        }
    }
    
    if (possibleEvents.empty()) {
        possibleEvents = events; // 以防万一
    }
    
    // 随机选择一个事件
    Event* selected = possibleEvents[randomInt(0, possibleEvents.size() - 1)];
    selected->trigger(this);
}

// 实现Event类的trigger方法
void Event::trigger(World* world) {
    showInfo();
    
    // 根据事件类型处理不同影响
    if (name == "地震") {
        // 随机改变一些地形
        if (!world->getTerrains().empty()) {
            int affected = randomInt(1, max(1, (int)world->getTerrains().size() / 5));
            for (int i = 0; i < affected; ++i) {
                Terrain* t = world->getTerrains()[randomInt(0, world->getTerrains().size() - 1)];
                t->setFertility(t->getFertility() - randomInt(10, 30));
                cout << "  " << t->getName() << "受到地震影响,肥沃度下降。" << endl;
            }
            world->setBalance(world->getBalance() - 5 * severity);
        }
    } 
    else if (name == "洪水") {
        if (!world->getTerrains().empty()) {
            int affected = randomInt(1, max(1, (int)world->getTerrains().size() / 4));
            for (int i = 0; i < affected; ++i) {
                Terrain* t = world->getTerrains()[randomInt(0, world->getTerrains().size() - 1)];
                t->setFertility(t->getFertility() + randomInt(5, 15)); // 洪水过后土地可能更肥沃
                cout << "  " << t->getName() << "被洪水淹没,地形发生改变。" << endl;
            }
            world->setBalance(world->getBalance() - 4 * severity);
        }
    }
    else if (name == "甘霖") {
        if (!world->getTerrains().empty()) {
            int affected = randomInt(1, max(1, (int)world->getTerrains().size() / 3));
            for (int i = 0; i < affected; ++i) {
                Terrain* t = world->getTerrains()[randomInt(0, world->getTerrains().size() - 1)];
                t->setFertility(t->getFertility() + randomInt(10, 20));
                cout << "  " << t->getName() << "得到雨水滋润,肥沃度提升。" << endl;
            }
            world->setBalance(world->getBalance() + 3 * severity);
        }
    }
    else if (name == "物种大爆发") {
        // 创建新生物
        vector<string> species = {"飞鸟", "走兽", "鱼类", "昆虫", "植物"};
        vector<string> names = {"迅捷的", "强壮的", "智慧的", "美丽的", "神秘的"};
        
        int newSpecies = randomInt(1, 3);
        for (int i = 0; i < newSpecies; ++i) {
            if (world->getTerrains().empty()) break;
            
            string creatureName = names[randomInt(0, names.size() - 1)] + species[randomInt(0, species.size() - 1)];
            Terrain* habitat = world->getTerrains()[randomInt(0, world->getTerrains().size() - 1)];
            Creature* newCreature = new Creature(
                creatureName,
                species[randomInt(0, species.size() - 1)],
                habitat,
                randomInt(50, 500),
                randomInt(10, 60),
                randomInt(30, 80)
            );
            
            // 随机添加所需元素
            if (!world->getElements().empty()) {
                int reqCount = randomInt(1, 3);
                for (int j = 0; j < reqCount; ++j) {
                    Element* reqElem = world->getElements()[randomInt(0, world->getElements().size() - 1)];
                    newCreature->addRequiredElement(reqElem);
                }
            }
            
            world->addCreature(newCreature);
            cout << "  新物种" << creatureName << "出现在" << habitat->getName() << endl;
        }
        world->setBalance(world->getBalance() + 5 * severity);
    }
    else if (name == "瘟疫") {
        if (!world->getCreatures().empty()) {
            int affected = randomInt(1, max(1, (int)world->getCreatures().size() / 3));
            for (int i = 0; i < affected; ++i) {
                Creature* c = world->getCreatures()[randomInt(0, world->getCreatures().size() - 1)];
                int loss = c->getPopulation() * randomInt(20, 50) / 100;
                c->setPopulation(c->getPopulation() - loss);
                cout << "  " << c->getName() << "遭受瘟疫,损失了" << loss << "个体。" << endl;
                
                // 可能导致灭绝
                if (c->getPopulation() == 0) {
                    cout << RED << "  不幸的是," << c->getName() << "已经灭绝了。" << RESET << endl;
                }
            }
            world->setBalance(world->getBalance() - 6 * severity);
        }
    }
    else if (name == "生物进化") {
        if (!world->getCreatures().empty()) {
            Creature* c = world->getCreatures()[randomInt(0, world->getCreatures().size() - 1)];
            int intelGain = randomInt(5, 15);
            c->increaseIntelligence(intelGain);
            cout << "  " << c->getName() << "经历了显著进化,智力提升了" << intelGain << "点!" << endl;
            
            // 如果进化成智慧生物,可能建立文明
            if (c->getIsSentient()) {
                bool hasCiv = false;
                for (auto civ : world->getCivilizations()) {
                    if (civ->getFounder() == c) {
                        hasCiv = true;
                        break;
                    }
                }
                
                if (!hasCiv && randomInt(0, 3) == 0) { // 25%概率
                    string civName = c->getName() + "文明";
                    Civilization* newCiv = new Civilization(civName, c, c->getHabitat());
                    world->addCivilization(newCiv);
                    cout << MAGENTA << "  历史性时刻! " << c->getName() << "建立了" << civName << "!" << RESET << endl;
                }
            }
            world->setBalance(world->getBalance() + 4 * severity);
        }
    }
    else if (name == "科技突破") {
        if (!world->getCivilizations().empty()) {
            Civilization* civ = world->getCivilizations()[randomInt(0, world->getCivilizations().size() - 1)];
            int techGain = randomInt(30, 80);
            civ->setTechnology(civ->getTechnology() + techGain);
            cout << "  " << civ->getName() << "取得了重大科技突破,科技水平提升了" << techGain << "点!" << endl;
            world->setBalance(world->getBalance() + 5 * severity);
        }
    }
    else if (name == "黄金时代") {
        if (!world->getCivilizations().empty()) {
            Civilization* civ = world->getCivilizations()[randomInt(0, world->getCivilizations().size() - 1)];
            int techGain = randomInt(50, 150);
            int cultGain = randomInt(50, 150);
            civ->setTechnology(civ->getTechnology() + techGain);
            civ->setCulture(civ->getCulture() + cultGain);
            civ->setResources(civ->getResources() + randomInt(200, 500));
            cout << "  " << civ->getName() << "进入了黄金时代! 科技+=" << techGain << ", 文化+=" << cultGain << endl;
            world->setBalance(world->getBalance() + 8 * severity);
        }
    }
    else if (name == "战争爆发") {
        if (world->getCivilizations().size() >= 2) {
            Civilization* civ1 = world->getCivilizations()[randomInt(0, world->getCivilizations().size() - 1)];
            Civilization* civ2;
            do {
                civ2 = world->getCivilizations()[randomInt(0, world->getCivilizations().size() - 1)];
            } while (civ1 == civ2);
            
            cout << "  " << civ1->getName() << "与" << civ2->getName() << "爆发了战争!" << endl;
            civ1->setStability(civ1->getStability() - 20);
            civ2->setStability(civ2->getStability() - 20);
            civ1->setResources(civ1->getResources() - 100);
            civ2->setResources(civ2->getResources() - 100);
            world->setBalance(world->getBalance() - 7 * severity);
        }
    }
    else if (name == "资源丰富") {
        if (!world->getTerrains().empty()) {
            Terrain* t = world->getTerrains()[randomInt(0, world->getTerrains().size() - 1)];
            t->setFertility(t->getFertility() + randomInt(15, 30));
            
            // 如果有文明在该地形上,资源增加
            for (auto civ : world->getCivilizations()) {
                for (auto ct : civ->getTerritories()) {
                    if (ct == t) {
                        civ->setResources(civ->getResources() + randomInt(100, 300));
                        cout << "  " << civ->getName() << "发现了丰富的资源,资源增加!" << endl;
                        break;
                    }
                }
            }
            world->setBalance(world->getBalance() + 5 * severity);
        }
    }
}

// 游戏类 - 处理游戏流程
class Game {
private:
    World* world;
    bool isRunning;
    bool cheatMode; // 作弊模式
    
public:
    Game() : isRunning(true), cheatMode(false) {
        // 创建世界
        cout << MAGENTA << "===== 欢迎来到创世主模拟器 =====" << RESET << endl;
        cout << "请为你的世界命名: ";
        string worldName;
        getline(cin, worldName);
        if (worldName.empty()) worldName = "我的创世世界";
        world = new World(worldName);
        
        // 初始化基本元素
        initializeBasicElements();
    }
    
    ~Game() {
        delete world;
    }
    
    // 初始化基本元素
    void initializeBasicElements() {
        world->addElement(new Element("土", "构成固体物质的基本元素", 80, 30, true));
        world->addElement(new Element("水", "构成液体的基本元素", 60, 50, true));
        world->addElement(new Element("火", "提供能量和热量的基本元素", 20, 90, true));
        world->addElement(new Element("气", "构成气体的基本元素", 40, 70, true));
        
        cout << GREEN << "\n创世之初,你创造了四个基本元素: 土、水、火、气" << RESET << endl;
    }
    
    // 运行游戏
    void run() {
        while (isRunning) {
            showMainMenu();
            handleInput();
        }
        
        cout << "\n创世结束。感谢你的参与!" << endl;
    }
    
    // 显示主菜单
    void showMainMenu() const {
        world->showStatus();
        cout << "\n===== 创世主菜单 =====" << endl;
        cout << "1. 元素操作 - 创造和组合元素" << endl;
        cout << "2. 地形塑造 - 创建和修改地形" << endl;
        cout << "3. 生命创造 - 创造和观察生物" << endl;
        cout << "4. 文明引导 - 查看和影响文明" << endl;
        cout << "5. 时间流逝 - 推进世界发展" << endl;
        cout << "6. 世界观察 - 查看世界全貌" << endl;
        cout << "7. 创世干预 - 触发特殊事件" << endl;
        if (cheatMode) {
            cout << "8. 作弊菜单 - 创世主的秘密力量" << endl;
        }
        cout << "0. 结束创世 - 离开这个世界" << endl;
        cout << "请选择你的行动: ";
    }
    
    // 处理用户输入
    void handleInput() {
        int choice;
        cin >> choice;
        cin.ignore(numeric_limits<streamsize>::max(), '\n');
        
        switch (choice) {
            case 1:
                elementMenu();
                break;
            case 2:
                terrainMenu();
                break;
            case 3:
                creatureMenu();
                break;
            case 4:
                civilizationMenu();
                break;
            case 5:
                advanceTimeMenu();
                break;
            case 6:
                observeWorldMenu();
                break;
            case 7:
                triggerEventMenu();
                break;
            case 8:
                if (cheatMode) cheatMenu();
                else invalidChoice();
                break;
            case 0:
                isRunning = false;
                break;
            default:
                invalidChoice();
        }
    }
    
    // 无效选择处理
    void invalidChoice() const {
        cout << RED << "无效的选择,请重试。" << RESET << endl;
        pause();
    }
    
    // 暂停等待用户
    void pause() const {
        cout << "\n按回车键继续...";
        cin.get();
    }
    
    // 元素操作菜单
    void elementMenu();
    
    // 地形塑造菜单
    void terrainMenu();
    
    // 生命创造菜单
    void creatureMenu();
    
    // 文明引导菜单
    void civilizationMenu();
    
    // 时间流逝菜单
    void advanceTimeMenu();
    
    // 世界观察菜单
    void observeWorldMenu();
    
    // 触发事件菜单
    void triggerEventMenu();
    
    // 作弊菜单
    void cheatMenu();
};

// 实现Game类的elementMenu方法
void Game::elementMenu() {
    cout << "\n===== 元素操作 =====" << endl;
    cout << "1. 查看所有元素" << endl;
    cout << "2. 组合两种元素" << endl;
    cout << "3. 创造新的基本元素 (需要特殊条件)" << endl;
    cout << "0. 返回主菜单" << endl;
    cout << "请选择: ";
    
    int choice;
    cin >> choice;
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    
    switch (choice) {
        case 1:
            world->showAllElements();
            pause();
            break;
        case 2: {
            if (world->getElements().size() < 2) {
                cout << RED << "世界中的元素太少,无法组合。" << RESET << endl;
                pause();
                break;
            }
            
            world->showAllElements();
            cout << "\n请输入要组合的第一种元素编号: ";
            int e1;
            cin >> e1;
            cout << "请输入要组合的第二种元素编号: ";
            int e2;
            cin >> e2;
            
            if (e1 < 1 || e1 > (int)world->getElements().size() || 
                e2 < 1 || e2 > (int)world->getElements().size() || 
                e1 == e2) {
                cout << RED << "无效的元素选择。" << RESET << endl;
                pause();
                break;
            }
            
            world->combineElements(world->getElements()[e1 - 1], world->getElements()[e2 - 1]);
            pause();
            break;
        }
        case 3: {
            // 创造新基本元素需要世界平衡度很高
            if (world->getBalance() < 80 && !cheatMode) {
                cout << RED << "世界平衡度不足,无法创造新的基本元素。需要平衡度达到80以上。" << RESET << endl;
                pause();
                break;
            }
            
            cout << "请输入新基本元素的名称: ";
            string name;
            getline(cin, name);
            
            if (world->findElement(name)) {
                cout << RED << "这个元素已经存在。" << RESET << endl;
                pause();
                break;
            }
            
            cout << "请输入元素描述: ";
            string desc;
            getline(cin, desc);
            
            int stability = randomInt(30, 70);
            int energy = randomInt(30, 70);
            
            world->addElement(new Element(name, desc, stability, energy, true));
            cout << GREEN << "成功创造了新的基本元素: " << name << RESET << endl;
            world->setBalance(world->getBalance() - 20); // 创造基本元素消耗大量平衡
            pause();
            break;
        }
        case 0:
            return;
        default:
            invalidChoice();
    }
}

// 实现Game类的terrainMenu方法
void Game::terrainMenu() {
    cout << "\n===== 地形塑造 =====" << endl;
    cout << "1. 查看所有地形" << endl;
    cout << "2. 创建新地形" << endl;
    cout << "3. 修改现有地形" << endl;
    cout << "0. 返回主菜单" << endl;
    cout << "请选择: ";
    
    int choice;
    cin >> choice;
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    
    switch (choice) {
        case 1:
            world->showAllTerrains();
            pause();
            break;
        case 2: {
            if (world->getElements().empty()) {
                cout << RED << "没有元素,无法创造地形。请先创造元素。" << RESET << endl;
                pause();
                break;
            }
            
            cout << "请输入地形名称: ";
            string name;
            getline(cin, name);
            
            if (world->findTerrain(name)) {
                cout << RED << "这个地形已经存在。" << RESET << endl;
                pause();
                break;
            }
            
            cout << "请输入地形类型 (如: 山脉、平原、海洋、森林等): ";
            string type;
            getline(cin, type);
            
            // 随机坐标
            int x = randomInt(-10, 10);
            int y = randomInt(-10, 10);
            cout << "地形将生成在坐标 (" << x << "," << y << ")" << endl;
            
            cout << "请输入地形大小 (1-100): ";
            int size;
            cin >> size;
            size = max(1, min(100, size));
            
            // 创建地形
            Terrain* newTerrain = new Terrain(name, type, x, y, size);
            
            // 选择构成元素
            world->showAllElements();
            cout << "请选择构成地形的元素 (输入编号,用空格分隔,0结束): ";
            
            vector<int> elemIndices;
            int idx;
            while (cin >> idx && idx != 0) {
                if (idx > 0 && idx <= (int)world->getElements().size()) {
                    elemIndices.push_back(idx - 1);
                } else {
                    cout << RED << "无效的元素编号,已忽略。" << RESET << endl;
                }
            }
            
            if (elemIndices.empty()) {
                // 至少需要一种元素
                cout << YELLOW << "未选择元素,将随机选择一种基本元素。" << RESET << endl;
                vector<Element*> basicElements;
                for (auto e : world->getElements()) {
                    if (e->isBasicElement()) {
                        basicElements.push_back(e);
                    }
                }
                if (!basicElements.empty()) {
                    newTerrain->addElement(basicElements[randomInt(0, basicElements.size() - 1)]);
                } else {
                    newTerrain->addElement(world->getElements()[0]);
                }
            } else {
                // 添加选择的元素
                for (int i : elemIndices) {
                    newTerrain->addElement(world->getElements()[i]);
                }
            }
            
            world->addTerrain(newTerrain);
            cout << GREEN << "成功创造了新地形: " << name << RESET << endl;
            pause();
            break;
        }
        case 3: {
            if (world->getTerrains().empty()) {
                cout << RED << "世界中还没有地形。" << RESET << endl;
                pause();
                break;
            }
            
            world->showAllTerrains();
            cout << "请选择要修改的地形编号: ";
            int t;
            cin >> t;
            
            if (t < 1 || t > (int)world->getTerrains().size()) {
                cout << RED << "无效的地形编号。" << RESET << endl;
                pause();
                break;
            }
            
            Terrain* terrain = world->getTerrains()[t - 1];
            cout << "\n1. 修改名称" << endl;
            cout << "2. 修改肥沃度" << endl;
            cout << "3. 添加构成元素" << endl;
            cout << "0. 返回" << endl;
            cout << "请选择: ";
            
            int action;
            cin >> action;
            cin.ignore(numeric_limits<streamsize>::max(), '\n');
            
            switch (action) {
                case 1: {
                    cout << "请输入新名称: ";
                    string newName;
                    getline(cin, newName);
                    // 这里无法直接修改名称,因为我们没有setter方法,所以只是模拟
                    cout << YELLOW << "地形名称已修改为: " << newName << RESET << endl;
                    break;
                }
                case 2: {
                    cout << "请输入新的肥沃度 (0-100): ";
                    int fert;
                    cin >> fert;
                    terrain->setFertility(fert);
                    cout << GREEN << "地形肥沃度已修改为: " << fert << RESET << endl;
                    break;
                }
                case 3: {
                    world->showAllElements();
                    cout << "请选择要添加的元素编号: ";
                    int e;
                    cin >> e;
                    
                    if (e < 1 || e > (int)world->getElements().size()) {
                        cout << RED << "无效的元素编号。" << RESET << endl;
                        break;
                    }
                    
                    terrain->addElement(world->getElements()[e - 1]);
                    cout << GREEN << "已向" << terrain->getName() << "添加元素: " << world->getElements()[e - 1]->getName() << RESET << endl;
                    break;
                }
                case 0:
                    break;
                default:
                    invalidChoice();
            }
            pause();
            break;
        }
        case 0:
            return;
        default:
            invalidChoice();
    }
}

// 实现Game类的creatureMenu方法
void Game::creatureMenu() {
    cout << "\n===== 生命创造 =====" << endl;
    cout << "1. 查看所有生物" << endl;
    cout << "2. 创造新生物" << endl;
    cout << "3. 加速生物进化" << endl;
    cout << "0. 返回主菜单" << endl;
    cout << "请选择: ";
    
    int choice;
    cin >> choice;
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    
    switch (choice) {
        case 1:
            world->showAllCreatures();
            pause();
            break;
        case 2: {
            if (world->getTerrains().empty()) {
                cout << RED << "没有地形,无法创造生物。请先创造地形。" << RESET << endl;
                pause();
                break;
            }
            
            // 检查是否有生命能量元素
            bool hasLifeEnergy = false;
            for (auto e : world->getElements()) {
                if (e->getName() == "生命能量") {
                    hasLifeEnergy = true;
                    break;
                }
            }
            
            if (!hasLifeEnergy && !cheatMode) {
                cout << RED << "没有生命能量,无法创造生物。请先通过水和闪电的组合获得生命能量。" << RESET << endl;
                pause();
                break;
            }
            
            cout << "请输入生物名称: ";
            string name;
            getline(cin, name);
            
            if (world->findCreature(name)) {
                cout << RED << "这种生物已经存在。" << RESET << endl;
                pause();
                break;
            }
            
            cout << "请输入生物物种: ";
            string species;
            getline(cin, species);
            
            // 选择栖息地
            world->showAllTerrains();
            cout << "请选择生物的栖息地编号: ";
            int t;
            cin >> t;
            
            if (t < 1 || t > (int)world->getTerrains().size()) {
                cout << RED << "无效的地形编号。" << RESET << endl;
                pause();
                break;
            }
            
            Terrain* habitat = world->getTerrains()[t - 1];
            
            cout << "请输入初始种群数量: ";
            int population;
            cin >> population;
            population = max(10, min(1000, population));
            
            cout << "请输入初始智力水平 (0-100): ";
            int intelligence;
            cin >> intelligence;
            intelligence = max(0, min(100, intelligence));
            
            cout << "请输入适应力水平 (0-100): ";
            int adaptability;
            cin >> adaptability;
            adaptability = max(0, min(100, adaptability));
            
            // 创建生物
            Creature* newCreature = new Creature(name, species, habitat, population, intelligence, adaptability);
            
            // 添加所需元素
            if (!world->getElements().empty()) {
                // 自动选择栖息地的元素作为生存需求
                for (auto elem : habitat->getElements()) {
                    newCreature->addRequiredElement(elem);
                }
                // 再随机添加1-2种其他元素
                int extra = randomInt(1, 2);
                for (int i = 0; i < extra; ++i) {
                    Element* elem = world->getElements()[randomInt(0, world->getElements().size() - 1)];
                    newCreature->addRequiredElement(elem);
                }
            }
            
            world->addCreature(newCreature);
            cout << GREEN << "成功创造了新生物: " << name << RESET << endl;
            pause();
            break;
        }
        case 3: {
            if (world->getCreatures().empty()) {
                cout << RED << "世界中还没有生物。" << RESET << endl;
                pause();
                break;
            }
            
            world->showAllCreatures();
            cout << "请选择要加速进化的生物编号: ";
            int c;
            cin >> c;
            
            if (c < 1 || c > (int)world->getCreatures().size()) {
                cout << RED << "无效的生物编号。" << RESET << endl;
                pause();
                break;
            }
            
            Creature* creature = world->getCreatures()[c - 1];
            int gain = randomInt(5, 20);
            creature->increaseIntelligence(gain);
            cout << GREEN << creature->getName() << "的智力提升了" << gain << "点!" << RESET << endl;
            
            // 如果进化成智慧生物,提示可能建立文明
            if (creature->getIsSentient()) {
                cout << MAGENTA << "这个生物已经成为智慧生物,可能会建立文明!" << RESET << endl;
            }
            
            pause();
            break;
        }
        case 0:
            return;
        default:
            invalidChoice();
    }
}

// 实现Game类的civilizationMenu方法
void Game::civilizationMenu() {
    cout << "\n===== 文明引导 =====" << endl;
    cout << "1. 查看所有文明" << endl;
    cout << "2. 帮助特定文明发展" << endl;
    cout << "3. 直接创建新文明 (需要智慧生物)" << endl;
    cout << "0. 返回主菜单" << endl;
    cout << "请选择: ";
    
    int choice;
    cin >> choice;
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    
    switch (choice) {
        case 1:
            world->showAllCivilizations();
            pause();
            break;
        case 2: {
            if (world->getCivilizations().empty()) {
                cout << RED << "世界中还没有文明。" << RESET << endl;
                pause();
                break;
            }
            
            world->showAllCivilizations();
            cout << "请选择要帮助的文明编号: ";
            int c;
            cin >> c;
            
            if (c < 1 || c > (int)world->getCivilizations().size()) {
                cout << RED << "无效的文明编号。" << RESET << endl;
                pause();
                break;
            }
            
            Civilization* civ = world->getCivilizations()[c - 1];
            cout << "\n1. 提升科技水平" << endl;
            cout << "2. 提升文化水平" << endl;
            cout << "3. 增加资源储备" << endl;
            cout << "4. 提高稳定性" << endl;
            cout << "0. 返回" << endl;
            cout << "请选择帮助方式: ";
            
            int action;
            cin >> action;
            
            switch (action) {
                case 1: {
                    int gain = randomInt(20, 50);
                    civ->setTechnology(civ->getTechnology() + gain);
                    cout << GREEN << civ->getName() << "的科技水平提升了" << gain << "点!" << RESET << endl;
                    break;
                }
                case 2: {
                    int gain = randomInt(20, 50);
                    civ->setCulture(civ->getCulture() + gain);
                    cout << GREEN << civ->getName() << "的文化水平提升了" << gain << "点!" << RESET << endl;
                    break;
                }
                case 3: {
                    int gain = randomInt(100, 300);
                    civ->setResources(civ->getResources() + gain);
                    cout << GREEN << civ->getName() << "的资源增加了" << gain << "单位!" << RESET << endl;
                    break;
                }
                case 4: {
                    int gain = randomInt(5, 20);
                    civ->setStability(civ->getStability() + gain);
                    cout << GREEN << civ->getName() << "的稳定性提升了" << gain << "点!" << RESET << endl;
                    break;
                }
                case 0:
                    break;
                default:
                    invalidChoice();
            }
            
            world->setBalance(world->getBalance() - 5); // 干预文明会消耗世界平衡
            pause();
            break;
        }
        case 3: {
            // 寻找智慧生物
            vector<Creature*> sentientCreatures;
            for (auto c : world->getCreatures()) {
                if (c->getIsSentient()) {
                    // 检查是否已有文明
                    bool hasCiv = false;
                    for (auto civ : world->getCivilizations()) {
                        if (civ->getFounder() == c) {
                            hasCiv = true;
                            break;
                        }
                    }
                    if (!hasCiv) {
                        sentientCreatures.push_back(c);
                    }
                }
            }
            
            if (sentientCreatures.empty()) {
                cout << RED << "没有合适的智慧生物来建立文明。请先让生物进化到智慧水平。" << RESET << endl;
                pause();
                break;
            }
            
            cout << "请选择文明的建立者: " << endl;
            for (size_t i = 0; i < sentientCreatures.size(); ++i) {
                cout << i + 1 << ". " << sentientCreatures[i]->getName() << " (栖息地: " << sentientCreatures[i]->getHabitat()->getName() << ")" << endl;
            }
            
            cout << "请选择: ";
            int c;
            cin >> c;
            
            if (c < 1 || c > (int)sentientCreatures.size()) {
                cout << RED << "无效的选择。" << RESET << endl;
                pause();
                break;
            }
            
            Creature* founder = sentientCreatures[c - 1];
            cout << "请为这个文明命名: ";
            string name;
            cin.ignore();
            getline(cin, name);
            
            if (name.empty()) {
                name = founder->getName() + "文明";
            }
            
            Civilization* newCiv = new Civilization(name, founder, founder->getHabitat());
            world->addCivilization(newCiv);
            cout << GREEN << "成功创建了新文明: " << name << RESET << endl;
            pause();
            break;
        }
        case 0:
            return;
        default:
            invalidChoice();
    }
}

// 实现Game类的advanceTimeMenu方法
void Game::advanceTimeMenu() {
    cout << "\n===== 时间流逝 =====" << endl;
    cout << "当前时间: " << getTimeString(world->getAge()) << endl;
    cout << "1. 推进1天" << endl;
    cout << "2. 推进7天" << endl;
    cout << "3. 推进30天" << endl;
    cout << "4. 快速推进直到发生重要事件" << endl;
    cout << "0. 返回主菜单" << endl;
    cout << "请选择: ";
    
    int choice;
    cin >> choice;
    
    switch (choice) {
        case 1:
            world->advanceDay();
            pause();
            break;
        case 2:
            for (int i = 0; i < 7; ++i) {
                world->advanceDay();
                this_thread::sleep_for(chrono::milliseconds(300));
            }
            pause();
            break;
        case 3:
            for (int i = 0; i < 30; ++i) {
                world->advanceDay();
                if (i % 7 == 0) { // 每7天暂停一下
                    cout << "\n按回车键继续..." << endl;
                    cin.get();
                } else {
                    this_thread::sleep_for(chrono::milliseconds(200));
                }
            }
            pause();
            break;
        case 4: {
            cout << "开始快速推进时间,直到发生重要事件..." << endl;
            int daysPassed = 0;
            bool eventOccurred = false;
            
            while (!eventOccurred) {
                // 保存当前事件数量
                int prevEvents = 0; // 这里只是模拟,实际需要计数
                world->advanceDay();
                daysPassed++;
                
                // 检查是否有重要事件发生
                // 简化处理:每推进5天或发生了事件就停止
                if (daysPassed >= 5 || randomInt(0, 4) == 0) {
                    eventOccurred = true;
                }
                
                this_thread::sleep_for(chrono::milliseconds(100));
            }
            
            cout << "已推进" << daysPassed << "天。" << endl;
            pause();
            break;
        }
        case 0:
            return;
        default:
            invalidChoice();
    }
}

// 实现Game类的observeWorldMenu方法
void Game::observeWorldMenu() {
    cout << "\n===== 世界观察 =====" << endl;
    cout << "1. 查看世界概览" << endl;
    cout << "2. 查看所有元素" << endl;
    cout << "3. 查看所有地形" << endl;
    cout << "4. 查看所有生物" << endl;
    cout << "5. 查看所有文明" << endl;
    cout << "6. 查看世界地图" << endl;
    cout << "0. 返回主菜单" << endl;
    cout << "请选择: ";
    
    int choice;
    cin >> choice;
    
    switch (choice) {
        case 1:
            world->showStatus();
            pause();
            break;
        case 2:
            world->showAllElements();
            pause();
            break;
        case 3:
            world->showAllTerrains();
            pause();
            break;
        case 4:
            world->showAllCreatures();
            pause();
            break;
        case 5:
            world->showAllCivilizations();
            pause();
            break;
        case 6: {
            cout << "\n===== 世界地图 =====" << endl;
            cout << "坐标系统: (x,y) 范围: -10到10" << endl;
            
            // 简化的地图显示
            const int SIZE = 5; // 缩小显示范围
            for (int y = SIZE; y >= -SIZE; --y) {
                for (int x = -SIZE; x <= SIZE; ++x) {
                    bool hasTerrain = false;
                    for (auto t : world->getTerrains()) {
                        auto coords = t->getCoordinates();
                        if (coords.first == x && coords.second == y) {
                            hasTerrain = true;
                            // 根据地形类型显示不同符号
                            if (t->getType() == "海洋" || t->getType() == "湖泊") {
                                cout << BLUE << "~" << RESET;
                            } else if (t->getType() == "山脉" || t->getType() == "山地") {
                                cout << WHITE << "^" << RESET;
                            } else if (t->getType() == "森林" || t->getType() == "丛林") {
                                cout << GREEN << "*" << RESET;
                            } else if (t->getType() == "平原" || t->getType() == "草原") {
                                cout << YELLOW << "." << RESET;
                            } else {
                                cout << CYAN << "+" << RESET;
                            }
                            break;
                        }
                    }
                    if (!hasTerrain) {
                        cout << " ";
                    }
                }
                cout << endl;
            }
            
            cout << "\n图例: " << BLUE << "~" << RESET << "=水域 " 
                 << WHITE << "^" << RESET << "=山脉 " 
                 << GREEN << "*" << RESET << "=森林 " 
                 << YELLOW << "." << RESET << "=平原 "
                 << CYAN << "+" << RESET << "=其他地形" << endl;
            
            pause();
            break;
        }
        case 0:
            return;
        default:
            invalidChoice();
    }
}

// 实现Game类的triggerEventMenu方法
void Game::triggerEventMenu() {
    cout << "\n===== 创世干预 =====" << endl;
    cout << "1. 触发随机事件" << endl;
    cout << "2. 触发正面事件" << endl;
    cout << "3. 触发负面事件" << endl;
    cout << "0. 返回主菜单" << endl;
    cout << "请选择: ";
    
    int choice;
    cin >> choice;
    
    if (world->getAge() < 5 && !cheatMode) {
        cout << RED << "世界还太年轻,不宜进行过多干预。请等待创世第5天之后。" << RESET << endl;
        pause();
        return;
    }
    
    switch (choice) {
        case 1:
            world->randomEvent();
            world->setBalance(world->getBalance() - 10); // 干预会消耗平衡
            pause();
            break;
        case 2: {
            vector<Event*> positiveEvents;
            for (auto e : world->getEvents()) {
                if (e->getIsPositive()) {
                    positiveEvents.push_back(e);
                }
            }
            
            if (positiveEvents.empty()) {
                cout << RED << "没有可用的正面事件。" << RESET << endl;
                pause();
                break;
            }
            
            Event* selected = positiveEvents[randomInt(0, positiveEvents.size() - 1)];
            selected->trigger(world);
            world->setBalance(world->getBalance() - 15);
            pause();
            break;
        }
        case 3: {
            vector<Event*> negativeEvents;
            for (auto e : world->getEvents()) {
                if (!e->getIsPositive()) {
                    negativeEvents.push_back(e);
                }
            }
            
            if (negativeEvents.empty()) {
                cout << RED << "没有可用的负面事件。" << RESET << endl;
                pause();
                break;
            }
            
            Event* selected = negativeEvents[randomInt(0, negativeEvents.size() - 1)];
            selected->trigger(world);
            world->setBalance(world->getBalance() - 5);
            pause();
            break;
        }
        case 0:
            return;
        default:
            invalidChoice();
    }
}

// 实现Game类的cheatMenu方法
void Game::cheatMenu() {
    cout << "\n===== 作弊菜单 =====" << endl;
    cout << "1. 获得所有元素" << endl;
    cout << "2. 创造完美地形" << endl;
    cout << "3. 创造超级智慧生物" << endl;
    cout << "4. 直接创建高级文明" << endl;
    cout << "5. 平衡世界 (平衡度100)" << endl;
    cout << "0. 返回" << endl;
    cout << "请选择: ";
    
    int choice;
    cin >> choice;
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    
    switch (choice) {
        case 1: {
            vector<pair<string, string>> allElements = {
                {"土", "构成固体物质的基本元素"},
                {"水", "构成液体的基本元素"},
                {"火", "提供能量和热量的基本元素"},
                {"气", "构成气体的基本元素"},
                {"泥", "土和水混合形成的半固体"},
                {"石", "土被火加热形成的坚硬物质"},
                {"沙", "土被气流侵蚀形成的细小颗粒"},
                {"蒸汽", "水被火加热形成的气体"},
                {"云", "水与空气混合形成的漂浮物"},
                {"闪电", "火与气混合产生的电能"},
                {"陶", "泥土烧制而成的坚硬材料"},
                {"金属", "石头被高温熔炼出的金属"},
                {"冰", "水冷却形成的固态"},
                {"生命能量", "闪电击中水产生的神秘能量"},
                {"冷", "降低温度的元素"}
            };
            
            for (auto& p : allElements) {
                if (!world->findElement(p.first)) {
                    world->addElement(new Element(p.first, p.second, 50, 50, 
                                                p.first == "土" || p.first == "水" || 
                                                p.first == "火" || p.first == "气"));
                }
            }
            
            cout << GREEN << "已获得所有元素!" << RESET << endl;
            pause();
            break;
        }
        case 2: {
            cout << "请输入完美地形的名称: ";
            string name;
            getline(cin, name);
            
            if (name.empty()) name = "完美之地";
            
            int x = randomInt(-10, 10);
            int y = randomInt(-10, 10);
            
            Terrain* perfect = new Terrain(name, "完美地形", x, y, 100);
            perfect->setFertility(100);
            
            // 添加所有基本元素
            for (auto e : world->getElements()) {
                if (e->isBasicElement()) {
                    perfect->addElement(e);
                }
            }
            
            world->addTerrain(perfect);
            cout << GREEN << "已创建完美地形: " << name << RESET << endl;
            pause();
            break;
        }
        case 3: {
            if (world->getTerrains().empty()) {
                cout << RED << "先创建一些地形。" << RESET << endl;
                pause();
                break;
            }
            
            cout << "请输入超级智慧生物的名称: ";
            string name;
            getline(cin, name);
            
            if (name.empty()) name = "超级智慧体";
            
            Terrain* habitat = world->getTerrains()[0];
            Creature* super = new Creature(name, "超级智慧生物", habitat, 1000, 100, 100);
            
            // 添加所有元素作为需求
            for (auto e : world->getElements()) {
                super->addRequiredElement(e);
            }
            
            world->addCreature(super);
            cout << GREEN << "已创建超级智慧生物: " << name << RESET << endl;
            pause();
            break;
        }
        case 4: {
            if (world->getCreatures().empty()) {
                cout << RED << "先创建一些生物。" << RESET << endl;
                pause();
                break;
            }
            
            // 如果没有智慧生物,先创建一个
            Creature* founder = nullptr;
            for (auto c : world->getCreatures()) {
                if (c->getIsSentient()) {
                    founder = c;
                    break;
                }
            }
            
            if (!founder) {
                founder = world->getCreatures()[0];
                founder->increaseIntelligence(100);
            }
            
            cout << "请输入高级文明的名称: ";
            string name;
            getline(cin, name);
            
            if (name.empty()) name = "超级文明";
            
            Civilization* advanced = new Civilization(name, founder, founder->getHabitat());
            advanced->setTechnology(1000);
            advanced->setCulture(1000);
            advanced->setResources(10000);
            advanced->setStability(100);
            
            // 添加所有地形作为领土
            for (auto t : world->getTerrains()) {
                advanced->expand(t);
            }
            
            // 添加一些发明
            vector<string> inventions = {"太空旅行", "人工智能", "清洁能源", "基因编辑", "量子计算"};
            for (auto inv : inventions) {
                // 这里需要修改Civilization类才能实际添加,这里只是模拟
            }
            
            world->addCivilization(advanced);
            cout << GREEN << "已创建高级文明: " << name << RESET << endl;
            pause();
            break;
        }
        case 5:
            world->setBalance(100);
            cout << GREEN << "世界平衡度已设置为100!" << RESET << endl;
            pause();
            break;
        case 0:
            return;
        default:
            invalidChoice();
    }
}

int main() {
    // 设置中文字体支持
    setlocale(LC_ALL, "zh_CN.UTF-8");
    
    // 启动游戏
    Game game;
    game.run();
    
    return 0;
}
原文