Code:
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
void printColor(int color, char *str){
HANDLE hd=GetStdHandle(STD_OUTPUT_HANDLE);
switch(color){
case 1:
SetConsoleTextAttribute(hd,FOREGROUND_RED|FOREGROUND_INTENSITY);
break;
case 2:
SetConsoleTextAttribute(hd,FOREGROUND_GREEN|FOREGROUND_INTENSITY);
break;
case 3:
SetConsoleTextAttribute(hd,FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
break;
default:
SetConsoleTextAttribute(hd,FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
}
printf("%s",str);
}
void repeatPrint(int count, char *str){
int strl=strlen(str);
char *cstr=(char*)malloc(sizeof(char)*(strl+2));
sprintf(cstr, "%s\r", str);
if(count%4==0) count++;
for(int i=1;i<=count;i++){
printColor(i%4,cstr);
Sleep(1000);
}
printColor(4,"\n");
free(cstr);
}
void print(int n){
repeatPrint(n,"Press alphabets exam");
}
int main(){
system("color E0");
cout<<"\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\tloading...\n\n\n\t\t\t\tPlease press \"Caps Lock\"!(This program may get stuck.)";
Sleep(50);
system("color E2");
Sleep(2900);
system("color 80");
system("cls");
print(6);
srand(time(0));
system("cls");
system("color 3F");
for(int i=3;i>=0;i--){
cout<<"\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t"<<i<<"\n\n\n\t\t\t\t\t\tPlease no press now!\n";
Sleep(900);
system("color 32");
Sleep(100);
system("color 3F");
system("cls");
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0X3F);
int score=0,i=1;
char random,input,yr,I=1;
int randn;
string mark;
while(((double)clock()/CLOCKS_PER_SEC)<=214){
randn=rand()%128+1;
if(randn>=1&&randn<=5) random=32;
else random=rand()%26+65;
if(I==1)
printf("Now time have:200.000 second(s)\n");
else
printf("Now time have:%.3lf second(s)\n",214-(double)clock()/CLOCKS_PER_SEC);
if(random==32)
printf("Letter:%c(Space)",random);
else
printf("Letter:%c",random);
printf("\nNow Score:%d\n",score);
yr=random;
input=getch();
if(input==random){
score+=100;
printf("You\'re right! Score is %d!\n",score);
Sleep(50);
}
while(input!=random){
if(i==1)
printf("Error! Score is %d!\n",score-50);
score-=50;
input=getch();
if(input!=random)
printf("Error! Score is %d!\n",score-50);
Sleep(50);
i++;
}
system("cls");
I++;i=0;
}
system("cls");
system("color E0");
printf("You used %.3lf seconds",(double)clock()/CLOCKS_PER_SEC-14);
printf("\nAll score:%d\n",score);
if(score>20000)
mark="Good! A+";
else if(score>15000)
mark="A";
else if(score>10000)
mark="B";
else if(score>5000)
mark="C";
else if(score>0)
mark="D";
else
mark="ERROR: E";
cout<<mark;
cout<<endl<<endl<<"Please press any key to quit.";
getch();
return 0;
}
共 2 条回复
X
我崩了