孤岛求生游戏

· · 休闲·娱乐

《孤岛求生》游戏规则说明 一、游戏目标 你流落荒岛,需要活下来并造出大船逃离。

胜利条件(需同时满足):

已建造大船

储备能量 ≥ 1000

储备淡水 ≥ 1000

草药 ≥ 20

死亡条件(任一满足即结束):

生命值 ≤ 0

水分 ≤ 0

能量 ≤ 0

二、核心数值 属性 上限 每日消耗 说明 生命 100 视建筑而定 归零即死 水分 100 -40 归零即死 能量 100 -40 归零即死 储备淡水 无上限 — 自动补充水分 储备能量 无上限 — 自动补充能量 自动补充机制:每天结束时,若水分/能量不足 100,会自动从对应储备中扣除补满。储备不足则补到多少算多少。

三、每日流程 每天有 10 次行动机会,用完后自动结束当天

也可手动选择"结束当天"提前进入夜晚

夜晚结算顺序:

自动把食物转化为储备能量(含烤制)

自动把淡水转化为储备淡水

扣除水分 40、能量 40

自动补充水分和能量

海水淡化器工作(若已建造)

夜晚事件(血月 / 木屋 / 帐篷 / 无庇护)

进入新一天,行动次数重置为 10

四、资源说明 基础资源 木材:伐木获得

石料:采石获得

铁矿 / 煤矿:采石或伐木时有概率获得

钻石:采石有 5% 概率获得 2~3 颗

藤蔓:收集获得,用于建造和制作钓鱼竿

草药:收集藤蔓时有 50% 概率获得,可回血

食物与水 苹果:伐木/采石意外获得,每个 +5 能量

生鸟蛋:伐木/采石意外获得,每 5 个烤制后共 +50 能量

生鱼:钓鱼获得,每条烤制后 +50 能量

海水:收集获得,需海水淡化器转化为淡水

淡水:钓鱼意外获得,或海水淡化器产出

食物转化为能量对照 食物 能量 是否需要煤 苹果 +5/个 否 熟鸟蛋 +10/个 已烤好 烤鱼 +50/条 已烤好 生鸟蛋 5 个 +50 1 煤/5 个 生鱼 +50/条 1 煤/条 水转化对照 1 淡水 → 20 储备淡水

海水淡化器:每天消耗 10 海水 → 产 10 淡水

五、工具说明 所有工具都有耐久,每次使用 -1,耐久归零即损坏。

工具 制作材料 耐久 效果 木斧 5 木材 10 木材 ×2 石斧 2 木材 + 3 石料 30 木材 ×3 铁斧 2 木材 + 3 铁矿 50 木材 ×4 钻石斧 5 木材 + 3 钻石 100 木材 ×5,额外物品 100% 触发 木镐 5 木材 10 石料 ×1,矿石 10% 石镐 2 木材 + 3 石料 30 石料 ×2,矿石 10% 铁镐 2 木材 + 3 铁矿 50 石料 ×3,矿石 25% 钻石镐 5 木材 + 3 钻石 100 石料 ×4,矿石 100% 触发 钓鱼竿 5 木材 + 5 藤蔓 无限 可钓鱼 注意:钻石工具耐久耗尽后不会自动降级为其他工具,需要重新制作。

六、建造说明 建造不消耗行动次数,但需要材料。

建筑 材料 前置 效果 工作台 5 木材 无 解锁全部工具制作 帐篷 10 藤蔓 + 10 木材 无 夜晚不受野兽袭击 木屋 100 木材 + 25 石料 需帐篷 夜晚 +10 生命 海水淡化器 10 藤蔓 + 10 木材 + 10 石料 无 每天 10 海水 → 10 淡水 大船 500 木材 + 500 石料 + 200 藤蔓 无 胜利必要条件 注意:没有帐篷也没有木屋时,每晚会被野兽袭击,-50 生命。

七、制作说明 制作不消耗行动次数,但必须先造工作台。

未造工作台:只能制作工作台

已造工作台:可制作全部工具

制作出的工具耐久直接设为满值(不是叠加)

已有同类工具时再制作会覆盖,请注意

八、夜晚事件 情况 结果 血月之夜 -60 生命(无视建筑) 有木屋 +10 生命 只有帐篷 无伤 无庇护 -50 生命 血月规律:每 10 天一次(第 10、20、30…天),血月时木屋和帐篷都无效。

九、随机事件汇总 来源 概率 结果 伐木 20% 苹果×3 / 生蛋×5 / 煤×3 / 铁×2 伐木(钻石斧) 100% 同上 采石 5% 钻石×2~3 采石(矿石) 见工具表 铁/煤/苹果/生蛋 钓鱼 50%+递增 生鱼×5 钓鱼(额外) 20% 淡水×5 收集藤蔓 30% 草药×1 十、操作建议(新手向) 第一天:先伐木攒 5 木材 → 造工作台 → 造木斧

前两天:优先造帐篷,避免夜晚 -50 生命

中期:攒材料造木屋 + 海水淡化器,稳定回血和产水

煤很关键:烤鱼、烤蛋都要煤,采石/伐木时多留意

钻石优先做镐:钻石镐采石效率高、矿石 100% 触发,比钻石斧更实用

血月前:第 9 天尽量留够生命(≥60),否则血月会死

大船材料很多:500 木材 + 500 石料 + 200 藤蔓,尽早开始囤

草药留 20 个:是胜利条件之一,别全用来回血了

十一、胜负结算 游戏结束时显示:

死亡:你死了... 游戏结束。你在孤岛上生存了 X 天。

胜利:恭喜你! 你成功逃离了孤岛! 你在孤岛上生存了 X 天。

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <limits>

using namespace std;

void end_day();

struct Player {
    int health;
    int water;
    int energy;
};

struct Resources {
    int wood;
    int stone;
    int iron;
    int coal;
    int vine;
    int herb;
    int apple;
    int raw_egg;
    int cooked_egg;
    int raw_fish;
    int cooked_fish;
    int sea_water;
    int fresh_water;
    int diamond;
};

struct Tools {
    int wood_axe;
    int stone_axe;
    int iron_axe;
    int diamond_axe;
    int wood_pickaxe;
    int stone_pickaxe;
    int iron_pickaxe;
    int diamond_pickaxe;
    int fishing_rod;
};

struct Buildings {
    bool workbench;
    bool tent;
    bool wooden_house;
    bool water_purifier;
    bool big_ship;
};

struct GameState {
    int day;
    int actions_left;
    bool blood_moon;
    int stored_energy;
    int stored_water;
};

Player player;
Resources resources;
Tools tools;
Buildings buildings;
GameState game_state;

// ============ 跨平台工具函数 ============
void clear_input() {
    cin.clear();
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
}

void pause() {
    cout << "按回车键继续...";
    cin.get();
}

void clear_screen() {
    #ifdef _WIN32
        system("cls");
    #else
        system("clear");
    #endif
}

// ============ 初始化 ============
void init_game() {
    player.health = 100;
    player.water = 100;
    player.energy = 100;

    resources.wood = 0;
    resources.stone = 0;
    resources.iron = 0;
    resources.coal = 0;
    resources.vine = 0;
    resources.herb = 0;
    resources.apple = 0;
    resources.raw_egg = 0;
    resources.cooked_egg = 0;
    resources.raw_fish = 0;
    resources.cooked_fish = 0;
    resources.sea_water = 0;
    resources.fresh_water = 0;
    resources.diamond = 0;

    tools.wood_axe = 0;
    tools.stone_axe = 0;
    tools.iron_axe = 0;
    tools.diamond_axe = 0;
    tools.wood_pickaxe = 0;
    tools.stone_pickaxe = 0;
    tools.iron_pickaxe = 0;
    tools.diamond_pickaxe = 0;
    tools.fishing_rod = 0;

    buildings.workbench = false;
    buildings.tent = false;
    buildings.wooden_house = false;
    buildings.water_purifier = false;
    buildings.big_ship = false;

    game_state.day = 1;
    game_state.actions_left = 10;
    game_state.blood_moon = false;
    game_state.stored_energy = 0;
    game_state.stored_water = 0;

    srand((unsigned)time(0));
}

// ============ 状态显示 ============
void show_status() {
    clear_screen();

    cout << "=== 孤岛求生 ===" << endl;
    cout << "第 " << game_state.day << " 天 | 剩余行动: " << game_state.actions_left << endl;
    if (game_state.blood_moon) cout << "! 血月之夜 !" << endl;
    cout << "-----------------" << endl;
    cout << "状态: 生命 " << player.health << " | 水分 " << player.water << "% | 能量 " << player.energy << "%" << endl;
    cout << "储备: 能量 " << game_state.stored_energy << "% | 淡水 " << game_state.stored_water << "%" << endl;
    cout << "-----------------" << endl;
    cout << "资源:" << endl;
    cout << "木材: " << resources.wood << " | 石料: " << resources.stone << " | 铁矿: " << resources.iron << endl;
    cout << "煤矿: " << resources.coal << " | 藤蔓: " << resources.vine << " | 草药: " << resources.herb << endl;
    cout << "钻石: " << resources.diamond << endl;
    cout << "-----------------" << endl;
    cout << "食物资源:" << endl;
    cout << "苹果: " << resources.apple << " | 生鸟蛋: " << resources.raw_egg << " | 熟鸟蛋: " << resources.cooked_egg << endl;
    cout << "生鱼: " << resources.raw_fish << " | 烤鱼: " << resources.cooked_fish << endl;
    cout << "-----------------" << endl;
    cout << "水: 淡水 " << resources.fresh_water << " | 海水 " << resources.sea_water << endl;
    cout << "-----------------" << endl;
    cout << "工具:" << endl;
    if (tools.wood_axe > 0)     cout << "木斧 (耐久: " << tools.wood_axe << ") | ";
    if (tools.stone_axe > 0)    cout << "石斧 (耐久: " << tools.stone_axe << ") | ";
    if (tools.iron_axe > 0)     cout << "铁斧 (耐久: " << tools.iron_axe << ") | ";
    if (tools.diamond_axe > 0)  cout << "钻石斧 (耐久: " << tools.diamond_axe << ") | ";
    cout << endl;
    if (tools.wood_pickaxe > 0)    cout << "木镐 (耐久: " << tools.wood_pickaxe << ") | ";
    if (tools.stone_pickaxe > 0)   cout << "石镐 (耐久: " << tools.stone_pickaxe << ") | ";
    if (tools.iron_pickaxe > 0)    cout << "铁镐 (耐久: " << tools.iron_pickaxe << ") | ";
    if (tools.diamond_pickaxe > 0) cout << "钻石镐 (耐久: " << tools.diamond_pickaxe << ") | ";
    cout << endl;
    if (tools.fishing_rod > 0) cout << "钓鱼竿" << endl;
    cout << "-----------------" << endl;
    cout << "建筑:" << endl;
    if (buildings.workbench)     cout << "工作台 | ";
    if (buildings.tent)          cout << "帐篷 | ";
    if (buildings.wooden_house)  cout << "木屋 | ";
    if (buildings.water_purifier)cout << "海水淡化器 | ";
    if (buildings.big_ship)      cout << "大船 | ";
    cout << endl;
    cout << "-----------------" << endl;
}

// ============ 自动转化与补充 ============
void convert_food_to_energy() {
    int converted = 0;

    converted += resources.apple * 5;
    resources.apple = 0;

    converted += resources.cooked_egg * 10;
    resources.cooked_egg = 0;

    converted += resources.cooked_fish * 50;
    resources.cooked_fish = 0;

    // 自动烹饪生鸟蛋(每5个消耗1煤)
    int egg_batches = resources.raw_egg / 5;
    if (egg_batches > 0 && resources.coal >= egg_batches) {
        converted += egg_batches * 5 * 10;
        resources.raw_egg -= egg_batches * 5;
        resources.coal -= egg_batches;
    }

    // 自动烹饪生鱼(每条消耗1煤)
    if (resources.raw_fish > 0 && resources.coal >= resources.raw_fish) {
        converted += resources.raw_fish * 50;
        resources.coal -= resources.raw_fish;
        resources.raw_fish = 0;
    }

    game_state.stored_energy += converted;
}

void convert_water_to_stored() {
    game_state.stored_water += resources.fresh_water * 20;
    resources.fresh_water = 0;
}

void auto_refresh() {
    int water_needed = 100 - player.water;
    if (water_needed > 0) {
        if (game_state.stored_water >= water_needed) {
            game_state.stored_water -= water_needed;
            player.water = 100;
        } else {
            player.water += game_state.stored_water;
            game_state.stored_water = 0;
        }
    }

    int energy_needed = 100 - player.energy;
    if (energy_needed > 0) {
        if (game_state.stored_energy >= energy_needed) {
            game_state.stored_energy -= energy_needed;
            player.energy = 100;
        } else {
            player.energy += game_state.stored_energy;
            game_state.stored_energy = 0;
        }
    }
}

// ============ 行动 ============
void chop_wood() {
    int wood_gained = 10;
    int axe_used = 0;
    bool used_diamond_axe = false;   // 修复1:标识是否使用钻石斧

    if (tools.diamond_axe > 0) {
        wood_gained *= 5;
        tools.diamond_axe--;
        used_diamond_axe = true;
        axe_used = 1;
    } else if (tools.iron_axe > 0) {
        wood_gained *= 4;
        tools.iron_axe--;
        axe_used = 1;
    } else if (tools.stone_axe > 0) {
        wood_gained *= 3;
        tools.stone_axe--;
        axe_used = 1;
    } else if (tools.wood_axe > 0) {
        wood_gained *= 2;
        tools.wood_axe--;
        axe_used = 1;
    }

    resources.wood += wood_gained;
    cout << "获得了 " << wood_gained << " 木材!" << endl;

    // 修复1:只有钻石斧100%触发,普通斧头20%概率
    int rand_event = rand() % 100;
    if (used_diamond_axe || rand_event < 20) {
        int rand_item = rand() % 4;
        switch(rand_item) {
            case 0: resources.apple += 3;  cout << "意外发现了 3 个苹果!" << endl; break;
            case 1: resources.raw_egg += 5;cout << "意外发现了 5 个生鸟蛋!" << endl; break;
            case 2: resources.coal += 3;   cout << "意外发现了 3 个煤矿!" << endl; break;
            case 3: resources.iron += 2;   cout << "意外发现了 2 个铁矿!" << endl; break;
        }
    }

    if (axe_used && tools.wood_axe == 0 && tools.stone_axe == 0 &&
        tools.iron_axe == 0 && tools.diamond_axe == 0) {
        cout << "你的斧头坏了!" << endl;
    }

    game_state.actions_left--;
    if (game_state.actions_left == 0) {
        cout << "行动次数已用完,自动结束当天。" << endl;
        end_day();
        return;
    }
    pause();
}

void mine_stone() {
    if (tools.wood_pickaxe == 0 && tools.stone_pickaxe == 0 &&
        tools.iron_pickaxe == 0 && tools.diamond_pickaxe == 0) {
        cout << "你没有镐子,无法采石!" << endl;
        pause();
        return;
    }

    int stone_gained = 5;
    int pickaxe_used = 0;
    int ore_chance = 0;
    bool used_diamond_pickaxe = false;   // 修复2:标识是否使用钻石镐

    if (tools.diamond_pickaxe > 0) {
        stone_gained *= 4;
        tools.diamond_pickaxe--;
        used_diamond_pickaxe = true;
        pickaxe_used = 1;
        ore_chance = 100;
    } else if (tools.iron_pickaxe > 0) {
        stone_gained *= 3;
        tools.iron_pickaxe--;
        pickaxe_used = 1;
        ore_chance = 25;
    } else if (tools.stone_pickaxe > 0) {
        stone_gained *= 2;
        tools.stone_pickaxe--;
        pickaxe_used = 1;
        ore_chance = 10;
    } else if (tools.wood_pickaxe > 0) {
        tools.wood_pickaxe--;
        pickaxe_used = 1;
        ore_chance = 10;
    }

    resources.stone += stone_gained;
    cout << "获得了 " << stone_gained << " 石料!" << endl;

    // 5%概率获得钻石(与镐无关)
    if (rand() % 100 < 5) {
        int diamonds_found = 2 + rand() % 2;
        resources.diamond += diamonds_found;
        cout << "恭喜! 发现了 " << diamonds_found << " 颗钻石!" << endl;
    }

    int rand_event = rand() % 100;
    if (rand_event < ore_chance) {
        int rand_ore = rand() % 4;
        switch(rand_ore) {
            case 0:
                if (used_diamond_pickaxe) { resources.iron += 5; cout << "发现了 5 个铁矿!" << endl; }
                else                      { resources.iron += 3; cout << "发现了 3 个铁矿!" << endl; }
                break;
            case 1:
                if (used_diamond_pickaxe) { resources.coal += 8; cout << "发现了 8 个煤矿!" << endl; }
                else                      { resources.coal += 5; cout << "发现了 5 个煤矿!" << endl; }
                break;
            case 2: resources.apple += 3;  cout << "意外发现了 3 个苹果!" << endl; break;
            case 3: resources.raw_egg += 5;cout << "意外发现了 5 个生鸟蛋!" << endl; break;
        }
    }

    if (pickaxe_used && tools.wood_pickaxe == 0 && tools.stone_pickaxe == 0 &&
        tools.iron_pickaxe == 0 && tools.diamond_pickaxe == 0) {
        cout << "你的镐子坏了!" << endl;
    }

    game_state.actions_left--;
    if (game_state.actions_left == 0) {
        cout << "行动次数已用完,自动结束当天。" << endl;
        end_day();
        return;
    }
    pause();
}

void fish() {
    if (tools.fishing_rod == 0) {
        cout << "你没有钓鱼竿,无法钓鱼!" << endl;
        pause();
        return;
    }

    static int fish_count = 0;
    int success_chance = 50 + fish_count;
    if (success_chance > 100) success_chance = 100;

    int rand_event = rand() % 100;
    if (rand_event < success_chance) {
        resources.raw_fish += 5;
        cout << "成功钓到了 5 条鱼!" << endl;
    } else {
        cout << "钓鱼失败了!" << endl;
    }

    if (rand_event < 20) {
        resources.fresh_water += 5;
        cout << "意外获得了 5 单位水!" << endl;
    }

    fish_count++;
    game_state.actions_left--;
    if (game_state.actions_left == 0) {
        cout << "行动次数已用完,自动结束当天。" << endl;
        end_day();
        return;
    }
    pause();
}

void collect_vine() {
    resources.vine += 20;
    cout << "收集到了 20 个藤蔓!" << endl;

    int rand_event = rand() % 100;
    if (rand_event < 50) {
        resources.herb += 1;
        cout << "意外发现了 1 个草药!" << endl;
    }

    game_state.actions_left--;
    if (game_state.actions_left == 0) {
        cout << "行动次数已用完,自动结束当天。" << endl;
        end_day();
        return;
    }
    pause();
}

void collect_seawater() {
    resources.sea_water += 20;
    cout << "收集了 20 单位海水!" << endl;

    game_state.actions_left--;
    if (game_state.actions_left == 0) {
        cout << "行动次数已用完,自动结束当天。" << endl;
        end_day();
        return;
    }
    pause();
}

// ============ 建造菜单 ============
void build_menu() {
    int choice;
    while (true) {
        show_status();
        cout << "建造菜单:" << endl;
        cout << "1. 帐篷 (" << (buildings.tent ? "已建造" : (resources.vine >= 10 && resources.wood >= 10 ? "可建造" : "10藤蔓, 10木材")) << ")" << endl;
        cout << "2. 木屋 (" << (buildings.wooden_house ? "已建造" : (buildings.tent && resources.wood >= 100 && resources.stone >= 25 ? "可建造" : "需要帐篷, 100木材, 25石料")) << ")" << endl;
        cout << "3. 海水淡化器 (" << (buildings.water_purifier ? "已建造" : (resources.vine >= 10 && resources.wood >= 10 && resources.stone >= 10 ? "可建造" : "10藤蔓, 10木材, 10石料")) << ")" << endl;
        cout << "4. 大船 (" << (buildings.big_ship ? "已建造" : (resources.wood >= 500 && resources.stone >= 500 && resources.vine >= 200 ? "可建造" : "500木材, 500石料, 200藤蔓")) << ")" << endl;
        cout << "5. 返回" << endl;
        cout << "选择: ";
        cin >> choice;

        if (cin.fail()) {
            clear_input();
            cout << "无效输入,请输入数字!" << endl;
            pause();
            continue;
        }
        clear_input();

        if (choice == 1) {
            if (buildings.tent) {
                cout << "帐篷已建造,无法再次建造!" << endl;
                pause();
            } else if (resources.vine >= 10 && resources.wood >= 10) {
                resources.vine -= 10;
                resources.wood -= 10;
                buildings.tent = true;
                cout << "帐篷建造完成!" << endl;
                pause();
                break;
            } else {
                cout << "资源不足!" << endl;
                pause();
            }
        } else if (choice == 2) {
            if (buildings.wooden_house) {
                cout << "木屋已建造,无法再次建造!" << endl;
                pause();
            } else if (!buildings.tent) {
                cout << "需要先建造帐篷!" << endl;
                pause();
            } else if (resources.wood >= 100 && resources.stone >= 25) {
                resources.wood -= 100;
                resources.stone -= 25;
                buildings.wooden_house = true;
                cout << "木屋建造完成!" << endl;
                pause();
                break;
            } else {
                cout << "资源不足!" << endl;
                pause();
            }
        } else if (choice == 3) {
            if (buildings.water_purifier) {
                cout << "海水淡化器已建造,无法再次建造!" << endl;
                pause();
            } else if (resources.vine >= 10 && resources.wood >= 10 && resources.stone >= 10) {
                resources.vine -= 10;
                resources.wood -= 10;
                resources.stone -= 10;
                buildings.water_purifier = true;
                cout << "海水淡化器建造完成!" << endl;
                pause();
                break;
            } else {
                cout << "资源不足!" << endl;
                pause();
            }
        } else if (choice == 4) {
            if (buildings.big_ship) {
                cout << "大船已建造,无法再次建造!" << endl;
                pause();
            } else if (resources.wood >= 500 && resources.stone >= 500 && resources.vine >= 200) {
                resources.wood -= 500;
                resources.stone -= 500;
                resources.vine -= 200;
                buildings.big_ship = true;
                cout << "大船建造完成!" << endl;
                pause();
                break;
            } else {
                cout << "资源不足!" << endl;
                pause();
            }
        } else if (choice == 5) {
            break;
        } else {
            cout << "无效选择,请重试!" << endl;
            pause();
        }
    }
}

// ============ 制作菜单 ============
void craft_menu() {
    int choice;
    while (true) {
        show_status();
        cout << "制作菜单:" << endl;
        if (!buildings.workbench) {
            cout << "1. 工作台 (" << (resources.wood >= 5 ? "可制作" : "5木材") << ")" << endl;
            cout << "2. 返回" << endl;
        } else {
            cout << "1. 木斧 (" << (resources.wood >= 5 ? "可制作" : "5木材") << ") 耐久10" << endl;
            cout << "2. 木镐 (" << (resources.wood >= 5 ? "可制作" : "5木材") << ") 耐久10" << endl;
            cout << "3. 石斧 (" << (resources.wood >= 2 && resources.stone >= 3 ? "可制作" : "2木材, 3石料") << ") 耐久30" << endl;
            cout << "4. 石镐 (" << (resources.wood >= 2 && resources.stone >= 3 ? "可制作" : "2木材, 3石料") << ") 耐久30" << endl;
            cout << "5. 铁斧 (" << (resources.wood >= 2 && resources.iron >= 3 ? "可制作" : "2木材, 3铁矿") << ") 耐久50" << endl;
            cout << "6. 铁镐 (" << (resources.wood >= 2 && resources.iron >= 3 ? "可制作" : "2木材, 3铁矿") << ") 耐久50" << endl;
            cout << "7. 钻石斧 (" << (resources.wood >= 5 && resources.diamond >= 3 ? "可制作" : "5木材, 3钻石") << ") 耐久100" << endl;
            cout << "8. 钻石镐 (" << (resources.wood >= 5 && resources.diamond >= 3 ? "可制作" : "5木材, 3钻石") << ") 耐久100" << endl;
            cout << "9. 钓鱼竿 (" << (resources.wood >= 5 && resources.vine >= 5 ? "可制作" : "5木材, 5藤蔓") << ")" << endl;
            cout << "10. 返回" << endl;
        }
        cout << "选择: ";
        cin >> choice;

        if (cin.fail()) {
            clear_input();
            cout << "无效输入,请输入数字!" << endl;
            pause();
            continue;
        }
        clear_input();

        if (!buildings.workbench) {
            if (choice == 1) {
                if (resources.wood >= 5) {
                    resources.wood -= 5;
                    buildings.workbench = true;
                    cout << "工作台制作完成!" << endl;
                    pause();
                    break;
                } else {
                    cout << "资源不足!" << endl;
                    pause();
                }
            } else if (choice == 2) {
                break;
            } else {
                cout << "无效选择,请重试!" << endl;
                pause();
            }
        } else {
            if (choice == 1) {
                if (resources.wood >= 5) {
                    resources.wood -= 5;
                    tools.wood_axe = 10;
                    cout << "木斧制作完成!" << endl;
                    pause(); break;
                } else { cout << "资源不足!" << endl; pause(); }
            } else if (choice == 2) {
                if (resources.wood >= 5) {
                    resources.wood -= 5;
                    tools.wood_pickaxe = 10;
                    cout << "木镐制作完成!" << endl;
                    pause(); break;
                } else { cout << "资源不足!" << endl; pause(); }
            } else if (choice == 3) {
                if (resources.wood >= 2 && resources.stone >= 3) {
                    resources.wood -= 2; resources.stone -= 3;
                    tools.stone_axe = 30;
                    cout << "石斧制作完成!" << endl;
                    pause(); break;
                } else { cout << "资源不足!" << endl; pause(); }
            } else if (choice == 4) {
                if (resources.wood >= 2 && resources.stone >= 3) {
                    resources.wood -= 2; resources.stone -= 3;
                    tools.stone_pickaxe = 30;
                    cout << "石镐制作完成!" << endl;
                    pause(); break;
                } else { cout << "资源不足!" << endl; pause(); }
            } else if (choice == 5) {
                if (resources.wood >= 2 && resources.iron >= 3) {
                    resources.wood -= 2; resources.iron -= 3;
                    tools.iron_axe = 50;
                    cout << "铁斧制作完成!" << endl;
                    pause(); break;
                } else { cout << "资源不足!" << endl; pause(); }
            } else if (choice == 6) {
                if (resources.wood >= 2 && resources.iron >= 3) {
                    resources.wood -= 2; resources.iron -= 3;
                    tools.iron_pickaxe = 50;
                    cout << "铁镐制作完成!" << endl;
                    pause(); break;
                } else { cout << "资源不足!" << endl; pause(); }
            } else if (choice == 7) {
                if (resources.wood >= 5 && resources.diamond >= 3) {
                    resources.wood -= 5; resources.diamond -= 3;
                    tools.diamond_axe = 100;
                    cout << "钻石斧制作完成!" << endl;
                    pause(); break;
                } else { cout << "资源不足!" << endl; pause(); }
            } else if (choice == 8) {
                if (resources.wood >= 5 && resources.diamond >= 3) {
                    resources.wood -= 5; resources.diamond -= 3;
                    tools.diamond_pickaxe = 100;
                    cout << "钻石镐制作完成!" << endl;
                    pause(); break;
                } else { cout << "资源不足!" << endl; pause(); }
            } else if (choice == 9) {
                if (resources.wood >= 5 && resources.vine >= 5) {
                    resources.wood -= 5; resources.vine -= 5;
                    tools.fishing_rod = 1;
                    cout << "钓鱼竿制作完成!" << endl;
                    pause(); break;
                } else { cout << "资源不足!" << endl; pause(); }
            } else if (choice == 10) {
                break;
            } else {
                cout << "无效选择,请重试!" << endl;
                pause();
            }
        }
    }
}

// ============ 使用草药 ============
void use_herb() {
    if (resources.herb > 0) {
        resources.herb--;
        player.health += 10;
        if (player.health > 100) player.health = 100;
        cout << "你使用了草药,生命值恢复了10点!" << endl;
    } else {
        cout << "没有草药了!" << endl;
    }
    pause();
}

// ============ 结束一天 ============
void end_day() {
    cout << "一天结束了..." << endl;

    convert_food_to_energy();
    convert_water_to_stored();

    player.water -= 40;
    player.energy -= 40;

    auto_refresh();

    if (player.water < 0) player.water = 0;
    if (player.energy < 0) player.energy = 0;

    if (buildings.water_purifier && resources.sea_water >= 10) {
        resources.sea_water -= 10;
        resources.fresh_water += 10;
        cout << "海水淡化器工作了一天,产生了10单位淡水!" << endl;
    }

    if (game_state.blood_moon) {
        cout << "血月之夜,你无法入眠,受到了60点伤害!" << endl;
        player.health -= 60;
    } else {
        if (buildings.wooden_house) {
            cout << "你在木屋里安全地度过了一夜,生命值恢复了10点!" << endl;
            player.health += 10;
            if (player.health > 100) player.health = 100;
        } else if (buildings.tent) {
            cout << "你在帐篷里安全地度过了一夜!" << endl;
        } else {
            cout << "你晚上受到了野兽袭击,生命值减少了50点!" << endl;
            player.health -= 50;
        }
    }

    if (player.health < 0) player.health = 0;

    game_state.day++;
    game_state.actions_left = 10;
    game_state.blood_moon = (game_state.day % 10 == 0);

    cout << "新的一天开始了! 这是第 " << game_state.day << " 天" << endl;
    if (game_state.blood_moon) cout << "今晚将是血月之夜!" << endl;

    pause();
}

// ============ 胜负判定 ============
bool check_victory() {
    if (!buildings.big_ship) return false;
    if (game_state.stored_energy >= 1000 && game_state.stored_water >= 1000 && resources.herb >= 20) {
        return true;
    }
    return false;
}

bool check_death() {
    return player.health <= 0 || player.water <= 0 || player.energy <= 0;
}

// ============ 主函数 ============
int main() {
    init_game();
    int choice;

    while (true) {
        if (check_death()) {
            clear_screen();
            cout << "你死了... 游戏结束。" << endl;
            cout << "你在孤岛上生存了 " << game_state.day << " 天。" << endl;
            break;
        }

        if (check_victory()) {
            clear_screen();
            cout << "恭喜你! 你成功逃离了孤岛!" << endl;
            cout << "你在孤岛上生存了 " << game_state.day << " 天。" << endl;
            break;
        }

        show_status();
        cout << "行动菜单:" << endl;
        cout << "1. 伐木" << endl;
        cout << "2. 采石" << endl;
        cout << "3. 钓鱼" << endl;
        cout << "4. 收集藤蔓" << endl;
        cout << "5. 收集海水" << endl;
        cout << "6. 建造" << endl;
        cout << "7. 制作" << endl;
        cout << "8. 使用草药" << endl;
        cout << "9. 结束当天" << endl;
        cout << "选择: ";
        cin >> choice;

        if (cin.fail()) {
            clear_input();
            cout << "无效输入,请输入数字!" << endl;
            pause();
            continue;
        }
        clear_input();

        switch (choice) {
            case 1: chop_wood(); break;
            case 2: mine_stone(); break;
            case 3: fish(); break;
            case 4: collect_vine(); break;
            case 5: collect_seawater(); break;
            case 6: build_menu(); break;
            case 7: craft_menu(); break;
            case 8: use_herb(); break;
            case 9: end_day(); break;
            default:
                cout << "无效的选择!" << endl;
                pause();
        }
    }

    pause();
    return 0;
}