#include<iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
int flag,n,a,min,max;
while(1)
{
system("color f4");
system("cls");
min=-1;
max=101;
srand(time(NULL));
int ans=rand()%100+1;
cout<<"猜数字游戏"<<endl;
cout<<"是否开始玩此游戏,请输入选择序号"<<endl;
cout<<"1 确认 2 取消"<<endl;
cin>>flag;
if(flag==1)
{
cout<<"请输入你想玩的游戏难度序号"<<endl;
cout<<"1 无数条命"<<endl;
cout<<"2 6条命"<<endl;
cout<<"3 3条命"<<endl;
cin>>flag;
switch(flag)
{
case 1:
n=10;
break;
case 2:
n=6;
break;
case 3:
n=3;
break;
}
cout<<"开始游戏,游戏规则如下"<<endl;
cout<<"请输入1-100的数字"<<endl;
for(int i=n; i>=1; i--)
{
if(n==10)
{
i++;
}
else
{
cout<<"你还有"<<i<<"条命"<<endl;
}
cin>>a;
if(a>ans)
{
if(a<max) max=a;
cout<<"猜大了"<<endl;
}
else if(a<ans)
{
if(a>min) min=a;
cout<<"猜小了"<<endl;
}
else
{
cout<<"猜对了"<<endl;
break;
}
if(i==1)
{
cout<<"机会用完"<<endl;
}
cout<<"请重新猜,范围是"<<min<<"到"<<max<<"(不包括"<<min<<"和"<<max<<")"<<endl;
}
}
else if(flag==2)
{
break;
}
else
{
cout<<" 错误;"<<endl;
}
system("pause");
}
return 0;
}