跳到正文

休闲·娱乐

孤岛求生游戏

ycyzc14约 53 分钟
原文
文章信息与版本

文章信息

发布
2025年9月21日
收录
2025年12月12日
更新
2026年10月29日
篇幅
约 53 分钟

版本

  1. v2当前
  2. v1
C++
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>

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 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(time(0));
}

void show_status() {
    // 跨平台清屏处理
    #ifdef _WIN32
        system("cls");
    #else
        system("clear");
    #endif

    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 << "钻石斧 (耐久: 100) | ";  // 钻石斧
    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 << "钻石镐 (耐久: 100) | ";  // 钻石镐
    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;

    // 自动烹饪生鸟蛋
    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;
    }

    // 自动烹饪生鱼
    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;

    if (tools.diamond_axe > 0) {  // 钻石斧优先
        wood_gained *= 5;
        tools.diamond_axe--;
        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;

    // 钻石工具100%获得额外物品
    int rand_event;
    if (tools.diamond_axe > 0 || axe_used && tools.diamond_axe == 0) {
        rand_event = 0;  // 确保触发
    } else {
        rand_event = rand() % 100;
    }

    if (tools.diamond_axe > 0 || 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;
        system("pause");
        end_day();
        return;
    }
    system("pause");
}

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

    int stone_gained = 5;
    int pickaxe_used = 0;
    int ore_chance = 0;

    if (tools.diamond_pickaxe > 0) {  // 钻石镐优先
        stone_gained *= 4;
        tools.diamond_pickaxe--;
        pickaxe_used = 1;
        ore_chance = 100;  // 钻石镐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%概率获得钻石
    int diamond_chance = rand() % 100;
    if (diamond_chance < 5) {
        int diamonds_found = 2 + rand() % 2;  // 2或3颗钻石
        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 (tools.diamond_pickaxe > 0 || pickaxe_used && tools.diamond_pickaxe == 0) {
                    resources.iron += 5;
                    cout << "发现了 5 个铁矿!" << endl;
                } else {
                    resources.iron += 3;
                    cout << "发现了 3 个铁矿!" << endl;
                }
                break;
            case 1:
                if (tools.diamond_pickaxe > 0 || pickaxe_used && tools.diamond_pickaxe == 0) {
                    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;
        system("pause");
        end_day();
        return;
    }
    system("pause");
}

void fish() {
    if (tools.fishing_rod == 0) {
        cout << "你没有钓鱼竿,无法钓鱼!" << endl;
        system("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;
        system("pause");
        end_day();
        return;
    }
    system("pause");
}

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

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

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

void collect_seawater() {
    resources.sea_water += 20;
    cout << "收集了 20 单位海水!" << endl;
    game_state.actions_left--;
    if (game_state.actions_left == 0) {
        cout << "行动次数已用完,自动结束当天。" << endl;
        system("pause");
        end_day();
        return;
    }
    system("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()) {
            cin.clear();
            cin.ignore(10000, '\n');
            cout << "无效输入,请输入数字!" << endl;
            system("pause");
            continue;
        }

        if (choice == 1) {
            if (buildings.tent) {
                cout << "帐篷已建造,无法再次建造!" << endl;
                system("pause");
            } else if (resources.vine >= 10 && resources.wood >= 10) {
                resources.vine -= 10;
                resources.wood -= 10;
                buildings.tent = true;
                cout << "帐篷建造完成!" << endl;
                system("pause");
                break;
            } else {
                cout << "资源不足!" << endl;
                system("pause");
            }
        } else if (choice == 2) {
            if (buildings.wooden_house) {
                cout << "木屋已建造,无法再次建造!" << endl;
                system("pause");
            } else if (!buildings.tent) {
                cout << "需要先建造帐篷!" << endl;
                system("pause");
            } else if (resources.wood >= 100 && resources.stone >= 25) {
                resources.wood -= 100;
                resources.stone -= 25;
                buildings.wooden_house = true;
                cout << "木屋建造完成!" << endl;
                system("pause");
                break;
            } else {
                cout << "资源不足!" << endl;
                system("pause");
            }
        } else if (choice == 3) {
            if (buildings.water_purifier) {
                cout << "海水淡化器已建造,无法再次建造!" << endl;
                system("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;
                system("pause");
                break;
            } else {
                cout << "资源不足!" << endl;
                system("pause");
            }
        } else if (choice == 4) {
            if (buildings.big_ship) {
                cout << "大船已建造,无法再次建造!" << endl;
                system("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;
                system("pause");
                break;
            } else {
                cout << "资源不足!" << endl;
                system("pause");
            }
        } else if (choice == 5) {
            break;
        } else {
            cout << "无效选择,请重试!" << endl;
            system("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()) {
            cin.clear();
            cin.ignore(10000, '\n');
            cout << "无效输入,请输入数字!" << endl;
            system("pause");
            continue;
        }

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

    // 确保生命值不会低于0
    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;

    system("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()) {
            #ifdef _WIN32
                system("cls");
            #else
                system("clear");
            #endif
            cout << "你死了... 游戏结束。" << endl;
            cout << "你在孤岛上生存了 " << game_state.day << " 天。" << endl;
            break;
        }

        if (check_victory()) {
            #ifdef _WIN32
                system("cls");
            #else
                system("clear");
            #endif
            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()) {
            cin.clear();
            cin.ignore(10000, '\n');
            cout << "无效输入,请输入数字!" << endl;
            system("pause");
            continue;
        }

        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; system("pause");
        }
    }
    char byebye;
    cin>>byebye;
    return 0;
}
原文
抓取于
  1. ycyzc14

    棒极了!