#include <iostream>
#include <vector>
#include <map>
#include <cstdlib>
#include <ctime>
#include <limits>
#include <thread>
#include <chrono>
#include <fstream>
#include <string>
#include <algorithm>
using namespace std;
// ASCII艺术资源
const vector<string> TITLE_ART = {
"▓█████▄ ?█████ ███▄ ▄███▓ ██?███ ▄████▄ ▓█████ ██?███ ",
"?██? ██▌?██? ██?▓██??█? ██?▓██ ? ██??██? ?█ ▓█ ? ▓██ ? ██?",
"?██ █▌?██? ██?▓██ ▓██?▓██ ?▄█ ??▓█ ▄ ?███ ▓██ ?▄█ ?",
"?▓█▄ ▌?██ ██??██ ?██ ?██??█▄ ?▓▓▄ ▄██??▓█ ▄ ?██??█▄ ",
"??████▓ ? ████▓???██? ?██??██▓ ?██?? ▓███? ???████??██▓ ?██?",
" ??▓ ? ? ?????? ? ?? ? ?? ?▓ ??▓?? ?? ? ??? ?? ?? ?▓ ??▓?",
" ? ? ? ? ? ?? ? ? ? ?? ? ?? ? ? ? ? ? ?? ? ??",
" ? ? ? ? ? ? ? ? ? ?? ? ? ? ?? ? ",
" ? ? ? ? ? ? ? ? ? ? ",
" ? ? "
};
const vector<string> CAT_ART = {
" /\\_/\\ ",
"( o.o )",
" > ^ < "
};
const vector<string> RED_HAT_MAN = {
" _____",
" / \\",
" | O_O |",
" \\ ^ /",
" |||||",
" |||||"
};
const vector<string> MIRROR_SELF = {
" (@ @)",
" \\|/",
" |",
" / \\",
" / \\"
};
// 游戏状态结构体
struct GameState {
int sanity = 100;
int day = 1;
bool hasKey = false;
bool fedCat = false;
bool violatedRule = false;
bool knowsTruth = false;
map<string, bool> rulesBroken;
vector<string> knownRules;
vector<string> hiddenRules;
vector<string> inventory;
};
// 延迟打印函数
void delayPrint(const string& text, int delayMs = 30, bool newLine = true) {
for (char c : text) {
cout << c << flush;
this_thread::sleep_for(chrono::milliseconds(delayMs));
}
if (newLine) cout << endl;
}
// 清屏函数
void clearScreen() {
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}
// 显示ASCII艺术
void displayArt(const vector<string>& art) {
for (const auto& line : art) {
cout << line << endl;
}
}
// 显示标题画面
void displayTitle() {
clearScreen();
displayArt(TITLE_ART);
cout << "\n";
delayPrint("一座看似普通的公寓...隐藏着不为人知的规则...", 50);
cout << "\n";
}
// 初始化游戏规则
void initRules(GameState& state) {
state.knownRules = {
"1. 凌晨3:15不要回应任何敲门声",
"2. 电梯里出现戴红帽的人时,立即闭上眼睛数到10",
"3. 每周二必须喂食走廊的黑猫",
"4. 如果邻居向你借盐,拒绝并立即锁门",
"5. 不要相信镜子里的自己做出的不同动作",
"6. 发现规则自相矛盾时,优先遵守红色标记的规则",
"7. 每天检查冰箱里的食物数量,多出来的请立即丢弃",
"8. 不要试图寻找不存在的13楼"
};
state.hiddenRules = {
"9. 管理员只在夜间出现,白天见到的一律不是真正管理员",
"10. 如果看到窗外有月亮,无论实际时间,立即拉上窗帘",
"11. 收音机自动开启时,调频至103.7可获取安全时段",
"12. 发现规则第8条被划掉时,13楼确实存在且必须前往",
"13. 黑猫有时会说话,但只有说谎时才说真话",
"14. 你的记忆可能被修改过,不要完全信任日记内容",
"15. 公寓没有地下室,若发现地下室入口,不要进入但记住位置"
};
for (int i = 1; i <= 15; i++) {
state.rulesBroken["rule" + to_string(i)] = false;
}
}
// 显示规则
void displayRules(const GameState& state) {
clearScreen();
delayPrint("██████ 公寓管理规则 ██████", 50);
for (const auto& rule : state.knownRules) {
if (rule.find("红色标记") != string::npos) {
cout << "\033[31m"; // 红色
}
delayPrint(rule, 20);
if (rule.find("红色标记") != string::npos) {
cout << "\033[0m"; // 重置颜色
}
}
if (state.knowsTruth) {
delayPrint("\n=== 隐藏规则 ===", 50);
for (const auto& rule : state.hiddenRules) {
delayPrint(rule, 20);
}
}
cout << "\n按回车键继续...";
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin.get();
}
// 随机事件生成器
string randomEvent(GameState& state) {
vector<pair<string, function<void()>>> events = {
{"你听到走廊尽头传来婴儿哭声,但公寓里没有婴儿", [&](){ state.sanity -= 10; }},
{"电梯按钮上的数字正在缓慢变化", [&](){ state.sanity -= 15; }},
{"窗外有人影闪过,但你住在23楼", [&](){ state.sanity -= 12; }},
{"镜子里的你比现实慢了3秒", [&](){
state.sanity -= 20;
if (rand() % 100 < 30) {
delayPrint("镜子中的你突然笑了...", 50);
displayArt(MIRROR_SELF);
state.sanity -= 10;
}
}},
{"水龙头流出的水突然变成红色", [&](){ state.sanity -= 25; }},
{"电视机自动打开显示雪花画面", [&](){
state.sanity -= 15;
if (rand() % 100 < 20) {
delayPrint("雪花中隐约显示文字:逃...", 50);
state.sanity -= 10;
}
}},
{"手机收到来自自己的未发送短信", [&](){
state.sanity -= 18;
if (rand() % 100 < 40 && !state.knowsTruth) {
delayPrint("短信内容:规则9-15存在...寻找它们", 50);
state.knowsTruth = true;
}
}},
{"时钟突然快了2小时", [&](){ state.sanity -= 10; }},
{"闻到腐烂气味但找不到来源", [&](){ state.sanity -= 15; }},
{"所有电子设备同时显示3:15", [&](){
state.sanity -= 30;
if (rand() % 100 < 50) {
delayPrint("敲门声响起...", 50);
delayPrint("1. 不回应");
delayPrint("2. 询问是谁");
int choice;
cout << "选择: ";
cin >> choice;
if (choice == 2) {
delayPrint("\n门外传来:『终于找到你了...』");
delayPrint("门把手开始转动!");
state.rulesBroken["rule1"] = true;
state.sanity -= 40;
}
}
}},
{"发现墙上多了一扇之前不存在的门", [&](){
state.sanity -= 35;
delayPrint("门上有数字13...", 50);
delayPrint("1. 遵守规则不理会");
delayPrint("2. 尝试打开");
int choice;
cout << "选择: ";
cin >> choice;
if (choice == 2) {
if (any_of(state.knownRules.begin(), state.knownRules.end(),
[](const string& s){ return s.find("被划掉") != string::npos; })) {
delayPrint("\n你进入了13楼...发现真相!");
state.knowsTruth = true;
state.sanity = min(100, state.sanity + 30);
} else {
delayPrint("\n门后是无尽的黑暗...");
state.rulesBroken["rule8"] = true;
state.sanity -= 50;
}
}
}},
{"收音机自动开启,发出刺耳噪音", [&](){
state.sanity -= 15;
delayPrint("1. 关闭收音机");
delayPrint("2. 调频至103.7");
int choice;
cout << "选择: ";
cin >> choice;
if (choice == 2) {
delayPrint("\n收音机传出:'安全时段是每天的...'信号突然中断");
state.sanity += 10;
if (!state.knowsTruth) {
state.knownRules.push_back("16. 安全时段是每天上午10点到下午4点,此时异常较少");
}
}
}}
};
auto event = events[rand() % events.size()];
delayPrint("\n[发生事件] " + event.first);
event.second();
return event.first;
}
// 智能AI系统 - 公寓行为控制器
void apartmentAI(GameState& state) {
// 根据玩家状态调整事件概率
int anomalyChance = 30 + (100 - state.sanity) / 2;
anomalyChance = min(80, anomalyChance);
// 如果玩家快要发现真相,增加干扰
if (state.knowsTruth && !state.violatedRule) {
anomalyChance += 20;
}
// 如果玩家违反过规则,增加追击
for (const auto& rule : state.rulesBroken) {
if (rule.second) {
anomalyChance += 10;
}
}
// 特殊日期事件
if (state.day == 3) {
delayPrint("\n管理员留言:今天会有检查,请保持房间整洁...");
if (rand() % 100 < 60) {
delayPrint("你注意到留言的笔迹和你第一天看到的不同...");
state.sanity -= 15;
}
}
// 周二必须喂猫
if (state.day % 2 == 0 && !state.fedCat) {
delayPrint("\n黑猫在门外抓门,发出刺耳的声音...");
state.sanity -= 25;
state.rulesBroken["rule3"] = true;
}
}
// 游戏主循环
void playGame() {
srand(time(0));
GameState state;
initRules(state);
displayTitle();
delayPrint("管理员递给你一份规则手册后迅速离开,眼神闪烁...\n");
this_thread::sleep_for(chrono::seconds(2));
while (state.sanity > 0 && state.day <= 7 && !state.violatedRule) {
clearScreen();
delayPrint("═════════ 第 " + to_string(state.day) + " 天 ═════════", 50);
delayPrint("理智值: " + to_string(state.sanity) + "/100\n");
// 公寓AI控制事件
apartmentAI(state);
// 随机事件
if (rand() % 100 < 40 + (100 - state.sanity) / 5) {
randomEvent(state);
}
// 每日选择
delayPrint("\n你要做什么?");
delayPrint("1. 查看规则手册");
delayPrint("2. 检查冰箱");
delayPrint("3. 喂走廊的黑猫");
delayPrint("4. 使用电梯");
delayPrint("5. 检查窗外");
delayPrint("6. 留在房间休息");
int choice;
cout << "选择: ";
cin >> choice;
// 处理选择
switch (choice) {
case 1:
displayRules(state);
break;
case 2: {
int foodCount = 5 + rand() % 3;
delayPrint("\n冰箱里有 " + to_string(foodCount) + " 件食物");
if (foodCount > 7) {
delayPrint("发现多余食物!规则7要求丢弃...");
delayPrint("1. 遵守规则丢弃多余食物");
delayPrint("2. 留下食物(看起来很好吃)");
int subChoice;
cout << "选择: ";
cin >> subChoice;
if (subChoice == 2) {
delayPrint("\n你吃下了多余的食物...味道很奇怪");
state.rulesBroken["rule7"] = true;
state.sanity -= 30;
}
}
break;
}
case 3:
displayArt(CAT_ART);
if (state.day % 2 == 0) { // 周二和周四
delayPrint("\n黑猫满足地吃完了食物,发出呼噜声");
state.fedCat = true;
state.sanity += 15;
if (rand() % 100 < 20 && state.knowsTruth) {
delayPrint("黑猫突然说:'规则13是假的,就像我现在的这句话'");
state.sanity -= 20;
}
} else {
delayPrint("\n黑猫不理睬你的食物,冷冷盯着你");
state.sanity -= 10;
}
break;
case 4: {
delayPrint("\n电梯门缓缓打开...");
if (rand() % 100 < 30 + (100 - state.sanity) / 5) {
displayArt(RED_HAT_MAN);
delayPrint("里面站着一个戴红帽子的人!");
delayPrint("1. 遵守规则闭上眼睛数到10");
delayPrint("2. 直视他");
int subChoice;
cout << "选择: ";
cin >> subChoice;
if (subChoice == 1) {
delayPrint("\n你闭眼数到10...再睁开时电梯空了");
state.sanity += 5;
} else {
delayPrint("\n红帽人转向你:『你看得见我?』");
delayPrint("你的头痛欲裂!");
state.rulesBroken["rule2"] = true;
state.sanity -= 40;
}
} else {
delayPrint("电梯正常运转");
}
break;
}
case 5: {
delayPrint("\n你看向窗外...");
vector<string> views = {
"看到正常的城市景观",
"看到浓雾笼罩一切",
"看到另一个你正在窗外看着你",
"看到血红色的月亮"
};
string view = views[rand() % views.size()];
delayPrint(view);
if (view.find("月亮") != string::npos) {
delayPrint("1. 立即拉上窗帘");
delayPrint("2. 继续观察");
int subChoice;
cout << "选择: ";
cin >> subChoice;
if (subChoice == 2) {
delayPrint("\n月亮开始流血...");
state.rulesBroken["rule10"] = true;
state.sanity -= 35;
}
}
break;
}
case 6:
delayPrint("\n你在房间里休息,恢复了些许理智");
state.sanity += 20;
state.sanity = min(100, state.sanity);
break;
default:
delayPrint("\n无效选择");
}
// 检查规则违反
state.violatedRule = any_of(state.rulesBroken.begin(), state.rulesBroken.end(),
[](const pair<string, bool>& p){ return p.second; });
// 每日结束
if (!state.violatedRule && state.sanity > 0) {
delayPrint("\n夜幕降临...");
this_thread::sleep_for(chrono::seconds(1));
// 凌晨3:15事件
if (rand() % 100 < 40) {
delayPrint("\n[凌晨3:15] 突然的敲门声惊醒了你!");
delayPrint("1. 遵守规则不回应");
delayPrint("2. 询问是谁");
int subChoice;
cout << "选择: ";
cin >> subChoice;
if (subChoice == 2) {
delayPrint("\n门外传来:『终于找到你了...』");
delayPrint("门把手开始转动!");
state.rulesBroken["rule1"] = true;
state.sanity = 0;
}
}
state.day++;
state.fedCat = false; // 重置喂猫状态
}
}
// 游戏结局
clearScreen();
if (state.violatedRule) {
delayPrint("███ 结局:规则破坏者 ███", 50);
delayPrint("\n你违反了公寓的重要规则...");
delayPrint("现在它们知道你能看见它们了");
delayPrint("门锁自动打开的声音在黑暗中响起...\n");
} else if (state.sanity <= 0) {
delayPrint("███ 结局:理智丧失 ███", 50);
delayPrint("\n你的理智已经完全耗尽");
delayPrint("镜中的你微笑着伸出手...");
delayPrint("这次你没有抗拒\n");
} else if (state.knowsTruth) {
delayPrint("███ 结局:真相寻求者 ███", 50);
delayPrint("\n你发现了公寓隐藏的真相");
delayPrint("管理员递给你一把锈迹斑斑的钥匙:");
delayPrint("「现在你知道了...要留下还是离开?」\n");
} else {
delayPrint("███ 结局:幸存者 ███", 50);
delayPrint("\n你成功度过了7天并遵守了规则");
delayPrint("管理员递给你一把钥匙:");
delayPrint("「现在你可以离开了...或者留下来成为我们的一员」\n");
}
delayPrint("游戏结束", 100);
}
int main() {
srand(time(0));
while (true) {
displayTitle();
delayPrint("1. 开始游戏");
delayPrint("2. 退出");
int choice;
cout << "选择: ";
cin >> choice;
if (choice == 1) {
playGame();
cout << "按回车键返回主菜单...";
cin.ignore();
cin.get();
} else {
break;
}
}
delayPrint("再见...记得检查你家的规则手册", 50);
return 0;
}
c++规则怪谈游戏代码
最新推荐文章于 2025-10-17 21:23:12 发布
1089

被折叠的 条评论
为什么被折叠?



