#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <sstream>
#include <iomanip>
#include <conio.h>
#include <windows.h>
#include <thread>
#include <chrono>
using namespace std;
using namespace chrono;
// 控制台颜色设置
void setColor(int color) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}
void goTo(int x, int y) {
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
// 优化后的 slowPrint: 打印完后自动停顿
void slowPrint(const string& text, int char_delay_ms = 40, int end_pause_ms = 600) {
for(char c : text) {
cout << c;
cout.flush();
// 遇到换行符可以稍微多停一点点,或者保持原样
if(c == '\n') {
this_thread::sleep_for(milliseconds(char_delay_ms * 2));
} else {
this_thread::sleep_for(milliseconds(char_delay_ms));
}
}
// 【关键修改】整段话打印完后,额外停顿一段时间,让玩家阅读
this_thread::sleep_for(milliseconds(end_pause_ms));
}
class CipherGame {
private:
int stage;
int score;
map<string, bool> discoveredClues;
vector<string> inventory;
bool gameOver;
string playerName;
string playerRealName;
public:
CipherGame() : stage(1), score(0), gameOver(false) {}
void displayHeader() {
system("cls"); // 清屏
setColor(14); // 黄色
cout << "\n" << string(60, '=') << endl;
setColor(15); // 白色
cout << " 时间之谜 - 解密冒险游戏" << endl;
setColor(14); // 黄色
cout << string(60, '=') << endl;
setColor(10); // 绿色
cout << "玩家: " << playerName << " | 分数: " << score << " | 阶段: " << stage << endl;
setColor(11); // 青色
cout << "背包: ";
if(inventory.empty()) {
cout << "(空)";
} else {
for(const auto& item : inventory) {
cout << "[" << item << "] ";
}
}
cout << endl << string(60, '-') << endl;
setColor(7); // 默认白色
}
void showIntro() {
system("cls");
// 建议在游戏开始时设置编码,以支持中文显示(如果在中文Windows下运行)
// system("chcp 65001 > nul");
setColor(13); // 紫色
slowPrint("\n\n", 0, 200);
slowPrint("███████╗██╗ ██╗██████╗ ███████╗██████╗ ██████╗ ██╗ ██╗███████╗███████╗██████╗ \n", 10, 300);
slowPrint("██╔════╝╚██╗ ██╔╝██╔══██╗██╔════╝██╔══██╗ ██╔══██╗╚██╗ ██╔╝██╔════╝██╔════╝██╔══██╗\n", 10, 300);
slowPrint("█████╗ ╚████╔╝ ██████╔╝█████╗ ██████╔╝ ██████╔╝ ╚████╔╝ █████╗ █████╗ ██████╔╝\n", 10, 300);
slowPrint("██╔══╝ ╚██╔╝ ██╔═══╝ ██╔══╝ ██╔══██╗ ██╔══██╗ ╚██╔╝ ██╔══╝ ██╔══╝ ██╔══██╗\n", 10, 300);
slowPrint("███████╗ ██║ ██║ ███████╗██║ ██║ ██████╔╝ ██║ ███████╗███████╗██║ ██║\n", 10, 300);
slowPrint("╚══════╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚══════╝╚══════╝╚═╝ ╚═╝\n", 10, 800);
setColor(14); // 黄色
slowPrint("\n\n 欢迎来到时间之谜\n", 50, 1000);
setColor(7); // 默认白色
slowPrint("\n在遥远的未来,时间本身成为了最珍贵的资源。", 40);
slowPrint("\n一位古老的智者留下了关于时间本质的秘密,", 40);
slowPrint("\n只有真正的解谜者才能揭开时间的终极奥秘。", 40);
slowPrint("\n\n你将踏上一段穿越时空的旅程,寻找失落的知识碎片...", 40);
slowPrint("\n\n按任意键开始你的旅程...", 40, 1000); // 这里停顿久一点等待按键
_getch();
}
void getPlayerName() {
system("cls");
setColor(11);
slowPrint("\n请输入你的姓名: ", 50, 500);
setColor(7);
getline(cin, playerName);
if(playerName.empty()) playerName = "无名旅者";
slowPrint("\n你好,", 40);
setColor(14);
slowPrint(playerName, 40);
setColor(7);
slowPrint("。愿你在时间的长河中找到真相。", 40, 1000);
_getch();
}
string caesarCipher(const string& text, int shift, bool encrypt = true) {
string result = "";
int direction = encrypt ? 1 : -1;
for(char c : text) {
if(isalpha(c)) {
char base = islower(c) ? 'a' : 'A';
// 处理负数取模的情况
int offset = (c - base + direction * shift) % 26;
if(offset < 0) offset += 26;
result += char(offset + base);
} else {
result += c;
}
}
return result;
}
string reverseString(const string& str) {
string reversed = str;
reverse(reversed.begin(), reversed.end());
return reversed;
}
void stage1() {
system("cls");
displayHeader();
slowPrint("\n【第一阶段:时间图书馆】", 40, 800);
slowPrint("\n你缓缓推开厚重的橡木门,进入了传说中的时间图书馆。", 40);
slowPrint("\n书架直冲云霄,无数典籍散发着古老的气息。", 40);
slowPrint("\n空气中弥漫着羊皮纸和墨水的味道,仿佛时间在此凝固。", 40);
slowPrint("\n\n突然,一本书自动翻开,显现出一段神秘文字:", 40);
string cipherText = "Wklv lv d whvw ri brxu delolwb wr xqghuvwdqg wkh odqjxdjh ri wlph.";
setColor(12); // 红色
slowPrint("\n\"" + cipherText + "\"", 60, 1000);
setColor(7); // 默认白色
slowPrint("\n\n你感到一阵眩晕,仿佛文字在眼前跳动。", 40);
slowPrint("\n一个苍老的声音在你耳边响起:", 40);
slowPrint("\n\"年轻人,这是时间守护者留下的第一个考验。", 40);
slowPrint("\n凯撒曾经说过,当数字为3时,真理显现。\"", 40, 800);
slowPrint("\n\n请输入你解密后得到的内容: ", 40, 500);
string answer;
getline(cin, answer);
// 【修复BUG】这里应该是将明文加密得到密文,或者直接定义明文作为正确答案
// 之前的逻辑是:对明文进行"解密"操作,导致答案错误。
// 正确逻辑:玩家输入的是解密后的结果,所以 expected 应该是明文。
string expected = "This is a test of your ability to understand the language of time.";
// 简单的清洗输入,去除首尾空格(可选)
// answer.erase(0, answer.find_first_not_of(" \n\r\t"));
// answer.erase(answer.find_last_not_of(" \n\r\t") + 1);
if(answer == expected) {
score += 100;
discoveredClues["first_cipher"] = true;
inventory.push_back("时间语言入门");
setColor(10); // 绿色
slowPrint("\n\n解密成功!图书馆深处传来一声赞叹。", 40);
slowPrint("\n一本名为「时间语言入门」的书籍飞到你手中。", 40);
slowPrint("\n你感受到一股温暖的能量流过全身,仿佛觉醒了某种能力。", 40);
slowPrint("\n原来时间也有自己的语言...而你已经开始理解它。", 40, 1000);
setColor(7);
} else {
setColor(12); // 红色
slowPrint("\n\n解密失败。", 40);
slowPrint("\n苍老的声音叹息道:\"还需要更多的历练啊...\"", 40);
slowPrint("\n答案是: ", 40);
setColor(14);
slowPrint(expected, 40, 1500);
setColor(7);
}
slowPrint("\n\n按任意键继续你的旅程...", 40, 500);
_getch();
}
void stage2() {
system("cls");
displayHeader();
slowPrint("\n【第二阶段:镜像迷宫】", 40, 800);
slowPrint("\n一道光门在你面前开启,你踏入其中。", 40);
slowPrint("\n四周全是镜子,每一面镜子都反射出不同的景象。", 40);
slowPrint("\n有时是你现在的样子,有时是过去的记忆,有时是未来的幻象。", 40);
slowPrint("\n\n突然,一面特殊的镜子亮起,上面浮现出倒序的文字:", 40);
string mirrorText = "yenruoj si eman ym";
setColor(12);
slowPrint("\n\"" + mirrorText + "\"", 60, 1000);
setColor(7);
slowPrint("\n\n镜中出现了另一个你,微笑着说:", 40);
slowPrint("\n\"逆转即是真相,真相需要逆转来看。\"", 40, 800);
slowPrint("\n\n请输入你看到的原文: ", 40, 500);
string answer;
getline(cin, answer);
string expected = "my name is journey";
// 忽略大小写比较
string lowerAnswer = answer;
string lowerExpected = expected;
transform(lowerAnswer.begin(), lowerAnswer.end(), lowerAnswer.begin(), ::tolower);
transform(lowerExpected.begin(), lowerExpected.end(), lowerExpected.begin(), ::tolower);
if(lowerAnswer == lowerExpected) {
score += 150;
discoveredClues["mirror_clue"] = true;
inventory.push_back("镜像真理");
setColor(10);
slowPrint("\n\n镜子发出柔和的光芒,你的名字被确认。", 40);
slowPrint("\n一本名为「镜像真理」的水晶册出现在你面前。", 40);
slowPrint("\n当你触摸它时,感觉到了另一个自己的存在。", 40);
slowPrint("\n原来这就是你的真名...旅程(Journey)。", 40);
slowPrint("\n你意识到,每个人都是时间长河中的一段旅程。", 40, 1000);
setColor(7);
} else {
setColor(12);
slowPrint("\n\n镜中的你摇了摇头。", 40);
slowPrint("\n答案是: ", 40);
setColor(14);
slowPrint(expected, 40, 1500);
setColor(7);
}
slowPrint("\n\n按任意键继续...", 40, 500);
_getch();
}
void stage3() {
system("cls");
displayHeader();
slowPrint("\n【第三阶段:数字哲学】", 40, 800);
slowPrint("\n你来到一个纯白的空间,墙壁上浮现出三个数字序列。", 40);
slowPrint("\n这里寂静无声,只有数字的韵律在空气中流淌。", 40);
slowPrint("\n\n左侧墙面显示:", 40);
setColor(12);
slowPrint("\n序列A: 1, 1, 2, 3, 5, 8, 13, ?", 40);
setColor(7);
slowPrint("\n中间墙面显示:", 40);
setColor(12);
slowPrint("\n序列B: 2, 4, 8, 16, 32, ?", 40);
setColor(7);
slowPrint("\n右侧墙面显示:", 40);
setColor(12);
slowPrint("\n序列C: 1, 4, 9, 16, 25, ?", 40, 800);
setColor(7);
slowPrint("\n\n空间中央出现了一位身穿星袍的智者:", 40);
slowPrint("\n\"数字是宇宙的基石,也是时间的密码。", 40);
slowPrint("\nA序列体现了生命的增长模式,", 40);
slowPrint("\nB序列展现了能量的倍增规律,", 40);
slowPrint("\nC序列揭示了空间的扩张法则。\"", 40, 800);
slowPrint("\n\n请输入三个空缺数字,用逗号分隔 (例如: 21,64,36): ", 40, 500);
string input;
getline(cin, input);
vector<int> answers;
stringstream ss(input);
string token;
while(getline(ss, token, ',')) {
try {
// 去除空格
token.erase(remove_if(token.begin(), token.end(), ::isspace), token.end());
if(!token.empty())
answers.push_back(stoi(token));
} catch(...) {
answers.push_back(-1);
}
}
bool correct = answers.size() == 3 && answers[0] == 21 && answers[1] == 64 && answers[2] == 36;
if(correct) {
score += 200;
discoveredClues["number_sequence"] = true;
inventory.push_back("数学真理");
setColor(10);
slowPrint("\n\n智者的脸上露出欣慰的笑容。", 40);
slowPrint("\n\"你理解了宇宙的基本语言!\"", 40);
slowPrint("\n一本闪闪发光的「数学真理」悬浮到你面前。", 40);
slowPrint("\n数字是宇宙的语言,也是时间的密码...", 40);
slowPrint("\n你感觉自己与宇宙的脉动产生了共鸣。", 40, 1000);
setColor(7);
} else {
setColor(12);
slowPrint("\n\n智者轻轻摇头:", 40);
slowPrint("\n\"还需要更深的理解...正确答案是: 21, 64, 36\"", 40);
slowPrint("\nA是斐波那契数列的延续,B是2的幂次方,C是自然数的平方。", 40, 1500);
setColor(7);
}
slowPrint("\n\n按任意键继续...", 40, 500);
_getch();
}
void stage4() {
system("cls");
displayHeader();
slowPrint("\n【第四阶段:时间悖论】", 40, 800);
slowPrint("\n你发现自己站在一个无限延伸的时间回廊中。", 40);
slowPrint("\n过去、现在、未来的影像在空中交织。", 40);
slowPrint("\n你看到自己在不同时间点的生活片段。", 40);
slowPrint("\n\n突然,一个身影从时间迷雾中走出——那是时间守护者本人。", 40);
slowPrint("\n他有着无数张面孔,每一张都代表着不同的时代。", 40, 800);
slowPrint("\n\n守护者开口说道:", 40);
setColor(12);
slowPrint("\n\"如果时间旅行者回到过去杀死了自己的祖父,", 40);
slowPrint("\n那么时间旅行者还会存在吗?\"", 40, 1000);
setColor(7);
slowPrint("\n\n选项:", 40);
slowPrint("\nA) 时间旅行者不存在,因为祖父已死", 40);
slowPrint("\nB) 时间旅行者仍然存在,创造了平行宇宙", 40);
slowPrint("\nC) 时间线自我修正,阻止了悖论发生", 40);
slowPrint("\nD) 以上都有可能,取决于时间理论", 40, 800);
slowPrint("\n\n请选择你的答案 (A/B/C/D): ", 40, 500);
char choice;
cin >> choice;
cin.ignore(1000, '\n'); // 清除缓冲区,包括换行符
if(tolower(choice) == 'd') {
score += 250;
discoveredClues["paradox_solution"] = true;
inventory.push_back("时间哲学");
setColor(10);
slowPrint("\n\n时间守护者的多张面孔同时微笑。", 40);
slowPrint("\n\"智慧的年轻人,你理解了时间的多维本质。\"", 40);
slowPrint("\n一本古老的「时间哲学」飘到你手中。", 40);
slowPrint("\n你感受到了时间的无限可能性在你心中展开。", 40, 1000);
setColor(7);
} else {
setColor(12);
slowPrint("\n\n守护者的眼神变得深邃:", 40);
slowPrint("\n\"答案不够全面。", 40);
slowPrint("\n在量子力学中,多重宇宙理论认为所有可能性都存在。", 40);
slowPrint("\n时间并非单一路径,而是多重现实的集合。\"", 40, 1500);
setColor(7);
}
slowPrint("\n\n按任意键继续...", 40, 500);
_getch();
}
void finalStage() {
system("cls");
displayHeader();
slowPrint("\n【最终阶段:时间的核心】", 40, 800);
slowPrint("\n经过重重考验,你终于来到了时间的核心。", 40);
slowPrint("\n这里没有空间的概念,只有纯粹的时间流动。", 40);
slowPrint("\n所有你经历过的阶段都在这里汇聚。", 40, 800);
slowPrint("\n\n古老智者的全息影像出现在你面前:", 40);
setColor(12);
// 为了演示效果,这里不逐字打印超长乱码,直接显示
cout << "\n\"AIEMKJCXIJKIHXBIGIQHKIAKLMIBHIJIPJJTIULIKIMIJQIHLIRQHPSXNMQSPBMZVIEIREPBICIRGVLIYIORHGRCRVHGBRQIHZREVJYQIHGKYQIHOIVFADRBILVJHQIVAXLIBKJIJBRQIHLIRVYKBQLYQIRGRQIOVHBRQIHRLQBIBGVHQRHVHQIBGQIHRLQIBQIHRLQIBGHVHRQI\"" << endl;
setColor(7);
this_thread::sleep_for(milliseconds(1000)); // 长串字符后停顿
slowPrint("\n\n智者的声音回响在整个空间:", 40);
slowPrint("\n\"这是时间的终极密码,融合了所有你学到的知识。", 40);
slowPrint("\n第一阶段教你凯撒密码,", 40);
slowPrint("\n第二阶段教你逆向思维,", 40);
slowPrint("\n第三阶段教你数学规律,", 40);
slowPrint("\n第四阶段教你哲学思辨。", 40);
slowPrint("\n现在,将它们结合,揭示时间的终极秘密。\"", 40, 1000);
slowPrint("\n\n提示:答案是一句英文,包含 'time' 和 'simultaneously'。", 40);
slowPrint("\n请输入解密后的内容: ", 40, 500);
string answer;
getline(cin, answer);
transform(answer.begin(), answer.end(), answer.begin(), ::tolower);
// 简化判定:只要包含关键词即可
if(answer.find("time") != string::npos &&
answer.find("simultaneously") != string::npos) {
score += 500;
setColor(10);
slowPrint("\n\n时间核心开始发光,整个空间被温暖的光芒包围。", 40);
slowPrint("\n智者的影像变得更加清晰:", 40);
slowPrint("\n\n\"你成功了!你理解了时间的真正本质:", 40);
slowPrint("\n时间不是一个流动的河流,而是一个海洋,在其中所有时刻同时存在。", 40);
slowPrint("\n过去、现在、未来都是永恒的瞬间,相互交织成存在的织锦。\"", 40);
slowPrint("\n\n你已经成为时间的大师!", 40, 1000);
setColor(14);
slowPrint("\n\n★★★ 恭喜你完成了时间之谜! ★★★", 40, 1000);
setColor(7);
} else {
setColor(12);
slowPrint("\n\n智者点了点头:", 40);
slowPrint("\n\"虽然未能完全解开终极密码,但你已经掌握了时间的片段知识。", 40);
slowPrint("\n真正的答案是:Time exists simultaneously in an ocean of moments.", 40);
slowPrint("\n继续探索吧,时间的奥秘无穷无尽。\"", 40, 1500);
setColor(7);
}
slowPrint("\n\n按任意键查看结局...", 40, 500);
_getch();
}
void showEnding() {
system("cls");
setColor(13);
slowPrint("\n\n", 0, 200);
slowPrint("╔════════════════════════════════════════════════════════════════════════════╗\n", 20);
slowPrint("║ 最终结局 ║\n", 20);
slowPrint("╚════════════════════════════════════════════════════════════════════════════╝\n", 20, 800);
setColor(14);
slowPrint("\n玩家: ", 30);
setColor(15);
cout << playerName;
setColor(14);
slowPrint("\n总分: ", 30);
setColor(15);
cout << score;
setColor(14);
slowPrint("\n完成阶段: ", 30);
setColor(15);
cout << stage-1 << "/5";
setColor(14);
slowPrint("\n收集物品: ", 30);
setColor(15);
if(inventory.empty()) cout << "无";
for(size_t i=0; i<inventory.size(); ++i) {
cout << inventory[i];
if(i < inventory.size()-1) cout << ", ";
}
cout << endl;
setColor(7);
slowPrint("\n\n", 0, 500);
if(score >= 800) {
setColor(10);
slowPrint("你成功解开了时间的终极秘密,成为了时间的大师!", 40);
slowPrint("\n在时间的海洋中,你看到了所有可能性的交汇点。", 40);
slowPrint("\n过去、现在、未来融为一体,你获得了洞察一切的智慧。", 40);
slowPrint("\n时间的长河因你的智慧而为你歌唱...", 40, 1000);
} else if(score >= 400) {
setColor(11);
slowPrint("你部分解开了时间的秘密,获得了宝贵的知识。", 40);
slowPrint("\n虽然未能完全掌握时间的本质,但你已经超越了普通人的认知。", 40);
slowPrint("\n时间的智慧将在你心中继续成长...", 40, 1000);
} else {
setColor(12);
slowPrint("你经历了时间的考验,但仍有更多秘密等待探索。", 40);
slowPrint("\n时间的奥秘深不可测,需要更多的智慧和勇气。", 40);
slowPrint("\n但你的旅程已经开始了,继续前行吧...", 40, 1000);
}
setColor(14);
slowPrint("\n\n感谢你体验《时间之谜》解密游戏!", 40);
slowPrint("\n愿你在真实的时间长河中也能找到属于自己的答案。", 40, 1000);
setColor(7);
slowPrint("\n\n按任意键退出...", 40, 500);
_getch();
}
void play() {
showIntro();
getPlayerName();
stage1(); stage++; if(gameOver) return;
stage2(); stage++; if(gameOver) return;
stage3(); stage++; if(gameOver) return;
stage4(); stage++; if(gameOver) return;
finalStage(); stage++;
showEnding();
}
};
int main() {
// 设置控制台输出编码为UTF-8,防止中文乱码
// system("chcp 65001 > nul");
CipherGame game;
game.play();
return 0;
}剪贴板
剪贴板 iyskl83k
剪贴板信息
剪贴板信息
- 收录
- 更新