打字小游戏
熬夜写的小游戏,本来想加个计算每分钟打字速度的功能,奈何没思路,就这样吧!
#include<stdio.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
char levels='D'; //output level分数
int score=0; //your score等级
int num=0;
int GeZi=0; //GeZi代表要打印多少个空格
int index=0;
void KongGe(int num); //打印空格的函数
void Game(){
index=0;
while(1){
KongGe(GeZi);
printf("%c",'a'+num);
Sleep(80); //间隔时间,越小越快
printf("\b \n");
index++;
if(index>23){ //字母掉到底部
score-=1;
break;
}
if(kbhit()){
int c=getch();
if(c!='a'+num){
score--;
printf("t\t\t\t\t\tError!!!");//敲错字幕
Sleep(150);
break;
}
if(c='a'+num){
score+=1;
break;
}
}
}
}
void Daying(int num){
int i;
for(i=0;i<num;i++){
printf("-");
}
printf("\n");
}
void KongGe(int num){
int i;
for(i=1;i<num;i++){
printf(" ");
}
}
/*------------------------------------------------------------------------*/
int main(){
printf("\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\tPlease enter anykey to continue");
printf("\n\t\t\t\t\tAuthor:GGLDD");
getch();
/*-----------------------------------------------------------------------*/
system("cls");
struct tm *sysTime;
time_t nowTime;
while(1){
time(&nowTime);
sysTime=localtime(&nowTime);
num=rand()%26;
GeZi=rand()%110;
printf("\t\tlevels:%c\t\tTime%d-%d-%d\t\t\t",levels,sysTime->tm_hour,sysTime->tm_min,sysTime->tm_sec);
printf("Score:%d\n",score);
printf("\t\t \t\t\t\t\n");
Daying(110);
Game();
system("cls");
if(score>60&&score<80)
levels='C';
if(score>80&&score<90)
levels='B';
if(score>90&&score<100)
levels='A';
if(score>100)
levels='S';
if(score<60&&score>0)
levels='D';
if(score<0)
levels='F';
}
return 0;
}
text.c.zip
(1.26 KB)