发布网友 发布时间:2022-04-22 16:08
共4个回答
热心网友 时间:2023-08-26 12:51
程序一:
类似于学习机上的指法练习程序,简单而实用
#include<time.h>
main()
{
int x,y,i,j;
unsigned int Timer;
char ch;
char key;
char *kb[]={"Q W E R T Y U I O P [ ]","A S D F G H J K L ; '","Z X C V B N M , . /"};
long AllCounter=0,RightCounter=0,FalseCounter=0;
time_t t;
int fun_Esc();
srand((unsigned)time(&t));
clrscr();
gotoxy(18,1);
printf("%s\n",kb[0]);
gotoxy(20,3);
printf("%s\n",kb[1]);
gotoxy(22,5);
printf("%s\n",kb[2]);
gotoxy(11,25);
for(i=0;i<60;i++)
{
printf("=");
}
gotoxy(1,1);
printf("AllCh: %ld\nRight: %ld\nFalse: %ld",AllCounter,RightCounter,FalseCounter);
printf("\n\n");
printf("Esc to exit");
printf("\n");
printf("Enter to pause");
gotoxy(26,12);
printf("* * * * * * * * * * * * * * *");
gotoxy(26,13);
printf("* Press any key to start! *");
gotoxy(26,14);
printf("* * * * * * * * * * * * * * *");
gotoxy(51,13);
if(getch()==27)
{
if(fun_Esc()==1)
{
clrscr();
exit(0);
}
}
gotoxy(23,12);
printf(" ");
gotoxy(23,13);
printf(" ");
gotoxy(23,14);
printf(" ");
lab_start:
y = 6;
Timer = 100000;
i = rand()%3;
j = rand()%(12-i);
ch = kb[i][j*4];
x = 18+i*2+j*4;
while(y<=24)
{
if(kbhit())
{
key = getch();
if(key==ch key==ch+32)
{
ch = '*'; Timer = 1000;
}
else if(key==27)
{
if(fun_Esc()==1)
{
clrscr();
exit(0);
}
}
else if(key=='\r')
{
gotoxy(x,y-1);
printf(" ");
gotoxy(28,13);
printf("Press any key to continue");
getch();
gotoxy(28,13);
printf(" ");
}
else
{
FalseCounter++;
}
}
if(y>6)
{
gotoxy(x,y-1);
printf(" ");
}
gotoxy(x,y);
printf("%c",ch);
gotoxy(1,1);
printf("AllCh: %ld\nRight: %ld\nFalse: %ld",AllCounter,RightCounter,FalseCounter);
delay(Timer);
y++;
}
AllCounter++;
if(ch == '*')
{
RightCounter++;
}
goto lab_start;
}
int fun_Esc()
{
int key = '#';
gotoxy(24,12);
printf("* * * * * * * * * * * * * * * * *");
gotoxy(24,13);
printf("* Are you sure to exit? (Y/N) *");
gotoxy(24,14);
printf("* * * * * * * * * * * * * * * * *");
gotoxy(51,13);
while(key!='Y' && key!='y' && key!='N' && key!='n')
{
key = getch();
if(key=='Y' key=='y')
{
return 1;
}
if(key=='N' key=='n')
{
gotoxy(24,12);
printf(" ");
gotoxy(24,13);
printf(" ");
gotoxy(24,14);
printf(" ");
return 0;
}
}
}
程序二:
大家自己设三个或一个文本文件,内含1000个字符就行了,英文字母或其他字符都可以。谢谢指教!!主函数在下面!介绍一下自定义函数的功能吧
自定义函数名称
函数功能
Background()
设置简单友好界面。
DEMO()
设置菜单供用户选择练习方式及退出。
Get_charater()
实现从用户指定文件随机抽取100个字符并显示在屏幕上供用户参照打字的功能
Typing()
程序的核心,实现了接受输入的字符、判断正误、计算练习成绩和时间等并显示在屏幕
特点:而主函数则非常简单,只包含这四个要调用的函数。这四个函数功能单一,且每个函数不超过50行,较好地满足设计风格。
#include
#include
#include
#include
#include
char string[101];
void Background()
{
int driver=DETECT,mode; /*定义变量*/
int x1=20,y1=20,r=10,num;
int x2=20,y2=450;
int color1=10,color2=10; /*在此设置颜色,一改全改*/
initgraph(&driver,&mode,"a:\\bgi "); /*初始化图形模式*/
setcolor(color1); /*步骤一、设置当前颜色用于绘图*/
for(num=0;num<30;num++)
{
circle(x1,y1,r); /*步骤二、使用当前颜色绘制一个闭合图形*/
setfillstyle(num%12,color1); /*步骤三、设置填充方式*/
floodfill(x1,y1,color1); /*步骤四、对闭合图形进行填充*/
x1+=20;
delay(100);
}
setcolor(color2);
for(num=0;num<30;num++)
{
circle(x2,y2,r);
setfillstyle(num%12,color2);
floodfill(x2,y2,color2);
x2+=20;
delay(100);
}
setcolor(YELLOW); /*改变当前颜色,输出友好话*/
settextstyle(0,0,2);
outtextxy(50,150,"WELCOME TO THE TYPING WORLD!");
setcolor(LIGHTMAGENTA);
outtextxy(200,350,"DESIGED BY HE ZHANG HONG");
sleep(3); /*延时二秒观看结果*/
closegraph(); /*关闭图形*/
}
void DEMO() /*设置菜单函数*/
{
printf("_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_**_*\n”
"\t\t\t"
"THE DEMO DISPLAY FOR THE FILE SYSTEM\n"
"\n"
"\t\t"
"1:PRATICE ONLY ENGLISH Characters.\n"
"\t\t"
"2:PRATICE OTHER Charcters.\n"
"\t\t"
"3:PRATICE ALL Charcters.\n"
"\t\t"
"4:QUIT AT ONCE!\n"
"\n");
}
void Get_character(void) /*设置得到字符函数*/
{
void Typing(); /*声明typing()函数*/
FILE *in;
int i,t,choice;
char ch;
t=abs(time(0))%700; /*获取随机数来指定下面指针的位*/
printf("\nPLEASE ENTER YOUR CHOICE:");
choice=getch();
clrscr(); /*清屏*/
switch(choice) /*选择不同打开文件来打不同的字符*/
{
case ’1’: in=fopen("english.txt","r");
break;
case ’2’: in=fopen("others.txt","r");
break;
case ’3’: in=fopen("type all.txt","r");
break;
case ’4’: exit(1);break;
}
fseek(in,t*1l,0);
fgets(string,101,in);
printf("\n");
printf("********************************************************************");
for(i=0;i<100;i++)
putchar(string[i]);
printf("\n");
printf("********************************************************************");
fclose(in);
printf("LET’S BEGIN TYPING,OK?[Y/N]");
printf("\n");
ch=getch();
if(ch==’n’||ch==’N’) /*判断是否练习打字*/
exit(0);
else if(ch==’y’||ch==’Y’)
Typing();
}
void Typing(void) /*设置打字(包括计算其他结果)函数*/
{
int i,j,Right_char=0,Wrong_char=0,Sum_char=0;
float Speed,Timeused,Right_rate;
char absorb_char,ch_1,ch_2,ch_3;
time_t star,stop; /*定义time变量,获取系统时间并显示在屏幕上*/
time(&star);
printf("\n");
printf("time begin:%s",ctime(&star));
i=0;
absorb_char=getchar(); /*接受键盘输入的字符并在下面的while语句判断正 错和计算结果*/
while(absorb_char!=’\n’&&i<100)
{
if(absorb_char==string[i])
{
Right_char++;
Sum_char++;
}
else
{
Wrong_char++;
Sum_char++;
}
i++;
absorb_char=getchar();
}
time(&stop);
Timeused=difftime(stop,star); /*利用difftime()函数输出所用时间*/
Right_rate=(float)Right_char/(float)Sum_char*100;
Speed=(Sum_char/Timeused)*60;
printf("time end:%s",ctime(&stop)); /*下面显示分数*/
printf("****#################~~~~~~~~~~~~~YOUR SCORE!!~~~~~~~~~~~~~~################****");
printf(" 1: TOTAL TIME USED:%.3f\n",Timeused);
printf(" 2: YOU HAVE TYPED:%d\n",Sum_char);
printf(" 3: Typing Right_Characters are:%d\n",Right_char);
printf(" 4: Typing Wrong_Characters are:%d\n",Wrong_char);
printf(" 5: YOUR TYPING SPEED IS :%.2f\\min\n",Speed);
printf(" 6: YOUR TYPING RIGHT_RATE IS :%.2f%%\n",Right_rate);
printf("****#################~~~~~~~~~~~~~YOUR SCORE!!~~~~~~~~~~~~~~################****");
if(Speed<=50||Right_rate<=80) /*询问用户是否重来一遍*/
{
printf(" NOT VERY GOOD!\n TRY IT AGAIN,OK?[Y/N]\n");
ch_2=getch();
if(ch_2==’n’||ch_2==’N’) exit(0);
else if(ch_2==’y’||ch_2==’Y’)
{
clrscr();
DEMO(); /*分别调用函数重来一遍*/
Get_character();
Typing();
}
exit(0);
}
else printf(" WELL DONE!!\n ONE MORE TIME?[Y/N]\n"); /*询问用户是否重来一遍*/
ch_3=getch();
if(ch_3==’n’||ch_3==’N’) exit(0);
else if(ch_3==’y’||ch_3==’Y’)
{
clrscr();
DEMO(); /*分别调用函数重来一遍*/
Get_character();
Typing();
}
exit(0);
}
main(void) /*主函数包含四个要调用的函数*/
{
Background();
DEMO();
Get_character();
Typing();
}追问那你还有没有vb的程序呢?
追答大哥你要的是C语言的啊。。。
VB的:
加10个label1控件组,一个timer,
操作:
运行后,回车即可进行游戏,
代码:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Dim m As Integer
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Timer1.Interval = 100
Else
For j = 0 To 9
If Label1(j).Caption = UCase(Chr(KeyAscii)) Then
m = m + 1
If m = 30 Then Me.Caption = "第一级"
If m = 60 Then Me.Caption = "第2级"
If m = 90 Then Me.Caption = "第3级"
Label1(j).Top = 0
Exit For
End If
Next
End If
End Sub
Private Sub Form_Load()
For i = 0 To 9
Label1(i).Top = 0
Next
Me.Caption = "第0级"
End Sub
Private Sub Timer1_Timer()
Static n As Integer
If n = 10 Then
MsgBox "游戏结束"
Timer1.Enabled = False
End If
For i = 0 To 9
If Label1(i).Top > Form1.Height Then
Label1(i).Top = 0
Randomize
Label1(i).Caption = Chr(Int(Rnd * 26 + 65))
n = n + 1
ElseIf Label1(i).Top = 0 Then
Randomize
Label1(i).Caption = Chr(Int(Rnd * 26 + 65))
Label1(i).Top = Label1(i).Top + 100
Else
Label1(i).Top = Label1(i).Top + 100
End If
Next
End Sub
热心网友 时间:2023-08-26 12:51
去玩金山打字通里的打字游戏吧。
热心网友 时间:2023-08-26 12:52
楼上的你很彪悍呀( ⊙o⊙ )哇
热心网友 时间:2023-08-26 12:52
额 要我说 这方面的还是 金山打字 最强