类型:半转载(转载后进行增减)
转载于:???(不好意思忘记了)
理解难度:3
代码:
#include<bits/stdc++.h>
#include<stdlib.h>
#include<time.h>
using namespace std;
void Start();
void GetResults();
int i,j,life,maxrand;
char c;
void Start()
{
system("color fa");
int qw;
i=0;
j=0;
life=0;
maxrand=6;
cout<<setw(65)<<"选择难度\n"; // the user has to select a difficutly level
cout<<setw(73)<<"0 : 萌新专用 (范围0-5)\n";
cout<<setw(71)<<"1 : 简单 (范围0-15)\n";
cout<<setw(71)<<"2 : 中等 (范围0-30)\n";
cout<<setw(71)<<"3 : 困难 (范围0-50)\n";
cout<<setw(71)<<"4 : 炼狱 (范围0-80)\n";
cout<<setw(71)<<"5 : 终极 (范围0-100)\n";
cout<<setw(73)<<"6 : 无人能赢 (范围0-200)\n";
cout<<setw(76)<<"7 : 无法用语言形容 (范围0-500)\n";
cout<<setw(74)<<"8 : 惩罚用的 (范围0-1000)\n";
cout<<setw(73)<<"9 : 最难的 (范围0-5000)\n";
cout<<setw(87)<<"按1、2、3、4、5、6、7、8、9、0除外的键退出\n\n\n";
cout<<setw(70)<<"您现在在的地点:选择处\n\n";
c=30;
cin>>c; // read the user's choice
cout<<"\n";
switch(c)
{
case '0':
maxrand=5; // the random number will be between 0 and maxrand
system("cls");
cout<<"加载中…";
qw=0;
while(qw<=100000000){
qw++;
}
system("cls");
cout<<"加载完成!";
system("cls");
break;
case '1':
maxrand=15;
system("cls");
cout<<"加载中…";
qw=0;
while(qw<=100000000){
qw++;
}
system("cls");
cout<<"加载完成!";
system("cls");
break;
case '2':
maxrand=30;
system("cls");
cout<<"加载中…";
qw=0;
while(qw<=100000000){
qw++;
}
system("cls");
cout<<"加载完成!";
system("cls");
break;
case '3':
maxrand=50;
system("cls");
cout<<"加载中…";
qw=0;
while(qw<=100000000){
qw++;
}
system("cls");
cout<<"加载完成!";
system("cls");
break;
case '4':
maxrand=80;
system("cls");
cout<<"加载中…";
qw=0;
while(qw<=100000000){
qw++;
}
system("cls");
cout<<"加载完成!";
system("cls");
break;
case '5':
maxrand=100;
system("cls");
cout<<"加载中…";
qw=0;
while(qw<=100000000){
qw++;
}
system("cls");
cout<<"加载完成!";
system("cls");
break;
case '6':
maxrand=200;
system("cls");
cout<<"加载中…";
qw=0;
while(qw<=100000000){
qw++;
}
system("cls");
cout<<"加载完成!";
system("cls");
break;
case '7':
maxrand=500;
system("cls");
cout<<"加载中…";
qw=0;
while(qw<=100000000){
qw++;
}
system("cls");
cout<<"加载完成!";
system("cls");
break;
case '8':
maxrand=1000;
system("cls");
cout<<"加载中…";
qw=0;
while(qw<=100000000){
qw++;
}
system("cls");
cout<<"加载完成!";
system("cls"); // the random number will be between 0 and maxrand
break;
case '9':
maxrand=5000;
system("cls");
cout<<"加载中…";
qw=0;
while(qw<=100000000){
qw++;
}
system("cls");
cout<<"加载完成!";
system("cls"); // the random number will be between 0 and maxrand
break;
default:
system("cls");
cout<<"您现在在的地点:退出处";
exit(0);
break;
}
life=5; // number of lifes of the player
srand((unsigned)time(NULL)); // init Rand() function
j=rand()%maxrand; // j get a random value between 0 and maxrand
GetResults();
}
void GetResults()
{
if(life<=0)
{ // if player has no more life then he loses
cout<<"你输了!\n";
cout<<"正确数字是:"<<j<<"\n";
Start();
}
cout<<"请输入: ";
cin>>i;
if((i>maxrand)||(i<0))
{ // if the user number isn't correct, restart
cout<<"数字输入错误!"<<maxrand;
GetResults();
}
if(i==j)
{
cout<<"你赢了!\n\n"; // the user found the secret number
cout<<"正确数字就是:"<<j<<"\n";
Start();
}
else if(i>j)
{
cout<<"太大了\n";
life=life-1;
cout<<"剩余机会:"<<life<<"\n\n";
GetResults();
}
else if(i<j)
{
cout<<"太小了\n";
life=life-1;
cout<<"剩余机会: "<<life<<"\n\n";
GetResults();
}
}
int main()
{
cout<<"** 一个好玩的游戏 **\n";
cout<<"这个游戏的名字叫猜数字。\n";
cout<<"你要根据提示猜出数字。\n";
cout<<"你只有5次机会。\n";
cout<<"你要根据智商选择你要的等级。\n";
cout<<"最后一个选项特别难!\n\n";
Start();
return 0;
}