1. 游戏简介
Game Overview(游戏简介)
这是一款运行在 Windows 终端窗口中的黑客攻防小游戏。玩家扮演系统防御者,在黑客不断发起入侵攻击时,通过输入正确的防御指令来阻止攻击、修复系统漏洞。游戏采用经典的琥珀绿(Amber Green)终端配色,营造复古黑客氛围。
This is a hacker defense mini-game running in a Windows terminal window. The player acts as a system defender, typing correct defense commands to block hacker attacks and repair system vulnerabilities. The game uses the classic amber-green terminal color scheme to create a retro hacker atmosphere.
2. 运行环境与准备
Environment & Preparation(运行环境与准备)
本游戏使用 C++ 编写,基于 Windows 控制台 API(windows.h),无需安装第三方库,在中国境内可直接编译运行。推荐使用 Visual Studio 或 MinGW-w64(g++)进行编译。
This game is written in C++ and based on the Windows Console API (windows.h). No third-party libraries are required, and it can be compiled and run directly in China. Visual Studio or MinGW-w64 (g++) is recommended.
编译命令(MinGW):
g++ -o hacker_defense hacker_defense.cpp -static -mwindowsCompile command (MinGW):
3. 完整源代码
Full Source Code(完整源代码)
以下是完整的 C++ 源代码,复制后保存为 hacker_defense.cpp 即可编译运行。
The complete C++ source code is below. Save it as hacker_defense.cpp and compile.
#include <windows.h> #include <iostream> #include <string> #include <vector> #include <ctime> #include <cstdlib> // 控制台颜色:琥珀绿 const int AMBER_GREEN = 10; // 亮绿色 const int DARK_GREEN = 2; // 暗绿色 const int RED = 12; // 红色(警告) // 设置控制台颜色 void setColor(int color) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color); } // 居中输出 void centerText(const std::string& text) { HANDLE h = GetStdHandle(ST