我连夜爆肝写代码
终于,反应大师2.0写好了!
本次更新了单人模式(听到嘀嘀嘀时要按S键),
可以进行刷记录,
但是,退出尽量要按照正确方式(在主界面按3)哦!
不然,你的记录不能保存了!
话不多说,上代码:
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int main()
{
long double min=1000000000,cj;
ifstream a("cj.binggan");
a>>min;
a.close();
srand(time(0));
system("mode con cols=30 lines=10");
system("color 2a");
while(1)
{
system("color 2a");
system("cls");
cout<<"反应大师\n\n1.单人 2.双人 3.退出";
char s;
s=getch();
while(s!='1'&&s!='2'&&s!='3')s=getch();
system("cls");
if(s=='1')
{
bool f=1,zb=0;
long long n=rand()%10+1;
for(long long i=1;i<=n*50;i++)
{
if(GetKeyState('S')<0)
{
cout<<"不能作弊哦!\n";
cout<<"按空格继续";
s=getch();
while(s!=' ')s=getch();
system("cls");
f=0;
zb=1;
break;
}
Sleep(1);
}
cj=clock();
while(f)
{
Beep(1000,10);
if(GetKeyState('S')<0)
{
f=0;
break;
}
}
cj=(clock()-cj)/1000.0;
system("cls");
if(cj==min&&!zb)
{
cout<<"你现在的成绩和你的最高成绩一样都是"<<min;
cout<<"秒";
}
else
if(cj<min&&!zb)
{
cout<<"你刷新了你的记录!!!\n";
cout<<"最高记录刷新为"<<cj;
cout<<"秒";
min=cj;
}
else
if(!zb)
{
cout<<"你现在的成绩差最高成绩"<<cj-min<<"\n";
cout<<"成绩:"<<cj;
cout<<"秒";
}
if(!zb)
{
cout<<"\n\n\n按空格继续";
s=getch();
while(s!=' ')s=getch();
}
}
else
if(s=='2')
{
bool f,b=1,a=0;
long long n=rand()%10+1;
for(long long i=1;i<=n*50;i++)
{
if(GetKeyState('S')<0)
{
cout<<"玩家1作弊了!!!\n\n\n";
cout<<"按空格继续";
s=getch();
while(s!=' ')s=getch();
b=0;
a=1;
break;
}
if(GetKeyState(40)<0)
{
cout<<"玩家2作弊了!!!\n\n\n";
cout<<"按空格继续";
s=getch();
while(s!=' ')s=getch();
b=0;
a=1;
break;
}
Sleep(1);
}
while(b)
{
Beep(1000,10);
if(GetKeyState('S')<0)
{
b=0;
f=1;
break;
}
if(GetKeyState(40)<0)
{
b=0;
f=0;
break;
}
}
if(f&&!a)
{
system("color 19");
cout<<"玩家1赢了!!!";
cout<<"\n\n\n按空格继续";
s=getch();
while(s!=' ')s=getch();
}
else
if(!a)
{
system("color 4c");
cout<<"玩家2赢了!!!";
cout<<"\n\n\n按空格继续";
s=getch();
while(s!=' ')s=getch();
}
}
else
{
system("cls");
ofstream b("cj.binggan");
b<<min;
return 0;
}
}
return 0;
}
大家如果觉得我写得好
请点赞、收藏、关注我哦!