跳到正文

剪贴板

剪贴板 s8vyhjqt

原文
剪贴板信息

剪贴板信息

收录
更新
C++
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <random>
#include <ctime>
#include <algorithm>
#include <limits>
#include <thread>
#include <chrono>
#include <fstream>
#include <windows.h>
//特别鸣谢:98 
// -------------------- 跨平台暂停函数 --------------------
void pauseForSeconds(int seconds) {
    std::this_thread::sleep_for(std::chrono::seconds(seconds));
}

// -------------------- 清屏函数 --------------------
void clearScreen() {
#ifdef _WIN32
    system("cls");
#else
    system("clear");
#endif
}

// -------------------- 全局随机数生成器 --------------------
std::mt19937 rng(static_cast<unsigned>(std::time(nullptr)));

int randomInt(int min, int max) {
    return std::uniform_int_distribution<int>(min, max)(rng);
}

bool randomChance(double probability) {
    return std::uniform_real_distribution<double>(0.0, 1.0)(rng) < probability;
}

// -------------------- 玩家状态结构体 --------------------
struct Player {
    // 石像系统
    bool hasStatue = false;
    bool blueprintStatue = true;        // 初始拥有蓝图
    int permanentMultiplier = 1;        // 永久倍率,上限10000
    bool prayedMorning = false;
    bool prayedNoon = false;
    bool prayedNight = false;

    bool hasCampfire = false;           // 永久篝火
    int cookedFish = 0;                 // 烤鱼数量
    bool blueprintCampfire = false;     // 篝火蓝图

    // 核心属性
    int waterCollectorCount = 0;
    std::vector<int> waterCollectorTimers;
    int chests = 0;
    int keys = 0;
    int satiety = 5;
    int water = 5;
    // 资源
    int food = 3;
    int waterBottles = 3;
    int emptyBottles = 0;
    int medicine = 3;
    int expiredMeds = 0;
    // 材料
    int leaves = 0;
    int sticks = 0;
    int stones = 0;
    int rope = 0;
    int cloth = 0;
    int nails = 0;
    int fish = 0;
    int coconuts = 0;
    int coconutJuice = 0;
    // 工具/装备
    bool hasStoneSpear = false;
    bool hasPickaxe = false;
    bool hasStoneAxe = false;
    bool hasStoneSword = false;
    bool hasShoes = false;
    bool hasWaterCollector = false;
    int waterCollectorTimer = 0;
    bool hasFishingRod = false;
    bool hasSlingshot = false;
    int boatPaddlesCount = 0;
    // 蓝图
    bool blueprintSpear = false;
    bool blueprintPickaxe = false;
    bool blueprintAxe = false;
    bool blueprintSword = false;
    bool blueprintShoes = false;
    bool blueprintWaterCollector = false;
    bool blueprintNail = false;
    bool blueprintBoat = false;
    bool blueprintPaddles = false;
    bool blueprintFishingRod = false;
    bool blueprintSlingshot = false;
    // 房屋
    int houseLevel = 0;
    int houseHP = 0;
    // 状态
    bool hasPoison = false;
    bool hasCold = false;
    bool canActMorning = true;
    int day = 1;
    int exp = 0;
    int level = 0;
    bool gameOver = false;
    bool gameWin = false;
    // 夜间摘要
    std::string nightSummary = "";

    void addExp(int gain) {
        exp += gain;
        while (true) {
            int need;
            if (level == 0) need = 1000;
            else if (level == 1) need = 2000;
            else need = 1000 + level * 1000;
            if (exp >= need) {
                exp -= need;
                level++;
            } else break;
        }
    }
};

// -------------------- 存档(未修改,保持不变) --------------------
void save(Player& p, bool type = 1) {
    std::ofstream fout;
    const std::string savePath = "C:\\Program Files (x86)\\Dev-Cpp\\LOG.txt"; // 保留原有路径(或可改为相对路径)
    fout.open(savePath, std::ios::out);
    if (!type) {
        fout.close();
        if (remove(savePath.c_str()) == 0)
            std::cout << "删除成功!\n";
        else
            std::cout << "删除失败!\n";
        return;
    }
    std::cout << "存档中...\n";
    // 集水器数据
    fout << p.waterCollectorCount << ' ';
    for (auto x : p.waterCollectorTimers) fout << x << ' ';
    fout << std::endl;
    fout << std::endl;  // 留空行分隔

    // 基础资源
    fout << p.chests << ' ' << p.keys << ' ' << p.satiety << ' ' << p.water << std::endl;
    fout << p.food << ' ' << p.waterBottles << ' ' << p.emptyBottles << ' ' << p.medicine << ' ' << p.expiredMeds << std::endl;
    fout << p.leaves << ' ' << p.sticks << ' ' << p.stones << ' ' << p.rope << ' ' << p.cloth << ' ' << p.nails << ' ' << p.fish << ' ' << p.cookedFish << ' ' << p.coconuts << ' ' << p.coconutJuice << std::endl;

    // 工具/装备(包含篝火)
    fout << p.hasStoneSpear << ' ' << p.hasPickaxe << ' ' << p.hasStoneAxe << ' ' << p.hasStoneSword << ' ' << p.hasShoes << ' ' << p.hasFishingRod << ' ' << p.hasSlingshot << ' ' << p.hasCampfire << ' ' << p.boatPaddlesCount << std::endl;

    // 蓝图(包含篝火,石像蓝图初始拥有无需存)
    fout << p.blueprintSpear << ' ' << p.blueprintPickaxe << ' ' << p.blueprintAxe << ' ' << p.blueprintSword << ' ' << p.blueprintShoes << ' ' << p.blueprintWaterCollector << ' ' << p.blueprintNail << ' ' << p.blueprintBoat << ' ' << p.blueprintPaddles << ' ' << p.blueprintFishingRod << ' ' << p.blueprintSlingshot << ' ' << p.blueprintCampfire << std::endl;

    // 房屋
    fout << p.houseLevel << ' ' << p.houseHP << std::endl;

    // 状态
    fout << p.hasPoison << ' ' << p.hasCold << ' ' << p.canActMorning << std::endl;

    // 日期经验等级
    fout << p.day << ' ' << p.exp << ' ' << p.level << std::endl;

    // ===== 新增石像系统数据 =====
    fout << p.hasStatue << ' ' << p.blueprintStatue << ' ' << p.permanentMultiplier << ' ';
    fout << p.prayedMorning << ' ' << p.prayedNoon << ' ' << p.prayedNight << std::endl;

    fout.close();
    pauseForSeconds(2);
    std::cout << "存档成功!\n";
}

bool load(Player& p) {
    std::cout << "加载中...\n";
    std::ifstream fin;
    const std::string savePath = "C:\\Program Files (x86)\\Dev-Cpp\\LOG.txt";
    fin.open(savePath, std::ios::in);
    if (!fin || !fin.is_open()) {
        pauseForSeconds(2);
        std::cout << "存档不存在或损坏!\n";
        pauseForSeconds(2);
        return false;
    } else {
        fin.seekg(0, std::ios::end);
        auto sz = fin.tellg();
        fin.seekg(0, std::ios::beg);
        if (sz == 0) {
            pauseForSeconds(2);
            std::cout << "存档为空!\n";
            pauseForSeconds(2);
            return false;
        }
        // 读取集水器
        fin >> p.waterCollectorCount;
        p.waterCollectorTimers.clear();
        for (int i = 0; i < p.waterCollectorCount; i++) {
            int x;
            fin >> x;
            p.waterCollectorTimers.push_back(x);
        }

        // 读取基础资源
        fin >> p.chests >> p.keys >> p.satiety >> p.water;
        fin >> p.food >> p.waterBottles >> p.emptyBottles >> p.medicine >> p.expiredMeds;
        fin >> p.leaves >> p.sticks >> p.stones >> p.rope >> p.cloth >> p.nails >> p.fish >> p.cookedFish >> p.coconuts >> p.coconutJuice;

        // 工具
        fin >> p.hasStoneSpear >> p.hasPickaxe >> p.hasStoneAxe >> p.hasStoneSword >> p.hasShoes >> p.hasFishingRod >> p.hasSlingshot >> p.hasCampfire >> p.boatPaddlesCount;

        // 蓝图
        fin >> p.blueprintSpear >> p.blueprintPickaxe >> p.blueprintAxe >> p.blueprintSword >> p.blueprintShoes >> p.blueprintWaterCollector >> p.blueprintNail >> p.blueprintBoat >> p.blueprintPaddles >> p.blueprintFishingRod >> p.blueprintSlingshot >> p.blueprintCampfire;

        // 房屋
        fin >> p.houseLevel >> p.houseHP;

        // 状态
        fin >> p.hasPoison >> p.hasCold >> p.canActMorning;

        // 日期经验等级
        fin >> p.day >> p.exp >> p.level;

        // ===== 读取石像系统数据 =====
        fin >> p.hasStatue >> p.blueprintStatue >> p.permanentMultiplier;
        fin >> p.prayedMorning >> p.prayedNoon >> p.prayedNight;

        // 如果读取失败,说明旧存档无此数据,则设置默认值
        if (fin.fail()) {
            p.hasStatue = false;
            p.blueprintStatue = true;
            p.permanentMultiplier = 1;
            p.prayedMorning = p.prayedNoon = p.prayedNight = false;
            fin.clear(); // 清除错误状态
        }
    }
    fin.close();
    pauseForSeconds(2);
    std::cout << "加载成功!\n";
    pauseForSeconds(2);
    return true;
}

// -------------------- 辅助函数 --------------------
bool canCollectStones(const Player& p) { return p.level >= 1; }
bool canFish(const Player& p) { return p.level >= 2; }

void getCollectBounds(int level, int baseMin, int baseMax, int& outMin, int& outMax) {
    int bonus = level;
    outMin = baseMin + bonus;
    outMax = baseMax + bonus;
}

// 前置声明
void displayStatus(Player& p);
bool checkDeath(Player& p);
bool checkWin(Player& p);

// -------------------- 核心操作函数 --------------------
void eat(Player& p) {
    if (p.food <= 0) {
        std::cout << "没有食物可吃!\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    p.food--;
    p.satiety = std::min(5, p.satiety + 2);
    std::cout << "你吃了一份食物,饱食度 +2(当前 " << p.satiety << ")。\n";
    pauseForSeconds(2);
    displayStatus(p);
}

void drinkWater(Player& p) {
    if (p.waterBottles <= 0) {
        std::cout << "没有水可喝!\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    p.waterBottles--;
    p.water = std::min(5, p.water + 2);
    p.emptyBottles++;
    std::cout << "你喝了一瓶水,水分 +2(当前 " << p.water << "),获得一个空瓶。\n";
    pauseForSeconds(2);
    displayStatus(p);
}

void takeMedicine(Player& p) {
    if (p.medicine <= 0) {
        std::cout << "没有普通药片!\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    if (!p.hasPoison && !p.hasCold) {
        std::cout << "你目前没有中毒或感冒。\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    p.medicine--;
    if (p.hasPoison) {
        p.hasPoison = false;
        std::cout << "你服用药片,蛇毒已解!\n";
    } else if (p.hasCold) {
        p.hasCold = false;
        p.canActMorning = true;
        std::cout << "你服用药片,感冒已治愈!\n";
    }
    pauseForSeconds(2);
    displayStatus(p);
}

void takeExpiredMedicine(Player& p) {
    if (p.expiredMeds <= 0) {
        std::cout << "没有过期药!\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    if (!p.hasPoison && !p.hasCold) {
        std::cout << "你目前没有中毒或感冒。\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    int chance = (p.satiety + p.water) * 5;
    p.expiredMeds--;
    if (randomChance(chance / 100.0)) {
        if (p.hasPoison) {
            p.hasPoison = false;
            std::cout << "过期药生效!蛇毒已解!\n";
        } else if (p.hasCold) {
            p.hasCold = false;
            p.canActMorning = true;
            std::cout << "过期药生效!感冒已治愈!\n";
        }
    } else {
        std::cout << "过期药无效...\n";
    }
    pauseForSeconds(2);
    displayStatus(p);
}

void drinkCoconutJuice(Player& p) {
    if (p.coconutJuice <= 0) {
        std::cout << "没有椰汁可喝。\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    p.coconutJuice--;
    p.satiety = std::min(5, p.satiety + 1);
    p.water = std::min(5, p.water + 1);
    p.emptyBottles++;
    std::cout << "你喝了一瓶椰汁,饱食度+1,水分+1,获得一个空瓶。\n";
    pauseForSeconds(2);
    displayStatus(p);
}

void openChest(Player& p) {
    if (p.chests <= 0 || p.keys <= 0) {
        std::cout << "宝箱或钥匙不足。\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    p.chests--;
    p.keys--;
    std::cout << "你打开了一个宝箱!\n";
    int num = randomInt(4 + p.level, 6 + p.level);
    std::vector<std::string> items;
    std::vector<std::string> pool = {"过期药", "椰子", "石头", "水", "瓶子", "食物", "树枝", "树叶", "绳子", "塑料膜"};
    bool gotBlueprint = false;
    for (int i = 0; i < num; ++i) {
        if (!gotBlueprint && randomChance(0.15)) {
            std::vector<std::string> avail;
            if (!p.blueprintSpear) avail.push_back("石矛");
            if (!p.blueprintPickaxe) avail.push_back("石镐");
            if (!p.blueprintAxe) avail.push_back("石斧");
            if (!p.blueprintSword) avail.push_back("石剑");
            if (!p.blueprintShoes) avail.push_back("鞋");
            if (!p.blueprintWaterCollector) avail.push_back("集水");
            if (!p.blueprintNail) avail.push_back("铆钉");
            if (!p.blueprintBoat) avail.push_back("制船");
            if (!p.blueprintPaddles) avail.push_back("船桨");
            if (!p.blueprintFishingRod) avail.push_back("鱼竿");
            if (!p.blueprintSlingshot) avail.push_back("弹弓");
            if (!p.blueprintCampfire) avail.push_back("篝火");
            // 石像蓝图初始拥有,无需解锁
            if (!avail.empty()) {
                int idx = randomInt(0, avail.size() - 1);
                std::string bp = avail[idx];
                items.push_back("蓝图[" + bp + "]");
                if (bp == "石矛") p.blueprintSpear = true;
                else if (bp == "石镐") p.blueprintPickaxe = true;
                else if (bp == "石斧") p.blueprintAxe = true;
                else if (bp == "石剑") p.blueprintSword = true;
                else if (bp == "鞋") p.blueprintShoes = true;
                else if (bp == "集水") p.blueprintWaterCollector = true;
                else if (bp == "铆钉") p.blueprintNail = true;
                else if (bp == "制船") p.blueprintBoat = true;
                else if (bp == "船桨") p.blueprintPaddles = true;
                else if (bp == "鱼竿") p.blueprintFishingRod = true;
                else if (bp == "弹弓") p.blueprintSlingshot = true;
                else if (bp == "篝火") p.blueprintCampfire = true;
                gotBlueprint = true;
                continue;
            }
        }
        int idx = randomInt(0, pool.size() - 1);
        std::string item = pool[idx];
        items.push_back(item);
        if (item == "过期药") p.expiredMeds++;
        else if (item == "椰子") p.coconuts++;
        else if (item == "石头") p.stones++;
        else if (item == "水") p.waterBottles++;
        else if (item == "瓶子") p.emptyBottles++;
        else if (item == "食物") p.food++;
        else if (item == "树枝") p.sticks++;
        else if (item == "树叶") p.leaves++;
        else if (item == "绳子") p.rope++;
        else if (item == "塑料膜") p.cloth++;
    }
    std::cout << "宝箱中藏有:";
    for (auto& it : items) std::cout << it << " ";
    std::cout << "\n";
    p.waterBottles += 2;
    p.food += 2;
    std::cout << "额外获得 2 瓶水和 2 份食物!\n";
    pauseForSeconds(2);
    displayStatus(p);
}

void openCoconut(Player& p) {
    if (p.coconuts <= 0) {
        std::cout << "没有椰子。\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    if (p.satiety < 1 || p.water < 1) {
        std::cout << "你太虚弱,无法开椰子(需要饱食度和水分≥1)。\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    p.coconuts--;
    if (p.hasPickaxe) {
        std::cout << "你用石镐打开了椰子。\n";
    } else {
        if (p.stones <= 0) {
            std::cout << "没有石头,无法开椰子。\n";
            p.coconuts++;
            pauseForSeconds(2);
            displayStatus(p);
            return;
        }
        p.stones--;
        if (randomChance(0.5)) {
            std::cout << "石头崩飞了!\n";
        } else {
            std::cout << "石头完好。\n";
            p.stones++;
        }
        std::cout << "你用石头砸开了椰子。\n";
    }
    int juice = 2;
    int bottles = std::min(p.emptyBottles, juice);
    if (bottles > 0) {
        p.emptyBottles -= bottles;
        p.coconutJuice += bottles;
        juice -= bottles;
        std::cout << "你装了 " << bottles << " 瓶椰汁。\n";
    }
    if (juice > 0) {
        p.satiety = std::min(5, p.satiety + juice);
        p.water = std::min(5, p.water + juice);
        std::cout << "你直接喝掉了 " << juice << " 份椰汁,饱食度+" << juice << ",水分+" << juice << "。\n";
    }
    pauseForSeconds(2);
    displayStatus(p);
}

void cookFish(Player& p) {
    if (!p.hasCampfire) {
        std::cout << "没有篝火!\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    if (p.fish <= 0) {
        std::cout << "没有生鱼。\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    p.fish--;
    p.cookedFish++;
    std::cout << "cooking";
    for (int i = 0; i < 6; ++i) {
        pauseForSeconds(1);
        std::cout << ".";
    }
    std::cout << std::endl;
    std::cout << "烤熟了一条鱼。\n";
    pauseForSeconds(2);
    displayStatus(p);
}

void eatCookedFish(Player& p) {
    if (p.cookedFish <= 0) {
        std::cout << "没有烤鱼。\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    p.cookedFish--;
    int gain = (randomChance(0.34)) ? 2 : 3;
    p.satiety = std::min(5, p.satiety + gain);
    std::cout << "吃了烤鱼,饱食度 +" << gain << "\n";
    pauseForSeconds(2);
    displayStatus(p);
}

void eatCoconut(Player& p) {
    if (p.coconuts <= 0) {
        std::cout << "没有椰子。\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    p.coconuts--;
    p.satiety = std::min(5, p.satiety + 1);
    p.water = std::min(5, p.water + 1);
    std::cout << "你吃了一个椰子,饱食度+1,水分+1。\n";
    pauseForSeconds(2);
    displayStatus(p);
}

// -------------------- 祈祷函数 --------------------
void pray(Player& p, bool& prayedFlag, const std::string& periodName) {
    if (!p.hasStatue) {
        std::cout << "你对着天上的棍母祈祷。\n";
		pauseForSeconds(2);
		if(randomChance(0.0001))
		{
			std::cout<< "It's been a long way,"<<std::endl;
			pauseForSeconds(2);
			std::cout<< "without you my friends."<<std::endl;
			pauseForSeconds(2);
			std::cout<< "直升机从天而降,你被曼巴肘死了! M A N !"<<std::endl;
			pauseForSeconds(2);
			std::cout << "游戏结束。\n";
            Sleep(15000);
            exit(0);
		}
		std::cout << "然而并没有什么用。\n";
		pauseForSeconds(2);
		return;
    }
    if (prayedFlag) {
        std::cout << "本时段你已经祈祷过了。\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    int baseExp = randomInt(5, 10);
    bool crit = randomChance(0.05);
    bool permUp = randomChance(0.01);
    if (permUp) {
        p.permanentMultiplier = std::min(10000, p.permanentMultiplier * 10);
        std::cout << "? 虔诚的祈祷感动了上天!永久倍率提升至 " << p.permanentMultiplier << " 倍!\n";
        prayedFlag = true;
    }
    int gained = baseExp * p.permanentMultiplier;
    if (crit) gained *= 100,prayedFlag = true;
    p.addExp(gained);
    std::cout << "你向石像祈祷,获得了 " << gained << " 经验" << (crit ? "(暴击!)" : "") << "\n";
    pauseForSeconds(2);
    displayStatus(p);
}

// -------------------- 采集函数 --------------------
void addExpAndDisplay(Player& p, int gain) {
    p.addExp(gain);
    std::cout << "获得经验 " << gain << ",当前等级 " << p.level << "\n";
    pauseForSeconds(2);
    displayStatus(p);
}

void collectLeaves(Player& p) {
    int minL, maxL, minS, maxS;
    getCollectBounds(p.level, 4, 9, minL, maxL);
    getCollectBounds(p.level, 0, 2, minS, maxS);
    if (p.hasStoneAxe) {
        minL += 2;
        maxL += 2;
        minS += 2;
        maxS += 2;
    }
    int leaves = randomInt(minL, maxL);
    int sticks = randomInt(minS, maxS);
    p.leaves += leaves;
    p.sticks += sticks;
    std::cout << "你收集了树叶 " << leaves << " 个,树枝 " << sticks << " 个。\n";
    int gain = randomInt(100, 300);
    if (randomChance(0.1)) {
        gain = randomInt(700, 800);
        std::cout << "暴击!经验暴增!\n";
    }
    addExpAndDisplay(p, gain);
}

void collectSticks(Player& p) {
    int minS, maxS, minL, maxL;
    getCollectBounds(p.level, 4, 9, minS, maxS);
    getCollectBounds(p.level, 0, 2, minL, maxL);
    if (p.hasStoneAxe) {
        minS += 2;
        maxS += 2;
        minL += 2;
        maxL += 2;
    }
    int sticks = randomInt(minS, maxS);
    int leaves = randomInt(minL, maxL);
    p.sticks += sticks;
    p.leaves += leaves;
    std::cout << "你收集了树枝 " << sticks << " 个,树叶 " << leaves << " 个。\n";
    int gain = randomInt(100, 300);
    if (randomChance(0.1)) {
        gain = randomInt(700, 800);
        std::cout << "暴击!经验暴增!\n";
    }
    addExpAndDisplay(p, gain);
}

void collectStones(Player& p) {
    if (!canCollectStones(p)) {
        std::cout << "等级不足,需要LV1才能采集石头。\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    int minS, maxS;
    getCollectBounds(p.level, 3, 6, minS, maxS);
    int s = randomInt(minS, maxS);
    p.stones += s;
    std::cout << "你采集了石头 " << s << " 个。\n";
    int gain = randomInt(100, 300);
    if (randomChance(0.1)) {
        gain = randomInt(700, 800);
        std::cout << "暴击!经验暴增!\n";
    }
    addExpAndDisplay(p, gain);
}

void repairHouse(Player& p) {
    if (p.houseLevel == 0) {
        std::cout << "你还没有建造房屋,无法修复。\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    if (p.houseLevel == 4) {
        std::cout << "无限庇护所无需修复。\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    if (p.houseHP >= p.houseLevel) {
        std::cout << "房屋已满血,无需修复。\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    if (p.sticks < 3 || p.leaves < 3) {
        std::cout << "材料不足!需要 3 树枝和 3 树叶。\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    p.sticks -= 3;
    p.leaves -= 3;
    p.houseHP = p.houseLevel;
    std::cout << "房屋已修复至满血(当前血量 " << p.houseHP << ")。\n";
    pauseForSeconds(2);
    displayStatus(p);
}

void fish(Player& p) {
    if (!canFish(p)) {
        std::cout << "等级不足,需要LV2才能钓鱼。\n";
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
    int minF = p.hasFishingRod ? 3 : 0;
    int maxF = p.hasFishingRod ? 6 : 4;
    int min, max;
    getCollectBounds(p.level, minF, maxF, min, max);
    int f = randomInt(min, max);
    p.fish += f;
    std::cout << "你钓到了鱼 " << f << " 条。\n";
    int gain = randomInt(100, 300);
    if (randomChance(0.1)) {
        gain = randomInt(700, 800);
        std::cout << "暴击!经验暴增!\n";
    }
    addExpAndDisplay(p, gain);
}

// -------------------- 打野 --------------------
void hunt(Player& p) {
	int costW,costS;
	if(p.hasStoneSpear)
	{
		std::cout << "你选择打野,拥有石矛只消耗1/2天。\n";
	    costS = p.hasShoes ? 0 : 1;
	    costW = p.hasShoes ? 0 : 1;
	}
	else
	{
		std::cout << "你选择打野,消耗一整天。\n";
	    costS = p.hasShoes ? 2 : 3;
	    costW = p.hasShoes ? 2 : 3;
	}
	p.satiety -= costS;
    p.water -= costW;
    if (checkDeath(p)) {
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }

    std::cout << "你在野外搜索,获得:\n";
    int baseMin = 4, baseMax = 6;
    int num = randomInt(baseMin + p.level, baseMax + p.level);
    std::vector<std::string> items;
    std::vector<std::string> pool = {"过期药", "椰子", "石头", "水", "瓶子", "食物", "树枝", "树叶", "绳子", "塑料膜"};
    bool gotBlueprint = false, gotChest = false, gotKey = false;

    for (int i = 0; i < num; ++i) {
        if (!gotBlueprint && randomChance(0.15)) {
            std::vector<std::string> avail;
            if (!p.blueprintSpear) avail.push_back("石矛");
            if (!p.blueprintPickaxe) avail.push_back("石镐");
            if (!p.blueprintAxe) avail.push_back("石斧");
            if (!p.blueprintSword) avail.push_back("石剑");
            if (!p.blueprintShoes) avail.push_back("鞋");
            if (!p.blueprintWaterCollector) avail.push_back("集水");
            if (!p.blueprintNail) avail.push_back("铆钉");
            if (!p.blueprintBoat) avail.push_back("制船");
            if (!p.blueprintPaddles) avail.push_back("船桨");
            if (!p.blueprintFishingRod) avail.push_back("鱼竿");
            if (!p.blueprintSlingshot) avail.push_back("弹弓");
            if (!p.blueprintCampfire) avail.push_back("篝火");
            if (!avail.empty()) {
                int idx = randomInt(0, avail.size() - 1);
                std::string bp = avail[idx];
                items.push_back("蓝图[" + bp + "]");
                if (bp == "石矛") p.blueprintSpear = true;
                else if (bp == "石镐") p.blueprintPickaxe = true;
                else if (bp == "石斧") p.blueprintAxe = true;
                else if (bp == "石剑") p.blueprintSword = true;
                else if (bp == "鞋") p.blueprintShoes = true;
                else if (bp == "集水") p.blueprintWaterCollector = true;
                else if (bp == "铆钉") p.blueprintNail = true;
                else if (bp == "制船") p.blueprintBoat = true;
                else if (bp == "船桨") p.blueprintPaddles = true;
                else if (bp == "鱼竿") p.blueprintFishingRod = true;
                else if (bp == "弹弓") p.blueprintSlingshot = true;
                else if (bp == "篝火") p.blueprintCampfire = true;
                gotBlueprint = true;
                continue;
            }
        }
        if (randomChance(0.08)) {
            p.chests++;
            items.push_back("宝箱");
        }
        if (randomChance(0.10)) {
            p.keys++;
            items.push_back("宝箱钥匙");
        }
        int idx = randomInt(0, pool.size() - 1);
        std::string item = pool[idx];
        items.push_back(item);
        if (item == "过期药") p.expiredMeds++;
        else if (item == "椰子") p.coconuts++;
        else if (item == "石头") p.stones++;
        else if (item == "水") p.waterBottles++;
        else if (item == "瓶子") p.emptyBottles++;
        else if (item == "食物") p.food++;
        else if (item == "树枝") p.sticks++;
        else if (item == "树叶") p.leaves++;
        else if (item == "绳子") p.rope++;
        else if (item == "塑料膜") p.cloth++;
    }
    for (auto& it : items) std::cout << "- " << it << "\n";

    if (gotChest && gotKey) {
        std::cout << "宝箱+钥匙!打开宝箱!\n";
        if (randomChance(0.5)) {
            std::vector<std::string> avail;
            if (!p.blueprintSpear) avail.push_back("石矛");
            if (!p.blueprintPickaxe) avail.push_back("石镐");
            if (!p.blueprintAxe) avail.push_back("石斧");
            if (!p.blueprintSword) avail.push_back("石剑");
            if (!p.blueprintShoes) avail.push_back("鞋");
            if (!p.blueprintWaterCollector) avail.push_back("集水");
            if (!p.blueprintNail) avail.push_back("铆钉");
            if (!p.blueprintBoat) avail.push_back("制船");
            if (!p.blueprintPaddles) avail.push_back("船桨");
            if (!p.blueprintFishingRod) avail.push_back("鱼竿");
            if (!p.blueprintSlingshot) avail.push_back("弹弓");
            if (!avail.empty()) {
                int idx = randomInt(0, avail.size() - 1);
                std::string bp = avail[idx];
                std::cout << "获得蓝图:" << bp << "\n";
                if (bp == "石矛") p.blueprintSpear = true;
                else if (bp == "石镐") p.blueprintPickaxe = true;
                else if (bp == "石斧") p.blueprintAxe = true;
                else if (bp == "石剑") p.blueprintSword = true;
                else if (bp == "鞋") p.blueprintShoes = true;
                else if (bp == "集水") p.blueprintWaterCollector = true;
                else if (bp == "铆钉") p.blueprintNail = true;
                else if (bp == "制船") p.blueprintBoat = true;
                else if (bp == "船桨") p.blueprintPaddles = true;
                else if (bp == "鱼竿") p.blueprintFishingRod = true;
                else if (bp == "弹弓") p.blueprintSlingshot = true;
            } else {
                std::cout << "所有蓝图已解锁,获得大量物资!\n";
                p.food += 5;
                p.waterBottles += 5;
                p.emptyBottles += 5;
            }
        } else {
            std::cout << "获得大量物资!食物+5,水瓶+5,空瓶+5。\n";
            p.food += 5;
            p.waterBottles += 5;
            p.emptyBottles += 5;
        }
    } else if (gotChest) {
        std::cout << "获得宝箱,但没有钥匙。\n";
    } else if (gotKey) {
        std::cout << "获得钥匙,但没有宝箱。\n";
    }

    if (p.hasSlingshot) {
        int expGain = randomInt(100, 150);
        p.addExp(expGain);
        std::cout << "弹弓使你在打野中额外获得 " << expGain << " 经验!\n";
        pauseForSeconds(1);
    }
    if (p.hasStoneSpear) {
        if (randomChance(0.33)) {
            p.hasStoneSpear = false;
            std::cout << "石矛在打野中损坏了!\n";
            if (randomChance(0.5)) {
                p.rope++;
                std::cout << "你捡回了绳子!\n";
            }
            pauseForSeconds(1);
        }
    }
    pauseForSeconds(2);
    displayStatus(p);
}

// -------------------- 制作系统 --------------------
void showCraftMenu(const Player& p) {
    std::cout << "\n--- 制作菜单 ---\n";
    if (p.blueprintSpear) std::cout << "1. 石矛 (3石,2树枝,1绳)\n";
    if (p.blueprintPickaxe) std::cout << "2. 石镐 (3石,1树枝,1绳)\n";
    if (p.blueprintAxe) std::cout << "3. 石斧 (4石,1树枝,1绳)\n";
    if (p.blueprintSword) std::cout << "4. 石剑 (5石,2树枝)\n";
    if (p.blueprintShoes) std::cout << "5. 鞋 (3布,2绳)\n";
    if (p.blueprintWaterCollector) std::cout << "6. 集水器 (1布)\n";
    if (p.blueprintNail) std::cout << "7. 铆钉 (2石)\n";
    if (p.blueprintPaddles) std::cout << "8. 船桨 (6树枝,2绳)\n";
    if (p.blueprintFishingRod) std::cout << "9. 鱼竿 (5树枝,3绳,1铆钉)\n";
    if (p.blueprintSlingshot) std::cout << "10. 弹弓 (2树枝,1绳)\n";
    if (p.blueprintBoat) std::cout << "11. 制船 (100树枝,10绳,20空瓶,2船桨,20铆钉) - 胜利\n";
    if (p.blueprintCampfire) std::cout << "12. 篝火 (5石,5树叶,2布)\n";
    if (p.blueprintStatue) std::cout << "13. 石像 (4石头)\n";
    std::cout << "0. 返回\n";
}

void craftItem(Player& p, int choice) {
    switch (choice) {
        case 1:
            if (!p.blueprintSpear) { std::cout << "未解锁。\n"; break; }
            if (p.stones < 3 || p.sticks < 2 || p.rope < 1) { std::cout << "材料不足。\n"; break; }
            if (p.hasStoneSpear) { std::cout << "已拥有。\n"; break; }
            p.stones -= 3;
            p.sticks -= 2;
            p.rope -= 1;
            p.hasStoneSpear = true;
            std::cout << "制作石矛成功!\n";
            break;
        case 2:
            if (!p.blueprintPickaxe || p.stones < 3 || p.sticks < 1 || p.rope < 1 || p.hasPickaxe) { std::cout << "无法制作。\n"; break; }
            p.stones -= 3;
            p.sticks -= 1;
            p.rope -= 1;
            p.hasPickaxe = true;
            std::cout << "制作石镐成功!\n";
            break;
        case 3:
            if (!p.blueprintAxe || p.stones < 4 || p.sticks < 1 || p.rope < 1 || p.hasStoneAxe) { std::cout << "无法制作。\n"; break; }
            p.stones -= 4;
            p.sticks -= 1;
            p.rope -= 1;
            p.hasStoneAxe = true;
            std::cout << "制作石斧成功!\n";
            break;
        case 4:
            if (!p.blueprintSword || p.stones < 5 || p.sticks < 2 || p.hasStoneSword) { std::cout << "无法制作。\n"; break; }
            p.stones -= 5;
            p.sticks -= 2;
            p.hasStoneSword = true;
            std::cout << "制作石剑成功!\n";
            break;
        case 5:
            if (!p.blueprintShoes || p.cloth < 3 || p.rope < 2 || p.hasShoes) { std::cout << "无法制作。\n"; break; }
            p.cloth -= 3;
            p.rope -= 2;
            p.hasShoes = true;
            std::cout << "制作鞋成功!\n";
            break;
        case 6: {
            if (!p.blueprintWaterCollector) { std::cout << "未解锁。\n"; break; }
            if (p.cloth < 1) { std::cout << "材料不足(需要1布)。\n"; break; }
            int maxCollectors = 2 * p.level;
            if (p.waterCollectorCount >= maxCollectors) {
                std::cout << "集水器已达上限(" << maxCollectors << "个)。\n";
                break;
            }
            p.cloth -= 1;
            p.waterCollectorCount++;
            p.waterCollectorTimers.push_back(0);
            std::cout << "集水器建造完成!当前数量:" << p.waterCollectorCount << "。\n";
            break;
        }
        case 7:
            if (!p.blueprintNail || p.stones < 2) { std::cout << "无法制作。\n"; break; }
            p.stones -= 2;
            p.nails++;
            std::cout << "制作一个铆钉,当前:" << p.nails << "\n";
            break;
        case 8:
            if (!p.blueprintPaddles || p.sticks < 6 || p.rope < 2) { std::cout << "无法制作。\n"; break; }
            p.sticks -= 6;
            p.rope -= 2;
            p.boatPaddlesCount++;
            std::cout << "制作一个船桨,当前:" << p.boatPaddlesCount << "\n";
            break;
        case 9:
            if (!p.blueprintFishingRod || p.sticks < 5 || p.rope < 3 || p.nails < 1 || p.hasFishingRod) { std::cout << "无法制作。\n"; break; }
            p.sticks -= 5;
            p.rope -= 3;
            p.nails -= 1;
            p.hasFishingRod = true;
            std::cout << "制作鱼竿成功!\n";
            break;
        case 10:
            if (!p.blueprintSlingshot || p.sticks < 2 || p.rope < 1 || p.hasSlingshot) { std::cout << "无法制作。\n"; break; }
            p.sticks -= 2;
            p.rope -= 1;
            p.hasSlingshot = true;
            std::cout << "制作弹弓成功!\n";
            break;
        case 11:
            if (!p.blueprintBoat || p.sticks < 100 || p.rope < 10 || p.emptyBottles < 20 || p.boatPaddlesCount < 2 || p.nails < 20) {
                std::cout << "材料不足,无法造船。\n";
                break;
            }
            p.gameWin = true;
            p.gameOver = true;
            std::cout << "你造出了船!逃离蛇岛!\n";
            break;
        case 12:
            if (!p.blueprintCampfire) { std::cout << "未解锁。\n"; break; }
            if (p.stones < 5 || p.leaves < 5 || p.cloth < 2) {
                std::cout << "材料不足(需要5石头、5树叶、2布)。\n";
                break;
            }
            p.stones -= 5;
            p.leaves -= 5;
            p.cloth -= 2;
            p.hasCampfire = true;
            std::cout << "篝火制作成功!\n";
            break;
        case 13:
            if (!p.blueprintStatue) { std::cout << "未解锁。\n"; break; }
            if (p.stones < 4) { std::cout << "材料不足(需要4石头)。\n"; break; }
            p.stones -= 4;
            p.hasStatue = true;
            std::cout << "石像建造完成!现在你可以祈祷了。\n";
            break;
        default:
            std::cout << "无效选择。\n";
    }
    pauseForSeconds(2);
    displayStatus(p);
}

// -------------------- 房屋建造 --------------------
void buildHouse(Player& p) {
    while (true) {
        std::cout << "\n--- 建造/升级房屋 ---\n";
        if (p.houseLevel == 4) {
            std::cout << "已拥有无限庇护所。\n";
            pauseForSeconds(2);
            displayStatus(p);
            return;
        }
        if (p.houseLevel == 0) {
            std::cout << "当前无房。\n1级:5树枝+5树叶\n2级:8树枝+8树叶\n3级:10树枝+10树叶\n无限:10树枝+10树叶+20石头\n";
            std::cout << "输入要建造的等级 (1-4), 0取消: ";
        } else {
            std::cout << "当前等级 " << p.houseLevel << ",血量 " << p.houseHP << "\n";
            if (p.houseLevel == 1) std::cout << "升2:补3树枝+3树叶  升3:补5+5  无限:补5+5+20石\n";
            else if (p.houseLevel == 2) std::cout << "升3:补2树枝+2树叶  无限:补2+2+20石\n";
            else if (p.houseLevel == 3) std::cout << "无限:补0树枝+0树叶+20石\n";
            std::cout << "输入要升级到的等级 (2-4), 0取消: ";
        }
        int choice;
        std::cin >> choice;
        if (choice == 0) {
            pauseForSeconds(2);
            displayStatus(p);
            return;
        }
        int target = choice;
        if (target < 1 || target > 4 || target <= p.houseLevel) {
            std::cout << "无效等级,重新选择。\n";
            continue;
        }
        int needSticks = 0, needLeaves = 0, needStones = 0;
        if (target == 1) { needSticks = 5; needLeaves = 5; }
        else if (target == 2) { needSticks = 8; needLeaves = 8; }
        else if (target == 3) { needSticks = 10; needLeaves = 10; }
        else if (target == 4) { needSticks = 10; needLeaves = 10; needStones = 20; }
        if (p.houseLevel == 1) { needSticks -= 5; needLeaves -= 5; }
        else if (p.houseLevel == 2) { needSticks -= 8; needLeaves -= 8; }
        else if (p.houseLevel == 3) { needSticks -= 10; needLeaves -= 10; }
        if (needSticks < 0) needSticks = 0;
        if (needLeaves < 0) needLeaves = 0;

        if (p.sticks < needSticks || p.leaves < needLeaves || (target == 4 && p.stones < needStones)) {
            std::cout << "材料不足!需要树枝 " << needSticks << ",树叶 " << needLeaves;
            if (target == 4) std::cout << ",石头 " << needStones;
            std::cout << "。请重新选择。\n";
            continue;
        }
        p.sticks -= needSticks;
        p.leaves -= needLeaves;
        if (target == 4) p.stones -= needStones;
        p.houseLevel = target;
        if (target == 4) { p.houseHP = 9999;
            std::cout << "无限庇护所建成!\n"; } else { p.houseHP = target;
            std::cout << "房屋升级到 " << target << " 级!\n"; }
        pauseForSeconds(2);
        displayStatus(p);
        return;
    }
}

// -------------------- 夜间事件 --------------------
void nightEvents(Player& p) {
    std::cout << "\n--- 夜晚降临 ---\n";

    if (p.houseLevel > 0) {
        p.addExp(50 * p.level);
        std::cout << "房屋使你获得 " << 50 * p.level << " 经验!\n";
    }
    double snakeProb = 0.20;
    if (p.houseLevel > 0) snakeProb = 0.10;
    if (p.hasStoneSword && p.houseLevel > 0) snakeProb = 0.05;
    if (randomChance(snakeProb)) {
        std::cout << "?? 蛇咬!中毒!\n";
        p.hasPoison = true;
    } else {
        std::cout << "今晚无蛇。\n";
    }

    double windProb = 0.50;
    bool wind = randomChance(windProb);
    if (wind && p.houseLevel > 0 && p.houseLevel != 4) {
        std::cout << "?? 大风,房屋受损!\n";
        p.houseHP--;
        if (p.houseHP <= 0) std::cout << "房屋被摧毁(今晚保护仍在)。\n";
    } else if (wind && p.houseLevel == 4) {
        std::cout << "?? 大风,无限庇护所无损。\n";
    } else if (wind && p.houseLevel == 0) {
        std::cout << "?? 大风,没有房屋。\n";
    } else {
        std::cout << "今晚风平浪静。\n";
    }

    if (wind) {
        double coldProb = (p.houseLevel > 0) ? 0.05 : 0.50;
        if (randomChance(coldProb)) {
            std::cout << "?? 感冒了!\n";
            p.hasCold = true;
            p.canActMorning = false;
        } else {
            std::cout << "虽刮风,但未感冒。\n";
        }
    } else {
        std::cout << "无风,不会感冒。\n";
    }

    if (p.houseLevel > 0 && p.houseLevel != 4 && p.houseHP <= 0) {
        p.houseLevel = 0;
        p.houseHP = 0;
        std::cout << "房屋已毁。\n";
    }
    pauseForSeconds(2);
    displayStatus(p);
}

// -------------------- 状态显示 --------------------
void displayStatus(Player& p) {
    clearScreen();
    std::cout << "\n========== 第 " << p.day << " 天 ==========\n";
    std::cout << "饱食度: " << p.satiety << "/5  水分: " << p.water << "/5\n";
    std::cout << "食物: " << p.food << "  水瓶: " << p.waterBottles << "  空瓶: " << p.emptyBottles << "\n";
    std::cout << "药片(普通): " << p.medicine << "  过期药: " << p.expiredMeds << "\n";
    std::cout << "等级: LV" << p.level << "  经验: " << p.exp << "\n";
    std::cout << "树叶: " << p.leaves << "  树枝: " << p.sticks << "  石头: " << p.stones << "\n";
    std::cout << "绳子: " << p.rope << "  布: " << p.cloth << "  铆钉: " << p.nails << "\n";
    std::cout << "鱼: " << p.fish << "  椰子: " << p.coconuts << "  椰汁(瓶): " << p.coconutJuice << "\n";
    if (p.houseLevel > 0) {
        std::cout << "房屋等级: " << (p.houseLevel == 4 ? "无限庇护所" : std::to_string(p.houseLevel))
                  << "  血量: " << (p.houseLevel == 4 ? "∞" : std::to_string(p.houseHP)) << "\n";
    } else {
        std::cout << "房屋: 无\n";
    }
    std::cout << "工具: ";
	if (p.hasStoneSpear) std::cout << "石矛 ";
	if (p.hasPickaxe) std::cout << "石镐 ";
	if (p.hasStoneAxe) std::cout << "石斧 ";
	if (p.hasStoneSword) std::cout << "石剑 ";
	if (p.hasShoes) std::cout << "鞋 ";
	if (p.hasFishingRod) std::cout << "鱼竿 ";
	if (p.hasSlingshot) std::cout << "弹弓 ";
	if (p.waterCollectorCount > 0) std::cout << "集水器x" << p.waterCollectorCount << " ";
	if (p.hasCampfire) std::cout << "篝火 ";
	if (p.hasStatue) std::cout << "石像";
	if (p.permanentMultiplier > 1) std::cout << "(倍率x" << p.permanentMultiplier << ")";
	// 新增宝箱和钥匙显示
	if (p.chests > 0) std::cout << "宝箱x" << p.chests << " ";
	if (p.keys > 0) std::cout << "钥匙x" << p.keys << " ";
	std::cout << "\n";
    if (p.hasPoison) std::cout << "【中毒】 ";
    if (p.hasCold) std::cout << "【感冒】 ";
    std::cout << "\n";
    if (!p.nightSummary.empty()) {
        std::cout << p.nightSummary << "\n";
        p.nightSummary.clear();
    }
}

// -------------------- 死亡/胜利检查 --------------------
bool checkDeath(Player& p) {
    if (p.satiety < 0 || p.water < 0) {
        std::cout << "你死了... 游戏结束。\n";
        p.gameOver = true;
        return true;
    }
    return false;
}

bool checkWin(Player& p) {
    if (p.sticks >= 100 && p.rope >= 10 && p.emptyBottles >= 20 &&
        p.boatPaddlesCount >= 2 && p.nails >= 20) {
        std::cout << "?? 你造出了船!逃离蛇岛!\n";
        p.gameWin = true;
        p.gameOver = true;
        return true;
    }
    return false;
}

// -------------------- 夜晚阶段 --------------------
void nightPhase(Player& p) {
    // 每晚开始前清除感冒
    if (p.hasCold) {
        p.hasCold = false;
        p.canActMorning = true;
        std::cout << "你的感冒已经好了。\n";
        pauseForSeconds(1);
    }
    while (true) {
        displayStatus(p);
        if (checkDeath(p) || checkWin(p)) return;

        std::cout << "\n【晚上】可多次操作,输入 0 结束晚上。\n";
        std::cout << "1.吃 2.喝 3.吃药 4.过期药 5.喝椰汁 6.吃烤鱼 7.吃椰子 8.开椰子 9.制作 10.建房 11.什么都不做 12.修复房屋 13.开宝箱 14.烤鱼 15.祈祷 0.结束晚上\n";
        int choice;
        std::cin >> choice;
        if (choice == 0) break;
        switch (choice) {
            case 1:
                eat(p);
                break;
            case 2:
                drinkWater(p);
                break;
            case 3:
                takeMedicine(p);
                break;
            case 4:
                takeExpiredMedicine(p);
                break;
            case 5:
                drinkCoconutJuice(p);
                break;
            case 6:
                eatCookedFish(p);
                break;
            case 7:
                eatCoconut(p);
                break;
            case 8:
                openCoconut(p);
                break;
            case 9: {
                showCraftMenu(p);
                int c;
                std::cin >> c;
                if (c != 0) craftItem(p, c);
                break;
            }
            case 10:
                buildHouse(p);
                break;
            case 11:
                std::cout << "你休息了一下。\n";
                pauseForSeconds(2);
                displayStatus(p);
                break;
            case 12:
                repairHouse(p);
                break;
            case 13:
                openChest(p);
                break;
            case 14:
                cookFish(p);
                break;
            case 15:
                pray(p, p.prayedNight, "晚上");
                break;
            default:
                std::cout << "无效。\n";
        }
        if (checkDeath(p) || checkWin(p)) return;
    }
    // 晚上未祈祷衰减
    if (!p.prayedNight) {
        p.permanentMultiplier = std::max(1, p.permanentMultiplier / 10);
        std::cout << "你没有在晚上祈祷,永久倍率降低为 " << p.permanentMultiplier << " 倍。\n";
    }
    p.prayedNight = false;

    nightEvents(p);
    p.day++;
    if (p.hasSlingshot) {
        int expGain = randomInt(100, 150);
        p.addExp(expGain);
        std::cout << "弹弓使你在夜晚结束时额外获得 " << expGain << " 经验!\n";
        pauseForSeconds(1);
    }
}

// -------------------- startDay --------------------
void startDay(Player& p) {
    // 集水器产水
    if (p.waterCollectorCount) {
        for (size_t i = 0; i < p.waterCollectorTimers.size(); ++i) {
            p.waterCollectorTimers[i]++;
            if (p.waterCollectorTimers[i] >= 3) {
                p.waterBottles++;
                std::cout << "一个集水器产出一瓶水!\n";
                p.waterCollectorTimers[i] = 0;
            }
        }
    }

    displayStatus(p);
    if (checkDeath(p) || checkWin(p)) return;

    // ========== 早上(循环) ==========
    while (true) {
        displayStatus(p);
        if (checkDeath(p) || checkWin(p)) return;

        std::cout << "\n【早上】可多次操作,输入 0 结束早上。\n";
        std::cout << "1.吃 2.喝 3.吃药 4.过期药 5.喝椰汁 6.吃烤鱼 7.吃椰子 8.开椰子 9.制作 10.开宝箱 11.烤鱼 12.祈祷 0.结束早上\n选择: ";
        int ch;
        std::cin >> ch;
        if (ch == 0) break;
        switch (ch) {
            case 1:
                eat(p);
                break;
            case 2:
                drinkWater(p);
                break;
            case 3:
                takeMedicine(p);
                break;
            case 4:
                takeExpiredMedicine(p);
                break;
            case 5:
                drinkCoconutJuice(p);
                break;
            case 6:
                eatCookedFish(p);
                break;
            case 7:
                eatCoconut(p);
                break;
            case 8:
                openCoconut(p);
                break;
            case 9: {
                showCraftMenu(p);
                int c;
                std::cin >> c;
                if (c != 0) craftItem(p, c);
                break;
            }
            case 10:
                openChest(p);
                break;
            case 11:
                cookFish(p);
                break;
            case 12:
                pray(p, p.prayedMorning, "早上");
                break;
            default:
                std::cout << "无效输入。\n";
                pauseForSeconds(1);
                displayStatus(p);
        }
        if (checkDeath(p) || checkWin(p)) return;
    }
    // 早上未祈祷衰减
    if (!p.prayedMorning) {
        p.permanentMultiplier = std::max(1, p.permanentMultiplier / 10);
        std::cout << "你没有在早上祈祷,永久倍率降低为 " << p.permanentMultiplier << " 倍。\n";
    }
    p.prayedMorning = false;

    // ========== 上午(行动) ==========
    displayStatus(p);
    if (checkDeath(p) || checkWin(p)) return;

    std::cout << "\n【上午】";
    if (p.hasCold && !p.canActMorning) {
        std::cout << "你感冒了,上午无法行动!\n";
        pauseForSeconds(2);
        displayStatus(p);
    } else {
        std::cout << "1.捡树叶 2.捡树枝";
        if (canCollectStones(p)) std::cout << " 3.捡石头";
        if (canFish(p)) std::cout << " 4.钓鱼";
        std::cout << " 5.打野 6.制作 7.什么都不做\n选择: ";
        int act;
        std::cin >> act;
        if (act == 5) {
            // 打野分支
            if (p.hasStoneSpear) {
                hunt(p);
                if (p.gameOver) return;
                // 有石矛:打野仅占上午,继续执行后续(中午、下午会正常衰减)
            } else {
                hunt(p);
                if (p.gameOver) return;
                // 无石矛:打野跳过中午和下午,需手动触发中午和下午的未祈祷衰减
                // 中午衰减
                if (!p.prayedNoon) {
                    p.permanentMultiplier = std::max(1, p.permanentMultiplier / 10);
                    std::cout << "你没有在中午祈祷,永久倍率降低为 " << p.permanentMultiplier << " 倍。\n";
                }
                p.prayedNoon = false;
                nightPhase(p);
                return;
            }
        } else {
            switch (act) {
                case 1:
                    collectLeaves(p);
                    break;
                case 2:
                    collectSticks(p);
                    break;
                case 3:
                    if (canCollectStones(p)) collectStones(p);
                    else std::cout << "等级不足。\n";
                    break;
                case 4:
                    if (canFish(p)) fish(p);
                    else std::cout << "等级不足。\n";
                    break;
                case 6: {
                    showCraftMenu(p);
                    int c;
                    std::cin >> c;
                    if (c != 0) craftItem(p, c);
                    break;
                }
                case 7:
                    std::cout << "你休息了一下。\n";
                    pauseForSeconds(2);
                    displayStatus(p);
                    break;
                default:
                    std::cout << "无效。\n";
            }
            if (checkDeath(p) || checkWin(p)) return;
            // 上午结束扣点
            p.satiety--;
            p.water--;
            std::cout << "上午结束,饱食度-1,水分-1。\n";
            pauseForSeconds(2);
            displayStatus(p);
            if (checkDeath(p) || checkWin(p)) return;
        }
    }

    // ========== 中午(循环) ==========
    while (true) {
        displayStatus(p);
        if (checkDeath(p) || checkWin(p)) return;

        std::cout << "\n【中午】可多次操作,输入 0 结束中午。\n";
        std::cout << "1.吃 2.喝 3.喝椰汁 4.吃烤鱼 5.吃椰子 6.开椰子 7.制作 8.开宝箱 9.烤鱼 10.祈祷 0.结束中午\n选择: ";
        int ch;
        std::cin >> ch;
        if (ch == 0) break;
        switch (ch) {
            case 1:
                eat(p);
                break;
            case 2:
                drinkWater(p);
                break;
            case 3:
                drinkCoconutJuice(p);
                break;
            case 4:
                eatCookedFish(p);
                break;
            case 5:
                eatCoconut(p);
                break;
            case 6:
                openCoconut(p);
                break;
            case 7: {
                showCraftMenu(p);
                int c;
                std::cin >> c;
                if (c != 0) craftItem(p, c);
                break;
            }
            case 8:
                openChest(p);
                break;
            case 9:
                cookFish(p);
                break;
            case 10:
                pray(p, p.prayedNoon, "中午");
                break;
            default:
                std::cout << "无效输入。\n";
                pauseForSeconds(1);
                displayStatus(p);
        }
        if (checkDeath(p) || checkWin(p)) return;
    }
    // 中午未祈祷衰减
    if (!p.prayedNoon) {
        p.permanentMultiplier = std::max(1, p.permanentMultiplier / 10);
        std::cout << "你没有在中午祈祷,永久倍率降低为 " << p.permanentMultiplier << " 倍。\n";
    }
    p.prayedNoon = false;

    // ========== 下午(行动) ==========
    displayStatus(p);
    if (checkDeath(p) || checkWin(p)) return;

    std::cout << "\n【下午】(仅采集) 1.捡树叶 2.捡树枝";
    if (canCollectStones(p)) std::cout << " 3.捡石头";
    if (canFish(p)) std::cout << " 4.钓鱼";
    std::cout << " 5.制作 6.什么都不做\n选择: ";
    int act2;
    std::cin >> act2;
    switch (act2) {
        case 1:
            collectLeaves(p);
            break;
        case 2:
            collectSticks(p);
            break;
        case 3:
            if (canCollectStones(p)) collectStones(p);
            else std::cout << "等级不足。\n";
            break;
        case 4:
            if (canFish(p)) fish(p);
            else std::cout << "等级不足。\n";
            break;
        case 5: {
            showCraftMenu(p);
            int c;
            std::cin >> c;
            if (c != 0) craftItem(p, c);
            break;
        }
        case 6:
            std::cout << "你休息了一下。\n";
            pauseForSeconds(2);
            displayStatus(p);
            break;
        default:
            std::cout << "无效。\n";
    }
    if (checkDeath(p) || checkWin(p)) return;
    // 下午结束扣点
    p.satiety--;
    p.water--;
    std::cout << "下午结束,饱食度-1,水分-1。\n";
    pauseForSeconds(2);
    displayStatus(p);
    if (checkDeath(p) || checkWin(p)) return;

    // 进入夜晚
    nightPhase(p);
}

// -------------------- 主函数 --------------------
int main() {
	Player player;
    clearScreen();
    std::cout << "?? 欢迎来到《蛇岛》!\n";
    std::cout << "你流落荒岛,必须生存下去,并造出船只逃离。\n";
    std::cout << "注意:饱食度和水分低于0就会死亡!\n";
    std::cout << "祝你幸运!\n\n";
    std::cout << "按回车键开始游戏...";
    std::cin.get();
	std::cout << "是否要加载存档?\n1.是 0.否\n选择:";
	int op;
	std::cin >> op;
	if(op == 1)
	{
		clearScreen();
		bool ret = load(player);
		clearScreen();
		while(!ret)
		{
			std::cout << "请检查存档是否正常。\n是否再次尝试?\n1.是 0.否\n选择:";
			std::cin >> op;
			if(op == 0) break;
			clearScreen();
			ret = load(player);
			clearScreen();
		}
	}
	pauseForSeconds(2);
	clearScreen();
    while (!player.gameOver) {
        startDay(player);
        if (player.gameWin) {
            std::cout << "恭喜你成功逃离蛇岛!\n";
            Sleep(15000);
            break;
        }
        if (player.gameOver) {
            std::cout << "游戏结束。\n";
            Sleep(15000);
            break;
        }
    }
    return 0;
}