让 deepseek 配合我写一个游戏

· · 休闲·娱乐

游戏介绍

《方太阳下的轮回》—— 规则怪谈文字冒险

你是一名信息学竞赛生,今天是你自认为的 17 岁生日(实际上因为父母晚报年龄,你已满 18 岁)。你生活在一个由“蓝色空间号”后裔建立的虚拟世界中——这里的太阳是方的,有四个角和四条边;你所在的城市、高中、班级排名、年龄都恰好是“第四”。昨晚训练结束后,你的总通过题数正好是 4444。今天早上醒来,父母反复对你说:“要离开了,好好再看看这个世界吧。” 你隐约感到不对劲,但记忆中的一切似乎都正常。

这个世界隐藏着诡异的规则。当你踏入学校机房,你会发现两份相互矛盾的规则:一份是虚拟世界为了保护“17 岁”的你而制定的简体规则,另一份是曾经失踪的学长留下的繁体指引。你必须在轮回中探索真相,收集 U 盘,找到学长的数字化存在,才能打破循环。

核心机制:

游戏教程

1. 开始游戏

2. 地点与行动

3. 规则查看与玩家面板

4. 死亡与轮回

5. 结局与评分

6. 通关后

高分通关攻略

想要获得 SSS 评分(13.0 分)并非易事,但掌握以下技巧可以让你在轮回中游刃有余,大幅提升最终评分。

1. 理解评分公式

2. 开局必做:第一天获取规则

3. 高效获取 U 盘

4. 机房电脑利用技巧

机房 16 台电脑功能随机分布,每次轮回重新洗牌。查看电脑消耗 1 体力,但可能获得关键信息或触发结局。

5. 避免无谓死亡

6. 隐藏结局“第四面墙” —— 直接满分

7. 轮回天数与主线成功率的平衡

8. 体力分配建议

9. 多结局的选择

10. 最后提醒

祝你早日打破轮回,获得最高荣誉!

祝你揭开真相,逃离轮回!

游戏源码:

#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <algorithm>
#include <sstream>

using namespace std;

// ==================== 全局常量 ====================
const char GLITCH_CHAR = '▓';      // 乱码字符(直接使用 ▓)
const double BASE_SCORE = 10.0;    // 基础评分基数
const double MIN_SCORE = 3.0;      // 最低分
const double MAX_SCORE = 13.0;     // 最高分

// ==================== 全局统计变量 ====================
int cycleDays = 0;          // 轮回天数(隐藏,仅结算显示)
int totalChoices = 0;       // 所有轮回中选择次数
int totalGlitches = 0;      // 所有轮回中显示的乱码字符总数
int totalItems = 0;         // 所有轮回中获得的U盘总数(包括消耗的)
int itemsThisCycle = 0;     // 当前轮回获得的U盘数(用于计算消耗)

// ==================== 辅助函数 ====================

// 返回当前轮回的乱码概率
double getGlitchProb() {
    double p = 1.0 - cycleDays * 0.1;
    if (p < 0.0) p = 0.0;
    return p;
}

// 将字符串按概率p替换为乱码,并累加计数(可选)
string applyGlitch(const string& text, double p, bool count = true) {
    string result;
    for (size_t i = 0; i < text.size(); ++i) {
        if ((rand() / (RAND_MAX + 1.0)) < p) {
            result += GLITCH_CHAR;   // 使用 ▓
            if (count) ++totalGlitches;
        } else {
            result += text[i];
        }
    }
    return result;
}

// 将字符串按规则显示概率处理(编号部分不乱码)
string applyRuleGlitch(const string& ruleText, double p) {
    // 直接使用传入的概率,不再限制
    return applyGlitch(ruleText, p, true);
}

// 返回当前时间字符串(用于整点虚影判断)
string currentTimeString() {
    time_t now = time(0);
    tm* ltm = localtime(&now);
    char buffer[6];
    sprintf(buffer, "%02d:%02d", ltm->tm_hour, ltm->tm_min);
    return string(buffer);
}

// 指数函数近似(C++98没有exp,用简单近似)
double myExp(double x) {
    double result = 1.0;
    double term = 1.0;
    for (int i = 1; i < 20; ++i) {
        term *= x / i;
        result += term;
    }
    return result;
}

// 计算基础分(logistic映射)
double computeBaseScore() {
    double raw = BASE_SCORE - cycleDays * 0.6 + totalItems * 0.4 + totalChoices * 0.02 - totalGlitches * 0.002;
    // logistic: 3 + 10 / (1 + exp(-(raw-8)/2))
    double exponent = -(raw - 8.0) / 2.0;
    double denom = 1.0 + myExp(exponent);
    return MIN_SCORE + 10.0 / denom;
}

// ==================== 数据结构 ====================

struct Rule {
    int id;                 // 规则编号
    string content;         // 规则内容
    bool isTraditional;     // true=繁体,false=简体
    bool isSpecial;         // 是否为规则II的第5条(说明规则)
};

struct Computer {
    string id;              // 如"A1"
    int type;               // 0=开机1,1=开机2,2=开机3,3=硬币,4=学长,5=隐藏1,6=隐藏2,7=隐藏3,8=隐藏4,9=时间1,10=时间2,11=代码展示,12=小游戏1,13=小游戏2,14=小游戏3,15=小游戏4
    bool used;              // 当前轮回是否已被查看过
};

// ==================== 规则库 ====================

// 规则I(简体)
vector<Rule> createRulesI() {
    vector<Rule> rules;
    rules.push_back((Rule){1, "机房里的16台电脑,编号从A1到D4,其中有一台是陷阱,如果你使用它,你的意识将被永久锁定。", false, false});
    rules.push_back((Rule){2, "数字4444是世界的禁忌。如果你在任何屏幕上看到它,必须立刻闭上眼,从1数到4,再睁开。否则你会迷失在数字的循环中。", false, false});
    rules.push_back((Rule){3, "机房中严禁插入任何外接存储设备。若你插入U盘,系统会识别为入侵,你将立即被强制下线(死亡)。", false, false});
    rules.push_back((Rule){4, "机房墙上的时钟永远指向4:44,那是一个警告——在4:44时,你必须离开机房,否则你会被永远困在那个时刻。", false, false});
    rules.push_back((Rule){5, "那些闪烁的代码是系统的呼吸,不要去解读它们。你看得越久,它们就越会侵入你的思维,让你忘记自己是谁。", false, false});
    // 随机打乱顺序(但保留编号)
    random_shuffle(rules.begin(), rules.end());
    return rules;
}

// 规则II(繁体)
vector<Rule> createRulesII() {
    vector<Rule> rules;
    rules.push_back((Rule){1, "16台電腦中,有一台需要投入一枚刻著「4」的硬幣。投入後輸入「4444」,它會告訴你一個祕密——你已經輪迴了多少次。", true, false});
    rules.push_back((Rule){2, "(第一條)有兩台電腦與時間有關:一台永遠顯示4:44,那是世界的錨點;另一台在整點時會出現我的虛影,那是我在提醒你「時間不多了」。", true, false});
    rules.push_back((Rule){2, "(第二條)那些看似無用的程式碼其實隱藏著線索。仔細看,它們或許會告訴你下一個目的地。", true, false});
    rules.push_back((Rule){3, "你需要找到兩個空的U盤——一個在食堂(活著拿到它),一個在教室(答對10題拿到它)。然後回到機房,找到那台等待你的電腦(編號隨機),同時插入兩個U盤,你會見到我。", true, false});
    rules.push_back((Rule){4, "機房裡有四台電腦貼著規則或藏著紙條,把它們全部找到,你就能拼湊出這個世界的真相。", true, false});
    rules.push_back((Rule){5, "本規則共5條,但編號2使用了兩次,所以實際有6條。記住,那些小遊戲電腦只是為了讓你放鬆,真正的出口不在那裡。", true, true});
    random_shuffle(rules.begin(), rules.end());
    return rules;
}

// 规则III
const string RULE_III = "不要相信规则II。";

// 食堂规则(彩蛋)
const string CANTEEN_RULE = "食堂死亡方式:1. 没有消费就离开 2. 没有购买西红柿鸡蛋 3. 购买并食用西红柿鸡蛋";

// ==================== 全局数据 ====================

vector<Rule> knownRules;    // 已获得的规则(跨轮回保留)
bool coinObtainedThisCycle = false; // 当前轮回是否已获得硬币

// ==================== 游戏状态 ====================

int currentCycle = 0;       // 当前轮回数(用于概率计算,但cycleDays已全局)
int remainingEnergy;        // 剩余体力
bool gameOver = false;      // 游戏是否结束(达成结局)
bool mainEndingTriggered = false; // 是否已触发主线结局
string finalEndingName;     // 触发的结局名称
double finalScore;          // 最终评分

// 地点访问标记
bool visitedComputerRoom = false;
bool visitedCanteen = false;
bool visitedPlayground = false;
bool visitedClassroom = false;

// 教学楼答题计数
int correctCount = 0;

// 特殊结局触发条件统计
int noItemCycles = 0;               // 连续未获得U盘的轮回数
bool allGamesWon = false;           // 当前轮回是否已赢所有小游戏
int hiddenRulesFound = 0;           // 已找到的隐藏规则碎片数(跨轮回累计)
bool computerRoomFirstVisit = true; // 是否是第一次进入机房(用于获取规则,全局只触发一次)

// 统计违反规则计数(用于规则破坏者)
int violationCountI = 0;    // 违反规则I条数
int violationCountII = 0;   // 违反规则II条数

// 电脑列表
vector<Computer> computers;

// 初始化电脑功能(每个轮回随机分配)
void initComputers() {
    computers.clear();
    // 生成16个位置
    string ids[16] = {"A1","A2","A3","A4","B1","B2","B3","B4","C1","C2","C3","C4","D1","D2","D3","D4"};
    vector<int> types;
    // 按功能数量生成类型索引
    for (int i = 0; i < 3; i++) types.push_back(0); // 开机1
    for (int i = 0; i < 3; i++) types.push_back(1); // 开机2
    for (int i = 0; i < 3; i++) types.push_back(2); // 开机3
    types.push_back(3); // 硬币
    types.push_back(4); // 学长
    types.push_back(5); // 隐藏1
    types.push_back(6); // 隐藏2
    types.push_back(7); // 隐藏3
    types.push_back(8); // 隐藏4
    types.push_back(9); // 时间1
    types.push_back(10); // 时间2
    types.push_back(11); // 代码展示
    types.push_back(12); // 小游戏1
    types.push_back(13); // 小游戏2
    types.push_back(14); // 小游戏3
    types.push_back(15); // 小游戏4
    random_shuffle(types.begin(), types.end());
    for (int i = 0; i < 16; ++i) {
        Computer c;
        c.id = ids[i];
        c.type = types[i];
        c.used = false;
        computers.push_back(c);
    }
}

// 显示电脑列表(仅显示编号,不显示功能)
void showComputers() {
    cout << "剩余体力:" << remainingEnergy << endl;   // 新增:显示剩余体力
    cout << "机房里有16台电脑,编号如下:" << endl;
    for (int i = 0; i < 16; ++i) {
        cout << computers[i].id;
        if (computers[i].used) cout << "(已查看)";
        cout << " ";
        if ((i+1) % 4 == 0) cout << endl;
    }
}

// 根据类型返回电脑的描述(查看时显示)
string getComputerDescription(int type, bool& triggerDeath, bool& triggerItem, bool& triggerCoin, bool& triggerEnd) {
    triggerDeath = false;
    triggerItem = false;
    triggerCoin = false;
    triggerEnd = false;
    double p = getGlitchProb();
    ostringstream oss;
    switch (type) {
        case 0: // 开机1: 代码刷屏
            oss << "屏幕不断刷新着乱码,偶尔闪过一行字:" << applyGlitch("cycleDays=?", p);
            break;
        case 1: // 开机2: 学长日志
            if (cycleDays == 0) oss << "屏幕上显示着学长留下的日志:第一天,这里好奇怪。";
            else if (cycleDays == 1) oss << "屏幕上显示着学长留下的日志:第二次了,我好像记得什么。";
            else if (cycleDays == 2) oss << "屏幕上显示着学长留下的日志:第三次...我快记不清了。";
            else if (cycleDays >= 3) oss << "屏幕上显示着学长留下的日志:第" << cycleDays << "次了,我还在寻找出口。";
            else oss << "屏幕上显示着学长留下的日志:日志已损坏。";
            break;
        case 2: // 开机3: 倒计时
            {
                int seconds = rand() % 60 + 10;
                oss << "倒计时:距离系统重置 " << seconds << " 秒(数字在不断变化)";
            }
            break;
        case 3: // 硬币电脑
            oss << "这台电脑有一个硬币投入口。";
            break;
        case 4: // 学长电脑
            oss << "这台电脑看起来与众不同,屏幕上有一个闪烁的光标。";
            break;
        case 5: // 隐藏1
            oss << "墙上贴着一张守则:" << applyGlitch("禁止携带食物进入机房,违者死亡。", p);
            break;
        case 6: // 隐藏2
            oss << "抽屉里有一张纸条:" << applyGlitch("真正的规则在你们自己手中。", p);
            break;
        case 7: // 隐藏3
            oss << "键盘下压着一张纸条:" << applyGlitch("不要看镜子里的自己超过4秒。", p);
            break;
        case 8: // 隐藏4
            oss << "显示器背面刻着一行字:" << applyGlitch("如果你看到这个,说明你已经轮回太多次了。", p);
            break;
        case 9: // 时间1
            oss << "屏幕上显示着一个始终指向4:44的时钟。";
            break;
        case 10: // 时间2
            {
                string curTime = currentTimeString();
                oss << "屏幕上显示着当前时间:" << curTime;
                if (curTime.substr(3) == "00") { // 整点
                    oss << " 突然,屏幕上出现一个虚影,说道:“时间不多了。”";
                }
            }
            break;
        case 11: // 代码展示
            oss << "屏幕上显示着一段C++代码:" << endl;
            oss << "#include <iostream>" << endl;
            oss << "int main() { std::cout << \"Hello World\"; return 0; }";
            break;
        case 12: // 小游戏1 猜数字
        case 13: // 小游戏2 井字棋
        case 14: // 小游戏3 石头剪刀布
        case 15: // 小游戏4 掷骰子
            oss << "这是一台游戏电脑。";
            break;
        default: oss << "未知功能。";
    }
    return oss.str();
}

// 处理小游戏
bool playMiniGame(int type) {
    cout << "开始小游戏..." << endl;
    if (type == 12) { // 猜数字 1-100
        int target = rand() % 100 + 1;
        cout << "猜一个1-100之间的数字:";
        int guess;
        cin >> guess;
        totalChoices++;
        if (guess == target) {
            cout << "恭喜你猜对了!" << endl;
            return true;
        } else {
            cout << "猜错了,数字是" << target << "。" << endl;
            return false;
        }
    } else if (type == 13) { // 井字棋简化
        cout << "井字棋(简化版):你执X,电脑执O,你先走。" << endl;
        char board[3][3] = {{'1','2','3'},{'4','5','6'},{'7','8','9'}};
        int moves = 0;
        bool playerTurn = true;
        while (moves < 9) {
            for (int i = 0; i < 3; ++i) {
                for (int j = 0; j < 3; ++j) cout << board[i][j] << " ";
                cout << endl;
            }
            if (playerTurn) {
                int pos;
                cout << "输入位置编号(1-9): ";
                cin >> pos;
                totalChoices++;
                if (pos < 1 || pos > 9) { cout << "无效输入。" << endl; continue; }
                int r = (pos-1)/3, c = (pos-1)%3;
                if (board[r][c] != 'X' && board[r][c] != 'O') {
                    board[r][c] = 'X';
                    playerTurn = false;
                    moves++;
                } else {
                    cout << "该位置已有棋子,重新输入。" << endl;
                }
            } else {
                int r, c;
                do {
                    r = rand() % 3;
                    c = rand() % 3;
                } while (board[r][c] == 'X' || board[r][c] == 'O');
                board[r][c] = 'O';
                cout << "电脑下在" << (r*3+c+1) << endl;
                playerTurn = true;
                moves++;
            }
        }
        cout << "平局。算你赢吧。" << endl;
        return true;
    } else if (type == 14) { // 石头剪刀布
        string choices[3] = {"石头", "剪刀", "布"};
        int player;
        cout << "输入 0-石头, 1-剪刀, 2-布: ";
        cin >> player;
        totalChoices++;
        int computer = rand() % 3;
        cout << "电脑出了" << choices[computer] << ",你出了" << choices[player] << "。" << endl;
        if (player == computer) {
            cout << "平局,再试一次。" << endl;
            return playMiniGame(type);
        } else if ((player == 0 && computer == 1) || (player == 1 && computer == 2) || (player == 2 && computer == 0)) {
            cout << "你赢了!" << endl;
            return true;
        } else {
            cout << "你输了。" << endl;
            return false;
        }
    } else if (type == 15) { // 掷骰子
        int player = rand() % 6 + 1;
        int computer = rand() % 6 + 1;
        cout << "你掷出" << player << ",电脑掷出" << computer << "。" << endl;
        if (player > computer) {
            cout << "你赢了!" << endl;
            return true;
        } else if (player < computer) {
            cout << "你输了。" << endl;
            return false;
        } else {
            cout << "平局,重掷。" << endl;
            return playMiniGame(type);
        }
    }
    return false;
}

// ==================== 地点事件 ====================

bool goToCanteen() {
    cout << "你来到食堂。" << endl;
    cout << "窗口有西红柿鸡蛋盖饭,价格4元。" << endl;
    cout << "你会怎么做?" << endl;
    cout << "1. 购买并食用" << endl;
    cout << "2. 购买但不食用" << endl;
    cout << "3. 不购买直接离开" << endl;
    int choice;
    cin >> choice;
    totalChoices++;
    if (choice == 1) {
        cout << "你吃下了西红柿鸡蛋,突然感到一阵眩晕,倒在地上。" << endl;
        return true;
    } else if (choice == 2) {
        cout << "你付了钱,但没有吃,带走了饭。" << endl;
        cout << "你获得了食堂规则(彩蛋)和一个空U盘!" << endl;
        cout << "食堂规则:" << CANTEEN_RULE << endl;
        totalItems++;
        itemsThisCycle++;
        return false;
    } else if (choice == 3) {
        cout << "你什么都没买就离开了,刚走出门口,就失去了意识。" << endl;
        return true;
    } else {
        cout << "无效选择,原地死亡。" << endl;
        return true;
    }
}

bool goToClassroom() {
    cout << "你来到教学楼,开始答题挑战。" << endl;
    cout << "连续答对10题可获得U盘。错一道计数清零,错两道死亡。" << endl;
    int mistakes = 0;
    int consecutive = 0;
    while (consecutive < 10) {
        int type = rand() % 6;
        int a, b, correctAns;
        string op;
        switch (type) {
            case 0:
                a = rand() % 90 + 10;
                b = rand() % 90 + 10;
                correctAns = a + b;
                op = "+";
                break;
            case 1:
                a = rand() % 90 + 10;
                b = rand() % 90 + 10;
                if (a < b) swap(a, b);
                correctAns = a - b;
                op = "-";
                break;
            case 2:
                a = rand() % 9 + 1;
                b = rand() % 9 + 1;
                correctAns = a * b;
                op = "*";
                break;
            case 3:
                a = rand() % 9 + 1;
                correctAns = a * a;
                op = "^2";
                break;
            case 4:
                a = rand() % 9 + 1;
                correctAns = a * a * a;
                op = "^3";
                break;
            case 5:
                a = rand() % 4 + 1;
                correctAns = a * a * a * a;
                op = "^4";
                break;
        }
        int options[3];
        for (int i = 0; i < 3; ++i) {
            do {
                options[i] = correctAns + (rand() % 11 - 5);
                if (options[i] < 0) options[i] = 0;
            } while (options[i] == correctAns);
        }
        vector<int> opts;
        opts.push_back(correctAns);
        opts.push_back(options[0]);
        opts.push_back(options[1]);
        opts.push_back(options[2]);
        random_shuffle(opts.begin(), opts.end());

        cout << "题目: " << a << " " << op;
        if (type >= 3) cout << " = ?" << endl;
        else cout << " " << b << " = ?" << endl;
        for (int i = 0; i < 4; ++i) cout << i+1 << ". " << opts[i] << endl;
        int ans;
        cin >> ans;
        totalChoices++;
        if (ans < 1 || ans > 4 || opts[ans-1] != correctAns) {
            cout << "回答错误!" << endl;
            mistakes++;
            consecutive = 0;
            if (mistakes >= 2) {
                cout << "你已经错了两道题,死亡。" << endl;
                return true;
            } else {
                cout << "当前计数已清零,你还有一次机会。" << endl;
            }
        } else {
            cout << "回答正确!" << endl;
            consecutive++;
            cout << "当前连续正确:" << consecutive << "/10" << endl;
        }
    }
    cout << "恭喜你连续答对10题,获得一个空U盘!" << endl;
    totalItems++;
    itemsThisCycle++;
    return false;
}

bool goToPlayground() {
    cout << "你来到操场,看到一块牌子,上面写着:" << endl;
    cout << RULE_III << endl;
    return false;
}

void goHomeAndDie() {
    cout << "体力耗尽,你踏上回家的路。" << endl;
    int r = rand() % 3;
    switch (r) {
        case 0: cout << "路上遇到穿黑色制服的人,他问你“你看到了什么?”你还没来得及回答,便被拖入黑暗。" << endl; break;
        case 1: cout << "天空中的方形太阳突然发出刺眼光芒,你感到意识模糊,最终消散。" << endl; break;
        case 2: cout << "周围的时间开始扭曲,你被卡在循环的缝隙中,无法逃脱。" << endl; break;
    }
    cout << "你死了。" << endl;
}

// ==================== 主游戏循环 ====================

void newCycle() {
    remainingEnergy = 8;  // 体力从5改为8
    visitedComputerRoom = false;
    visitedCanteen = false;
    visitedPlayground = false;
    visitedClassroom = false;
    correctCount = 0;
    itemsThisCycle = 0;
    coinObtainedThisCycle = false;
    allGamesWon = false;
    violationCountI = 0;
    violationCountII = 0;

    initComputers();

    cout << "\n========== 新的一天开始 ==========" << endl;
    cout << "早上6:00,你在去学校的路上。" << endl;
    cout << "剩余体力:" << remainingEnergy << endl;

    cout << "你的父母站在门口,他们是如此善良友好,眼神中充满慈爱和不舍。" << endl;
    string parentWords = "要离开了,好好再看看这个世界吧。";
    double p = getGlitchProb();
    cout << "他们对你说:\"" << applyGlitch(parentWords, p) << "\" (他们反复重复着这句话)" << endl;
}

void processLocation() {
    while (remainingEnergy > 0 && !gameOver) {
        cout << "\n剩余体力:" << remainingEnergy << endl;
        cout << "你可以前往:" << endl;

        // 第一天(第一个轮回且还没去过机房)只显示机房选项
        vector<string> options;
        if (cycleDays == 0 && computerRoomFirstVisit) {
            options.push_back("机房");
        } else {
            options.push_back("机房");
            options.push_back("食堂");
            options.push_back("操场");
            options.push_back("教学楼");
        }
        random_shuffle(options.begin(), options.end());
        for (size_t i = 0; i < options.size(); ++i) {
            cout << i+1 << ". " << options[i] << endl;
        }
        cout << "5. 打开玩家面板" << endl;
        cout << "6. 查看已获得规则" << endl;
        cout << "请选择 (1-6): ";
        int choice;
        cin >> choice;
        totalChoices++;

        if (choice >= 1 && choice <= static_cast<int>(options.size())) {
            string loc = options[choice-1];
            if (loc == "机房") {
                remainingEnergy--;
                cout << "你来到机房。" << endl;
                if (computerRoomFirstVisit) {
                    computerRoomFirstVisit = false;
                    vector<Rule> rulesI = createRulesI();
                    vector<Rule> rulesII = createRulesII();
                    double p = getGlitchProb();
                    cout << "\n你看到墙上贴着一张告示(简体):" << endl;
                    for (size_t i = 0; i < rulesI.size(); ++i) {
                        knownRules.push_back(rulesI[i]);
                        cout << "规则 " << rulesI[i].id << ":";
                        string glitched = applyRuleGlitch(rulesI[i].content, p);
                        cout << glitched << " (简体)" << endl;
                    }
                    cout << "\n在机房,你发现一本泛黄的笔记本(繁体):" << endl;
                    for (size_t i = 0; i < rulesII.size(); ++i) {
                        knownRules.push_back(rulesII[i]);
                        cout << "规则 " << rulesII[i].id << ":";
                        string glitched = applyRuleGlitch(rulesII[i].content, p);
                        cout << glitched << " (繁体)" << endl;
                    }
                }
                // 进入机房后可以查看电脑
                while (remainingEnergy > 0 && !gameOver) {
                    showComputers();
                    cout << "输入要查看的电脑编号(如A1),或输入0返回:";
                    string compId;
                    cin >> compId;
                    totalChoices++;
                    if (compId == "0") break;
                    int idx = -1;
                    for (int i = 0; i < 16; ++i) {
                        if (computers[i].id == compId) {
                            idx = i;
                            break;
                        }
                    }
                    if (idx == -1) {
                        cout << "无效编号。" << endl;
                        continue;
                    }
                    if (computers[idx].used) {
                        cout << "这台电脑你今天已经查看过了。" << endl;
                        continue;
                    }
                    remainingEnergy--;
                    computers[idx].used = true;
                    bool death = false, item = false, coin = false, ending = false;
                    string desc = getComputerDescription(computers[idx].type, death, item, coin, ending);
                    cout << desc << endl;

                    int type = computers[idx].type;
                    if (type == 3) {
                        if (!coinObtainedThisCycle) {
                            cout << "你没有硬币。" << endl;
                        } else {
                            cout << "你投入了硬币,屏幕提示输入密码:";
                            string pass;
                            cin >> pass;
                            totalChoices++;
                            if (pass == "4444") {
                                cout << "屏幕显示:当前轮回次数 = " << cycleDays << "(隐藏信息)" << endl;
                            } else {
                                cout << "密码错误。" << endl;
                            }
                        }
                    } else if (type == 4) {
                        if (itemsThisCycle >= 2) {
                            cout << "你同时插入两个U盘,屏幕亮了,出现一行字:" << endl;
                            cout << "“你终于来了。相信我,跟我走,一起离开这里。”" << endl;
                            cout << "1. 相信他" << endl;
                            cout << "2. 怀疑" << endl;
                            int ch;
                            cin >> ch;
                            totalChoices++;
                            if (ch == 1) {
                                double failProb = 0.5 + max(0.5 - cycleDays * 0.04, 0.0);
                                if ((rand() / (RAND_MAX + 1.0)) < failProb) {
                                    cout << "失败了,一个U盘消失了。" << endl;
                                    totalItems--;
                                    itemsThisCycle--;
                                } else {
                                    finalEndingName = "与学长一同离开";
                                    gameOver = true;
                                    mainEndingTriggered = true;
                                    return;
                                }
                            } else if (ch == 2) {
                                cout << "你选择了怀疑,学长消失,两个U盘也没了。" << endl;
                                totalItems -= 2;
                                itemsThisCycle -= 2;
                                if (cycleDays >= 5) {
                                    cout << "突然,学长的虚影再次出现:“等等,我们可以一起探索系统漏洞!”" << endl;
                                    cout << "1. 接受" << endl;
                                    cout << "2. 拒绝" << endl;
                                    cin >> ch;
                                    totalChoices++;
                                    if (ch == 1) {
                                        finalEndingName = "与学长共存";
                                        gameOver = true;
                                        return;
                                    }
                                }
                            }
                        } else {
                            cout << "你需要两个U盘才能使用这台电脑。" << endl;
                        }
                    } else if (type >= 12 && type <= 15) {
                        bool win = playMiniGame(type);
                        if (win) {
                            static bool gamesWon[4] = {false,false,false,false};
                            gamesWon[type-12] = true;
                            bool all = true;
                            for (int i = 0; i < 4; ++i) if (!gamesWon[i]) all = false;
                            if (all) allGamesWon = true;
                        }
                    } else if (type >= 5 && type <= 8) {
                        hiddenRulesFound++;
                    }

                    if (death) {
                        cout << "你违反了规则,死亡。" << endl;
                        gameOver = true;
                        return;
                    }
                }
            } else if (loc == "食堂") {
                if (visitedCanteen) {
                    cout << "你今天已经去过食堂了。" << endl;
                    continue;
                }
                remainingEnergy--;
                visitedCanteen = true;
                if (goToCanteen()) {
                    gameOver = true;
                    return;
                }
            } else if (loc == "操场") {
                if (visitedPlayground) {
                    cout << "你今天已经去过操场了。" << endl;
                    continue;
                }
                remainingEnergy--;
                visitedPlayground = true;
                if (goToPlayground()) { gameOver = true; return; }
                if (allGamesWon) {
                    cout << "你展示了你赢得的成就,系统认为你是个游戏大师,决定送你离开。" << endl;
                    finalEndingName = "小游戏之王";
                    gameOver = true;
                    return;
                }
                if (hiddenRulesFound >= 4) {
                    cout << "你拼凑出了规则的真相,世界随之重组。" << endl;
                    finalEndingName = "规则解析者";
                    gameOver = true;
                    return;
                }
                if (violationCountI >= 5 && violationCountII >= 6) {
                    cout << "你挑战了所有规则,系统将你视为病毒删除。" << endl;
                    finalEndingName = "规则破坏者";
                    gameOver = true;
                    return;
                }
            } else if (loc == "教学楼") {
                if (visitedClassroom) {
                    cout << "你今天已经去过教学楼了。" << endl;
                    continue;
                }
                remainingEnergy--;
                visitedClassroom = true;
                if (goToClassroom()) {
                    gameOver = true;
                    return;
                }
            }
        } else if (choice == 5) {
            char probStr[10];
            sprintf(probStr, "%.2f", getGlitchProb());
            int randomMod = rand() % 100;
            ostringstream oss;
            oss << "=== 玩家面板 ===\n";
            oss << "率:" << probStr << "\n";
            oss << "轮:" << randomMod << "\n";
            oss << "其他信息布满了乱码...";
            cout << applyGlitch(oss.str(), getGlitchProb()) << endl;
        } else if (choice == 6) {
            if (knownRules.empty()) {
                cout << "你还没有获得任何规则。" << endl;
            } else {
                cout << "你拿到的所有规则如下:" << endl;
                double displayP = getGlitchProb(); // 不再限制
                for (size_t i = 0; i < knownRules.size(); ++i) {
                    cout << "规则 " << knownRules[i].id;
                    if (knownRules[i].isTraditional) cout << "(繁体)";
                    else cout << "(简体)";
                    cout << ":";
                    string glitched = applyGlitch(knownRules[i].content, displayP, true);
                    cout << glitched << endl;
                }
            }
            static int ruleViewCount = 0;
            if ((rand() % 100) == 0) {
                ruleViewCount++;
                if (ruleViewCount >= 10) {
                    finalEndingName = "第四面墙";
                    gameOver = true;
                    return;
                }
            }
        } else {
            cout << "无效选择。" << endl;
        }
    }

    if (remainingEnergy <= 0 && !gameOver) {
        goHomeAndDie();
        if (cycleDays >= 10 && (rand() % 20 == 0)) {
            cout << "在回家的路上,你突然明白了什么。你停下来,凝视着方太阳。" << endl;
            cout << "“我觉醒了。”你自言自语。" << endl;
            finalEndingName = "轮回觉醒";
            gameOver = true;
            return;
        }
        gameOver = true;
    }
}

// ==================== 主函数 ====================

int main() {
    srand(static_cast<unsigned>(time(0)));

    while (!gameOver) {
        newCycle();
        if (gameOver) break;
        processLocation();
        if (gameOver) {
            if (!mainEndingTriggered && finalEndingName.empty()) {
                cycleDays++;
                if (itemsThisCycle == 0) noItemCycles++;
                else noItemCycles = 0;
                if (noItemCycles >= 10) {
                    finalEndingName = "迷失轮回";
                    gameOver = true;
                } else {
                    gameOver = false;
                }
            }
        }
    }

    cout << "\n================================" << endl;
    cout << "You are the player. Wake Up." << endl;
    cout << "================================" << endl;

    cout << "========== 世界背景 ==========" << endl;
    cout << "这里是由蓝色空间号找到的宜居星球发展而来的世界。"
         << "由于初期人口不足,人类研发了一套虚拟世界系统。"
         << "父母可以陪刚出生的孩子在其中度过三天,孩子便会成长到18岁,"
         << "而父母的生理年龄只增长一年,但精神上却真实经历了十八年。"
         << endl;

    cout << "========== 游戏结算 ==========" << endl;
    cout << "结局:" << finalEndingName << endl;
    cout << "循环天数:" << cycleDays << endl;
    cout << "作出选择的次数:" << totalChoices << endl;
    cout << "总共显示乱码数:" << totalGlitches << endl;
    cout << "获得U盘总数:" << totalItems << endl;

    double base = computeBaseScore();
    double finalScore = base;
    if (finalEndingName == "轮回觉醒") finalScore = base + (MAX_SCORE - base) * 0.1;
    else if (finalEndingName == "小游戏之王") finalScore = base + (MAX_SCORE - base) * 0.05;
    else if (finalEndingName == "规则解析者") finalScore = base + (MAX_SCORE - base) * 0.08;
    else if (finalEndingName == "与学长共存") finalScore = base + (MAX_SCORE - base) * 0.03;
    else if (finalEndingName == "第四面墙") finalScore = MAX_SCORE;
    else if (finalEndingName == "迷失轮回") finalScore = base - (base - MIN_SCORE) * 0.5;
    else if (finalEndingName == "规则破坏者") finalScore = base - (base - MIN_SCORE) * 0.8;

    if (finalScore < MIN_SCORE) finalScore = MIN_SCORE;
    if (finalScore > MAX_SCORE) finalScore = MAX_SCORE;

    cout.precision(2);
    cout << fixed;
    cout << "评分:" << finalScore << " (";
    if (finalScore < 5.0) cout << "F";
    else if (finalScore < 7.0) cout << "D";
    else if (finalScore < 9.0) cout << "C";
    else if (finalScore < 11.0) cout << "B";
    else if (finalScore < 12.5) cout << "A";
    else cout << "SSS";
    cout << ")" << endl;

    cout << "感谢游玩!" << endl;

    // ========== 通关后菜单 ==========
    cout << "\n========== 通关后菜单 ==========" << endl;
    bool afterEnd = true;
    while (afterEnd) {
        cout << "1. 退出" << endl;
        cout << "2. 观看所有文字部分源码" << endl;
        cout << "请选择: ";
        int ch;
        cin >> ch;
        if (ch == 1) {
            afterEnd = false;
        } else if (ch == 2) {
            // 显示所有原始文本(无乱码)
            cout << "\n========== 所有文字源码 ==========" << endl;
            cout << "规则I(简体)原文:" << endl;
            cout << "1. 机房里的16台电脑,编号从A1到D4,其中有一台是陷阱,如果你使用它,你的意识将被永久锁定。" << endl;
            cout << "2. 数字4444是世界的禁忌。如果你在任何屏幕上看到它,必须立刻闭上眼,从1数到4,再睁开。否则你会迷失在数字的循环中。" << endl;
            cout << "3. 机房中严禁插入任何外接存储设备。若你插入U盘,系统会识别为入侵,你将立即被强制下线(死亡)。" << endl;
            cout << "4. 机房墙上的时钟永远指向4:44,那是一个警告——在4:44时,你必须离开机房,否则你会被永远困在那个时刻。" << endl;
            cout << "5. 那些闪烁的代码是系统的呼吸,不要去解读它们。你看得越久,它们就越会侵入你的思维,让你忘记自己是谁。" << endl;
            cout << "\n规则II(繁体)原文:" << endl;
            cout << "1. 16台電腦中,有一台需要投入一枚刻著「4」的硬幣。投入後輸入「4444」,它會告訴你一個祕密——你已經輪迴了多少次。" << endl;
            cout << "2. (第一條)有兩台電腦與時間有關:一台永遠顯示4:44,那是世界的錨點;另一台在整點時會出現我的虛影,那是我在提醒你「時間不多了」。" << endl;
            cout << "2. (第二條)那些看似無用的程式碼其實隱藏著線索。仔細看,它們或許會告訴你下一個目的地。" << endl;
            cout << "3. 你需要找到兩個空的U盤——一個在食堂(活著拿到它),一個在教室(答對10題拿到它)。然後回到機房,找到那台等待你的電腦(編號隨機),同時插入兩個U盤,你會見到我。" << endl;
            cout << "4. 機房裡有四台電腦貼著規則或藏著紙條,把它們全部找到,你就能拼湊出這個世界的真相。" << endl;
            cout << "5. 本規則共5條,但編號2使用了兩次,所以實際有6條。記住,那些小遊戲電腦只是為了讓你放鬆,真正的出口不在那裡。" << endl;
            cout << "\n规则III原文:" << RULE_III << endl;
            cout << "\n食堂规则原文:" << CANTEEN_RULE << endl;
            cout << "\n父母话语原文:要离开了,好好再看看这个世界吧。" << endl;
            cout << "\n电脑描述模板(部分):" << endl;
            cout << "- 开机代码刷屏:屏幕不断刷新着乱码,偶尔闪过一行字:cycleDays=?" << endl;
            cout << "- 学长日志:屏幕上显示着学长留下的日志..." << endl;
            cout << "- 倒计时:倒计时:距离系统重置 xx 秒" << endl;
            cout << "- 硬币电脑:这台电脑有一个硬币投入口。" << endl;
            cout << "- 学长电脑:这台电脑看起来与众不同,屏幕上有一个闪烁的光标。" << endl;
            cout << "- 隐藏规则1:禁止携带食物进入机房,违者死亡。" << endl;
            cout << "- 隐藏规则2:真正的规则在你们自己手中。" << endl;
            cout << "- 隐藏规则3:不要看镜子里的自己超过4秒。" << endl;
            cout << "- 隐藏规则4:如果你看到这个,说明你已经轮回太多次了。" << endl;
            cout << "- 时间电脑1:屏幕上显示着一个始终指向4:44的时钟。" << endl;
            cout << "- 时间电脑2:屏幕上显示着当前时间,整点时出现虚影“时间不多了”" << endl;
            cout << "- 代码展示:一段C++ Hello World代码" << endl;
            cout << "- 小游戏电脑:这是一台游戏电脑。" << endl;
            cout << "====================" << endl;
        } else {
            cout << "无效选择。" << endl;
        }
    }

    return 0;
}