纯c语言编写的打字游戏代码.docx
《纯c语言编写的打字游戏代码.docx》由会员分享,可在线阅读,更多相关《纯c语言编写的打字游戏代码.docx(12页珍藏版)》请在冰豆网上搜索。
![纯c语言编写的打字游戏代码.docx](https://file1.bdocx.com/fileroot1/2023-4/20/c6c97ab1-917e-4dea-a0bb-6d05600c0618/c6c97ab1-917e-4dea-a0bb-6d05600c06181.gif)
纯c语言编写的打字游戏代码
xx信息科技大学
软件工程1301SHERO组
#include
#include
#include
#include
#include
voidfunc();
voidfun();
voidfu();
intk=0,num;
voidmain(){intchoice,choice1;
floatresult;
system("color5A");
printf("开始游戏:
1结束:
0\n");
scanf("%d",&choice);
do{
switch(choice){case1:
printf("请选择字母【7】数字【8】数字+字母【9】");
scanf("%d",&choice1);
switch(choice1){case7:
func();break;
case8:
fun();break;
case9:
fu();break;}system("cls");
printf("\n\n\n\n\n\n\n\n\n\n您成功地击落%d个字母!
",k);
printf("\n您有%d个字母未击落!
",num-k);result=(float)k/num;
printf("\n您的准确率为%.2f!
",result);break;
case0:
exit
(1);break;
default:
system("cls");
printf("指令有误!
请检查指令。
\n");
getchar();}printf("\n\n\n\n\n\n\n继续游戏:
1
scanf("%d",&choice);
}while
(1);}/***************字母模块*****************/
voidfunc(){inta[25][80];
inti,l,j,m=0,n=0,t,t1,temp,c=0;
intsure,sure1=0,dif,N;
do{
do
{system("cls");
printf("\n请选择难度等级:
困难:
1普通:
2结束:
0
简单:
3\n");
");
scanf("%d",&dif);
if(dif!
=1&&dif!
=2&&dif!
=3)
{printf("\n指令有误,按任意键继续!
");
getchar();}else
sure1=1;
}while(sure1!
=1);
if(dif==1)
N=10;
if(dif==2)
N=500;
if(dif==3)
N=2000;
printf("\n请输入字母个数:
");
scanf("%d",&num);
switch(dif){case1:
printf("\n你选择了困难等级,%d个字母进行练习。
",num);break;case2:
printf("\n你选择了普通等级,%d个字母进行练习。
",num);break;case3:
printf("\n你选择了简单等级,%d个字母进行练习。
",num);break;}
printf("\n\n确定请按1,重新选择请按0");
scanf("%d",&sure);
system("cls");
}while(sure!
=1);
printf("\n\n\n\n\n\n\n\n\n\n按任意键开始游戏!
\n");getch();/*头文件为#include*/
system("cls");
for(i=0;i<25;i++)/*赋值为空格*/
for(j=0;j<80;j++)
a[i][j]=32;
system("cls");
srand((unsigned)time(NULL));
a[0][rand()%80+1]=(rand()%26+65);
for(t=0;t0;i--)
for(j=80;j>0;j--)
printf("%c",a[i][j]);
_sleep(N);/*时间延迟,用来控制难度*/
m=0;
while(m<=22){for(l=0;l<80;l++){temp=a[m+1][l];
a[m+1][l]=a[m][l];
a[m][l]=temp;}m++;}if(!
kbhit())
printf("");
else{charc=getch();
for(i=0;i<25;i++)
for(j=0;j<80;j++)
if(c==27)
exit
(1);
elseif(a[i][j]==c-32){a[i][j]=32;
putchar('\a');
k++;}}
system("cls");
/*以下是最后一个字母出现以后所执行的*/
if(t==num-1)
{for(t1=0;t1<23;t1++){for(i=24;i>0;i--)
for(j=80;j>0;j--)
printf("%c",a[i][j]);
_sleep(N);/*时间延迟,用来控制难度*/
m=0;
while(m<=22){for(l=0;l<80;l++){if(ma[m][l]=32;
temp=a[m][l];
a[m][l]=a[m+1][l];
a[m+1][l]=temp;}m++;}if(!
kbhit())
printf("");
else{charc=getch();
for(i=0;i<25;i++)
for(j=0;j<80;j++)
if(c==27)
exit
(1);
elseif(a[i][j]==c-32){a[i][j]=32;
putchar('\a');
k++;}}
system("cls");}}
/*以上是最后一个字母出现之后运行的*/
a[0][rand()%80+1]=(rand()%26+65);}}
/***************数字模块******************/
voidfun(){inta[25][80];
inti,l,j,m=0,n=0,t,t1,temp,c=0;
intsure,sure1=0,dif,N;
do{
do
{system("cls");
printf("\n请选择难度等级:
困难:
1普通:
2简单:
3");
scanf("%d",&dif);
if(dif!
=1&&dif!
=2&&dif!
=3)
{printf("\n指令有误,按任意键继续!
");
getchar();}else
sure1=1;
}while(sure1!
=1);
if(dif==1)
N=10;
if(dif==2)
N=500;
if(dif==3)
N=2000;
printf("\n请输入数字个数:
");
scanf("%d",&num);
switch(dif){case1:
printf("\n你选择了困难等级,%d个数字进行练习。
",num);break;case2:
printf("\n你选择了普通等级,%d个数字进行练习。
",num);break;case3:
printf("\n你选择了简单等级,%d个数字进行练习。
",num);break;}
printf("\n\n确定请按1,重新选择请按0");
scanf("%d",&sure);
system("cls");
}while(sure!
=1);
printf("\n\n\n\n\n\n\n\n\n\n按任意键开始游戏!
\n");getch();/*头文件为#include*/
system("cls");
for(i=0;i<25;i++)/*赋值为空格*/
for(j=0;j<80;j++)
a[i][j]=32;
system("cls");
srand((unsigned)time(NULL));
a[0][rand()%80+1]=(rand()%10+48);
system("cls");
for(t=0;t0;i--)
for(j=80;j>0;j--)
printf("%c",a[i][j]);
_sleep(N);/*时间延迟,用来控制难度*/
m=0;
while(m<=22){for(l=0;l<80;l++){temp=a[m+1][l];
a[m+1][l]=a[m][l];
a[m][l]=temp;}m++;}if(!
kbhit())
printf("");
else{charc=getch();
for(i=0;i<25;i++)
for(j=0;j<80;j++)
if(c==27)
exit
(1);
elseif(a[i][j]==c){a[i][j]=32;
putchar('\a');
k++;}}
system("cls");
/*以下是最后一个字母出现以后所执行的*/
if(t==num-1)
{for(t1=0;t1<23;t1++){for(i=24;i>0;i--)
for(j=80;j>0;j--)
printf("%c",a[i][j]);
_sleep(N);/*时间延迟,用来控制难度*/
m=0;
while(m<=22){for(l=0;l<80;l++){if(ma[m][l]=32;
temp=a[m][l];
a[m][l]=a[m+1][l];
a[m+1][l]=temp;}m++;}if(!
kbhit())
printf("");
else{charc=getch();
for(i=0;i<25;i++)
for(j=0;j<80;j++)
if(c==27)
exit
(1);
elseif(a[i][j]==c){a[i][j]=32;
putchar('\a');
k++;}}
system("cls");}}
/*以上是最后一个字母出现之后运行的*/
a[0][rand()%80+1]=(rand()%10+48);}}
/*****************数字+字母模块******************/
voidfu(){inta[25][80];
inti,l,j,m=0,n=0,t,t1,temp,c=0;
intsure,sure1=0,dif,N,NO;
do{
do
{system("cls");
printf("\n请选择难度等级:
困难:
1普通:
2
scanf("%d",&dif);
if(dif!
=1&&dif!
=2&&dif!
=3)
{printf("\n指令有误,按任意键继续!
");
getchar();}else
sure1=1;
}while(sure1!
=1);
if(dif==1)
N=10;
if(dif==2)
N=500;
if(dif==3)
N=2000;简单:
3");
printf("\n请输入个数:
");
scanf("%d",&num);
switch(dif){case1:
printf("\n你选择了困难等级,%d个字进行练习。
",num);break;
case2:
printf("\n你选择了普通等级,%d个字进行练习。
",num);break;
case3:
printf("\n你选择了简单等级,%d个字进行练习。
",num);break;}printf("\n\n确定请按1,重新选择请按0
scanf("%d",&sure);
system("cls");
}while(sure!
=1);
printf("\n\n\n\n\n\n\n\n\n\n
getch();/*头文件为#include*/
system("cls");
for(i=0;i<25;i++)/*赋值为空格*/
for(j=0;j<80;j++)
a[i][j]=32;
system("cls");
srand((unsigned)time(NULL));
NO=rand()%2;
switch(NO){case0:
a[0][rand()%80+1]=(rand()%26+65);break;
case1:
a[0][rand()%80+1]=(rand()%10+48);break;}for(t=0;t按任意键开始游戏!
\n");{for(i=24;i>0;i--)
for(j=80;j>0;j--)
printf("%c",a[i][j]);
_sleep(N);/*时间延迟,用来控制难度*/
m=0;
while(m<=22){for(l=0;l<80;l++){temp=a[m+1][l];
a[m+1][l]=a[m][l];
a[m][l]=temp;}m++;}if(!
kbhit())
printf("");
else{charc=getch();
for(i=0;i<25;i++)
for(j=0;j<80;j++)
if(c==27)
exit
(1);
elseif(a[i][j]==c-32){a[i][j]=32;
putchar('\a');
k++;}}
system("cls");
/*以下是最后一个字母出现以后所执行的*/
if(t==num-1)
{for(t1=0;t1<23;t1++){for(i=24;i>0;i--)
for(j=80;j>0;j--)
printf("%c",a[i][j]);
_sleep(N);/*时间延迟,用来控制难度*/
m=0;
while(m<=22){for(l=0;l<80;l++){if(ma[m][l]=32;
temp=a[m][l];
a[m][l]=a[m+1][l];
a[m+1][l]=temp;}m++;}if(!
kbhit())
printf("");
}}}else{charc=getch();
for(i=0;i<25;i++)
for(j=0;j<80;j++)
if(c==27)
exit
(1);
elseif(a[i][j]==c){a[i][j]=32;
putchar('\a');
k++;}elseif(a[i][j]==c-32){a[i][j]=32;
putchar('\a');
k++;}}
system("cls");}/*以上是最后一个字母出现之后运行的*/
a[0][rand()%80+1]=(rand()%26+65);