#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
void Start();
void GetResults();
int i, j, life, maxrand,mixrand;
char c;
void Start() {
i = 0;
j = 0;
life = 0;
maxrand = 6;
mixrand = 0;
cout << "请选择难度:\n";
cout << "1 : 简单 (0-120)\n";
cout << "2 : 一般 (0-105)\n";
cout << "3 : 普通 (0-90)\n";
cout << "4 : 中等 (0-75)\n";
cout << "5 : 偏难 (0-60)\n";
cout << "6 : 困难 (0-45)\n";
cout << "7 : 终极 (0-30)\n";
cout << "8 : 地狱 (0-15)\n";
cout << "输入其他内容则会退出\n";
c = 30;
cin >> c;
cout << "\n";
switch (c) {
case '8':
maxrand = 15;
break;
case '7':
maxrand = 30;
break;
case '6':
maxrand = 45;
break;
case '5':
maxrand = 60;
break;
case '4':
maxrand = 75;
break;
case '3':
maxrand = 90;
break;
case '2':
maxrand = 105;
break;
case '1':
maxrand = 120;
break;
default:
exit(0);
break;
}
life = 9+maxrand/15;
srand((unsigned)time(NULL));
j = rand() % (maxrand-2)+1;
GetResults();
}
void GetResults() {
if (life <= 0) {
cout << "恭喜你,你赢了!\n\n\n\n\n\n";
Start();
}
cout << "请输入数字: \n";
cin >> i;
if((i>=maxrand) || (i<=mixrand)) {
cout << "错误: 请输入"<<mixrand<<"到 " << maxrand<<"之间的数字\n";
GetResults();
}
if(i == j) {
cout << "很遗憾,你踩雷了!\n\n\n\n\n\n";
Start();
} else if(i>j) {
maxrand=i;
life = life - 1;
cout<<"请输入"<<mixrand<<"到 " << maxrand<<"之间的数字\n";
cout << "你还要走" << life << "步\n\n";
GetResults();
} else if(i<j) {
mixrand=i;
life = life - 1;
cout<<"请输入"<<mixrand<<"到 " << maxrand<<"之间的数字\n";
cout << "你还要走" << life << "步\n\n";
GetResults();
}
}
int main() {
cout << "** 杨式子工作室出品 **\n";
cout << "欢迎来到[扫雷]游戏。\n";
cout << "选择难度后,把数字告诉我,\n";
cout << "我会告诉你有没有踩雷哦!\n\n";
Start();
return 0;
}
希望对大家有所帮助!