打字练习代码
1C#打字游戏代码(初学者易懂)
} } private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) { if (DialogResult.Yes == MessageBox.Show(" 确 认 结 束 吗 [Y/N]", " 一 个 结 束 确 认 窗 口 ", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { Application.Exit(); } } private void 提示ToolStripMenuItem_Click(object sender, EventArgs e) { MessageBox.Show("打字练习"); } private void 击字字数ToolStripMenuItem_Click(object sender, EventArgs e) { MessageBox.Show(all.ToString()); } private void 正确数ToolStripMenuItem_Click(object sender, EventArgs e) { MessageBox.Show(right.ToString()); } private void 错误数ToolStripMenuItem_Click(object sender, EventArgs e)
using System; using System.Collections.Generic; using ponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication2 { public partial class Form1 : Form { int right = 0,all = 0, a = 0;
练习文章打字的编程
#include<dos.h>#include<stdio.h>#include<conio.h>xfk(){char *zq=" ture",*cu="flase",*fs="score"; int i,j,hh=7;textcolor(YELLOW);gotoxy(3,6);cputs(zq);gotoxy(3,11);cputs(cu);gotoxy(3,16);cputs(fs);textcolor(GREEN);for(i=1;i<=3;i++){gotoxy(3,hh);putch('\311');for(j=4;j<=7;j++){gotoxy(j,hh);putch('\315');}gotoxy(8,hh); putch('\273');hh=hh+5;}hh=8;for(i=1;i<=3;i++) {gotoxy(3,hh); putch('\272'); gotoxy(8,hh); putch('\272');hh=hh+5;}hh=9;for(i=1;i<=3;i++) {gotoxy(3,hh); putch('\310');for(j=4;j<=8;j++) {gotoxy(j,hh);putch('\315');}gotoxy(8,hh);putch('\274');hh=hh+5;}textcolor(GREEN);}wcbk(){int thh,tlh;textcolor(WHITE);thh=1;tlh=1;gotoxy(tlh,thh);putch('\332');for(tlh=2;tlh<=78;tlh++){gotoxy(tlh,thh);putch('\304');}gotoxy(tlh,thh);putch('\277');tlh=1;for(thh=2;thh<=25;thh++) {gotoxy(tlh,thh);putch('\263');gotoxy(tlh+78,thh); putch('\263');}thh=25;gotoxy(tlh,thh);putch('\300');for(tlh=2;tlh<=78;tlh++) {gotoxy(tlh,thh);putch('\304');}gotoxy(tlh,thh);putch('\276');textcolor(GREEN);}lcbk(){int thh,tlh;textcolor(YELLOW);thh=3;tlh=10;gotoxy(tlh,thh);putch('\311');for(tlh=11;tlh<=70;tlh++){gotoxy(tlh,thh);putch('\315');}gotoxy(tlh,thh);putch('\273');tlh=10;for(thh=4;thh<=22;thh++){gotoxy(tlh,thh);putch('\272');gotoxy(tlh+61,thh);putch('\272');}thh=23;gotoxy(tlh,thh);putch('\310');for(tlh=11;tlh<=70;tlh++){gotoxy(tlh,thh);putch('\315');}gotoxy(tlh,thh);putch('\274');textcolor(GREEN);}zhhs(char lfilename[20]){int hh=5,lh=13,i,wz=0,cj=4,bj=1,thh,tlh,zq=0,cu=0,fs=0; char *zh,lsslzh,filezh;FILE *fp;if(!(fp=fopen(lfilename,"r"))){printf("cannot open file\n");exit(1);}while(1){wcbk();lcbk();xfk();for(i=1;i<=6;i++){fread(zh,50,1,fp);gotoxy(lh,hh);cputs(zh);hh=hh+3;if(feof(fp)) break;}fseek(fp,wz,0);for(hh=6;hh<=21;hh=hh+3) {for(lh=13;lh<=62;lh++){bj=1;gotoxy(lh,hh);putch(24);gotoxy(lh,hh);filezh=fgetc(fp);wz=wz+1;if((lsslzh=getch())==27) exit(1);if((lsslzh==8)&&!(hh==6&&lh==13)){bj=0;if((lh==13)&&(hh!=6)){putch(' ');lh=62;hh=hh-3;cj=cj-3;}else lh=lh-1;wz=wz-2;gotoxy(lh,hh);putch(' ');gotoxy(lh,cj);putch(' ');gotoxy(lh+1,hh);putch(' ');lh=lh-1;fseek(fp,wz,0);}gotoxy(lh,hh);if(filezh==EOF) return(lsslzh);if(filezh==lsslzh){putch(lsslzh);fs=fs+5;zq=zq+1;gotoxy(4,8);printf("%2d",zq);gotoxy(4,18);printf("%2d",fs);}else{if(bj){cu=cu+1;gotoxy(4,13);printf("%2d",cu); gotoxy(lh,hh);textcolor(RED);putch(lsslzh);gotoxy(lh,cj);putch(25);gotoxy(lh,hh);sound(980);delay(100000);nosound();textcolor(GREEN);}}}cj=cj+3;}delay(2000);textcolor(YELLOW);clrscr();wz=ftell(fp);hh=5;lh=13;cj=4;}}main(){int thh=3,tlh=10;char zh;char *filename, *lesson="1.College Life\n2.study Online\n3.Lesiure Activity\n4.Living on your own";window(1,1,20,40);textbackground(BLUE);textcolor(YELLOW);while(1){clrscr();printf("%s\n",lesson);printf("choice lesson number:");zh=getch();switch(zh){case 49: filename="e:\\fcp\\college.txt";break;case 50: filename="e:\\fcp\\study.txt";break;case 51: filename="e:\\fcp\\lesiure.txt";break;case 52: filename="e:\\fcp\\living.txt";break;case 27: exit(1);default: printf("enter file name:");scanf("%s",filename); }clrscr();zhhs(filename);clrscr();printf("continue practic(y\n):");if(getch()=='n') break;}}。
打字程序代码
打字程序代码/*练习训练游戏*/#include#include#include#include#include#include#define MAXCHAR 100#define ESC 0x011b /* 退出程序键,调用quitgame()函数*/ #define F10x3b00/* 查看帮助信息,调用Help()函数 */#define F20x3c00/* 查看关于...信息,调用About()函数 */#defineF30x3d00/* 以下功能键暂时保留,如果增加功能可使用*/#defineF40x3e00#defineF50x3f00#defineF60x4000#defineF70x4100#defineF80x4200#defineF90x4300#defineF100x4400#define KEY1 0x0231#define KEY2 0x0332#define KEY3 0x0433#define KEY4 0x0534#define KEY01 0x4f31#define KEY02 0x5032#define KEY03 0x5133#define KEY04 0x4b34char string[MAXCHAR+1];int LittleWin(int WinType/*=1, quitgame; =2, Help;=3, About; =4, others;*/);/*when WinType=1, return 0, quit, return 1, not quit*/void quitgame();void Welcome();void drawframe();void Frame();void GetCharacter();void Typing();int LittleWin(int WinType/*=1, quitgame; =2, Help;=3, About; =4, others;*/)/*when WinType=1, return 0, quit, return 1, not quit*/{int i;char ch;window(18,6,62,20);textbackground(LIGHTGRAY);textcolor(BLACK);clrscr();gotoxy(1,1);cprintf("%c",201);for(i=0;i<43;i++)cprintf("%c",205);cprintf("%c",187);for(i=0;i<13;i++){gotoxy(1,i+2);cprintf("%c",186);gotoxy(45,i+2);cprintf("%c",186);}gotoxy(1,14);cprintf("%c",200);for(i=0;i<43;i++)cprintf("%c",205);cprintf("%c",188);gotoxy(20,1);switch(WinType){case 1:cprintf(" Exit ");textcolor(LIGHTRED);gotoxy(18,3);cprintf("Warning!");textcolor(LIGHTBLUE);gotoxy(5,5);cprintf("This operation will exit the program!"); gotoxy(10,7);cprintf("Do you really want to quit?"); textcolor(LIGHTGREEN);gotoxy(18,9);cprintf("OK? [Y/N]");/*window(18,20,62,20);textbackground(LIGHTBLUE);textcolor(YELLOW);clrscr();*/window(19,18,61,18);textbackground(LIGHTBLUE);textcolor(WHITE);clrscr();gotoxy(5,1);cprintf("Press Y to quit, press N to return."); while(1){ch=getch();if(ch=='Y'||ch=='y')return 0;else if(ch=='N'||ch=='n')return 1;}break;case 2:cprintf(" Help ");break;case 3:cprintf(" About ");break;case 4:cprintf(" Info ");break;default:break;}}void quitgame(){if(LittleWin(1)){Frame();return;}window(1,1,80,25);textbackground(BLACK);textcolor(LIGHTGRAY);clrscr();exit(0);}void Welcome(){int driver=VGA,mode=VGAHI; /*定义变量*/int x1=20,y1=20,r=10,num,i;int x2=20,y2=450;int color1=10,color2=10; /*在此设置颜色,一改全改*/static char ch1[28][2]={"W","e","l","c","o","m","e"," ","t","o"," ","t","h","e"," ","T","y","p","i","n","g"," ","W","o","r","l","d","!"};initgraph(&driver,&mode,"C:\\\c "); /*初始化图形模式*/setbkcolor(LIGHTBLUE);setcolor(color1); /*步骤一、设置当前颜色用于绘图*/for(num=0;num<30;num++){circle(x1,y1,r); /*步骤二、使用当前颜色绘制一个闭合图形*/ setfillstyle(num%12,color1); /*步骤三、设置填充方式*/ floodfill(x1,y1,color1); /*步骤四、对闭合图形进行填充*/ x1+=20;sound(300); /*输出声音*/delay(3000);nosound();}setcolor(color2);for(num=0;num<30;num++){circle(x2,y2,r);setfillstyle(num%12,color2);floodfill(x2,y2,color2);x2+=20;sound(300); /*输出声音*/delay(3000);nosound();}settextstyle(0,0,2);setcolor(LIGHTRED);sound(300); /*输出声音*/delay(3000);nosound();outtextxy(180,90,"^o^ Hello! ^o^");sound(300); /*输出声音*/delay(3000);nosound();setcolor(YELLOW);gotoxy(50,150);for(i=0;i<28;i++){outtextxy(50+i*16,150,ch1[i]);sound(300); /*输出声音*/delay(3000);nosound();}/*outtextxy(50,150,"Welcome to the Typing World!");*/ setcolor(WHITE);outtextxy(50,200,"This is a little");sound(300); /*输出声音*/delay(6000);nosound();outtextxy(100,250,"Typing Training");sound(300); /*输出声音*/delay(6000);nosound();outtextxy(150,300,"Software ... ^_^");sound(300); /*输出声音*/delay(6000);nosound();setcolor(LIGHTMAGENTA);outtextxy(100,350,"Ver. 2004-04-30");sound(300); /*输出声音*/delay(6000);nosound();setcolor(LIGHTGREEN);outtextxy(100,400,"Press any key to start...");sound(300); /*输出声音*/delay(6000);nosound();getch();closegraph(); /*关闭图形*/}void drawframe(){int i;window(1,1,80,1);textbackground(LIGHTGRAY);textcolor(BLACK);clrscr();gotoxy(7,1);cprintf("File Edit Run Compile Project Options Debug Help"); textcolor(RED);gotoxy(7,1);cprintf("F");gotoxy(14,1);cprintf("E");gotoxy(21,1);cprintf("R");gotoxy(27,1);cprintf("C");gotoxy(37,1);cprintf("P");gotoxy(47,1);cprintf("O");gotoxy(57,1);cprintf("D");gotoxy(65,1);cprintf("H");window(1,25,80,25);textbackground(LIGHTGRAY);textcolor(BLACK);clrscr();gotoxy(7,1);printf("F1-Help F2-About F3-Open F4-Restart Ctrl+F9-Run ESC-Quit");textcolor(RED);gotoxy(7,1);cprintf("F1");gotoxy(17,1);cprintf("F2");gotoxy(28,1);cprintf("F3");gotoxy(37,1);cprintf("F4");gotoxy(50,1);cprintf("Ctrl+F9");gotoxy(64,1);cprintf("ESC");window(1,2,80,24);textbackground(LIGHTBLUE);textcolor(LIGHTGRAY);clrscr();gotoxy(1,2);cprintf("%c",213);for(i=0;i<78;i++)cprintf("%c",205);cprintf("%c",184);for(i=0;i<21;i++){gotoxy(1,i+3);cprintf("%c",179);gotoxy(80,i+3);cprintf("%c",179);}gotoxy(1,22);cprintf("%c",192);for(i=0;i<78;i++)cprintf("%c",196);cprintf("%c",217);textcolor(WHITE);gotoxy(37,1);cprintf(" Type ");}void Frame() /*设置菜单函数*/{drawframe();window(2,3,79,22); textbackground(LIGHTBLUE); textcolor(YELLOW);clrscr();gotoxy(25,2);cprintf("The Typing World Menu\"); gotoxy(12,4);cprintf("1:Practice Only ENGLISH Characters."); gotoxy(12,6);cprintf("2:Practice Other Charcters.");gotoxy(12,8);cprintf("3:Practice All Charcters.");gotoxy(12,10);cprintf("4:Quit at once!");GetCharacter();}void GetCharacter(void) /*设置得到字符函数*/{void Typing(); /*声明typing()函数*/FILE *in;int i,t,choice;char ch;t=abs(time(0))%700; /*获取随机数来指定下面指针的位*/ gotoxy(12,12);cprintf("Please input your choice: ");while(1){gotoxy(38,12);choice=bioskey(0);if(choice==ESC||choice==KEY4||choice==KEY04) {quitgame();break;}else if(choice==KEY1||choice==KEY01){in=fopen("english.dat","r");break;}else if(choice==KEY2||choice==KEY02){in=fopen("others.dat","r");break;}else if(choice==KEY3||choice==KEY03){in=fopen("typeall.dat","r");break;}}clrscr(); /*清屏*/fseek(in,t*1l,0);fgets(string,MAXCHAR+1,in);textcolor(WHITE);gotoxy(1,2);cprintf("****************************************************** ************************");textcolor(YELLOW);for(i=0;i<maxchar;i++)cprintf("%c",string[i]);gotoxy(1,5);textcolor(WHITE);cprintf("****************************************************** ************************");fclose(in);gotoxy(1,6);cprintf("Let's begin typing,OK?[Y/N]");while(1){gotoxy(28,6);ch=getch();if(ch=='n'||ch=='N') /*判断是否练习打字*/{quitgame();break;}else if(ch=='y'||ch=='Y'){Typing();break;}}}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);textcolor(WHITE);gotoxy(1,6);cprintf("time begin:%s",ctime(&star));gotoxy(1,7);i=0;absorb_char=getch(); /*接受键盘输入的字符并在下面的while 语句判断正错和计算结果*/while(i<maxchar){if(absorb_char=='\')continue;elsecprintf("%c",absorb_char);if(absorb_char==string[i]){Right_char++;Sum_c</maxchar)</maxchar;i++)har++;}else{Wrong_char++;Sum_char++;}i++;absorb_char=getch();}time(&stop);Timeused=difftime(stop,star); /*利用difftime()函数输出所用时间*/Right_rate=(float)Right_char/(float)Sum_char*100;Speed=(Sum_char/Timeused)*60;gotoxy(1,11);cprintf("time end:%s",ctime(&stop)); /*下面显示分数*/textcolor(LIGHTGREEN);gotoxy(1,12);cprintf("********************YourScore!*************************");gotoxy(7,13);textcolor(WHITE);cprintf(" 1: TOTAL TIME USED:%.3f",Timeused);gotoxy(7,14);cprintf(" 2: YOU HAVE TYPED:%d",Sum_char);gotoxy(7,15);cprintf(" 3: Typing Right_Characters are:%d",Right_char);gotoxy(7,16);cprintf(" 4: Typing Wrong_Characters are:%d\",Wrong_char);gotoxy(7,17);cprintf(" 5: YOUR TYPING SPEED IS :%.2f\\\\min\",Speed);gotoxy(7,18);cprintf(" 6: YOUR TYPING RIGHT_RATE IS :%.2f%%\",Right_rate);textcolor(LIGHTGREEN);gotoxy(1,19);cprintf("********************YourScore!*************************");gotoxy(1,20);textcolor(WHITE);if(Speed<=50||Right_rate<=80) /*询问用户是否重来一遍*/{cprintf("Not Very Good! Try it Again,OK?[Y/N]");while(1){gotoxy(39,20);ch_2=getch();if(ch_2=='n'||ch_2=='N'){quitgame();break;}else if(ch_2=='y'||ch_2=='Y'){Frame();break;}}}else{cprintf("Well Done!! One More Time?[Y/N]"); /*询问用户是否重来一遍*/while(1){gotoxy(35,20);ch_3=getch();if(ch_3=='n'||ch_3=='N'){quitgame();break;}else if(ch_3=='y'||ch_3=='Y'){Frame();break;}}}}main(void) /*主函数包含两个要调用的函数*/ {/*Welcome();*/Frame();}。
英文打字练习程序源代码
■ 初学者英文打字练习程序
————————————————以下为程序代码—————————————
Option Explicit
Dim speed, right, wrong, keynum As Integer '定义速度,正确次数,错误次数,击键次数
lbl_time.Caption = 120 & " 秒"
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
keynum = keynum + 1
Else
lbl_score.BackColor = vbGreen
Timer1.Enabled = True
Timer2.Enabled = True
End If
End Sub
Private Sub Form_Load()
Form1.Left = (Screen.Width - Form1.Width) / 2
If KeyAscii = 27 Then
Timer1.Enabled = False
Timer2.Enabled = False
lbl_score.BackColor = vbYellow
lbl_score.Caption = "成绩: " & right & "分" & " 错误: " & wrong & " 个" & " 正确率: " & Int(right / keynum * 100) & "%" & " 按任意键继续"
c语言写打字训练程序
c语言写打字训练程序
打字训练是提高打字速度和准确度的有效方法,而c语言作为一种高级编程语言,可以利用其强大的功能和语法来编写一个打字训练程序。
一、设定需求
首先要设定需求,即需要让程序能够对用户进行打字速度和准确度的测试,同时需要提供不同难度和不同形式的打字练习。
二、设计程序算法
接下来需要设计程序的算法,即如何实现需求。
可以将程序分为三个模块,分别为输入模块、计算模块和输出模块。
1.输入模块:用户输入打字练习的文本,可以从文件中读取打字练习文本。
需要记录用户的开始时间和结束时间,以便计算用户的打字速度。
2.计算模块:计算模块会根据用户输入的文本和正确答案进行比较,计算用户的打字准确度和速度,并将结果传递给输出模块进行显示。
3.输出模块:输出模块会显示用户的打字速度和准确度,并给出评估。
三、编写程序代码
接下来就可以根据对算法的设计来编写程序代码了。
可以按照模块分别编写代码,其中输入模块可以使用c语言标准库中的文件读写函数进行实现。
计算模块需要编写字符串比较函数和计算打字速度和准确度的函数。
输出模块可以使用printf函数进行简单的命令行输出。
四、测试和优化程序
最后需要对程序进行测试和优化。
可以在代码中加入错误处理机制,防止出现崩溃现象,同时可以对用户接口进行优化,使其更加易用。
总之,使用C语言编写打字训练程序,需要从设定需求开始,设计程序算法,编写代码,测试和优化程序,才能达到预期的效果。
这
就需要程序员有一定的编程经验和思维能力。
通过不断学习和实践,我们可以不断提高自己的编程水平和技能,创造更加有用和实用的程序。
Python基础练习代码(20条)
Python基础练习代码(20条)1. 输入两个整数,输出它们的和。
a = int(input("请输入一个整数: "))b = int(input("请输入另一个整数: "))sum = a + bprint("{0} + {1} = {2}".format(a, b, sum))2. 计算一个整数的阶乘。
n = int(input("请输入一个正整数: "))fact = 1for i in range(1, n+1):fact *= iprint("{0}! = {1}".format(n, fact))3. 输入三角形三边的长度,判断是否为直角三角形。
a = float(input("请输入三角形第一条边的长度: "))b = float(input("请输入三角形第二条边的长度: "))c = float(input("请输入三角形第三条边的长度: "))if (a*a + b*b == c*c) or (a*a + c*c == b*b) or (b*b + c*c ==a*a):print("是直角三角形")else:print("不是直角三角形")4. 输入一个字符,判断它是否为大写字母。
ch = input("请输入一个字符: ")if ch >= 'A' and ch <= 'Z':print("{0}是大写字母".format(ch)) else:print("{0}不是大写字母".format(ch)) 5. 输入一个整数,判断它是否为素数。
n = int(input("请输入一个正整数: "))flag = 0if n == 1:print("1不是素数也不是合数")else:for i in range(2, n//2+1):if n % i == 0:flag = 1breakif flag == 0:print("{0}是素数".format(n))else:print("{0}不是素数".format(n))6. 输入一个字符,判断它是否为数字。
C语言入门训练代码(10条)
C语言入门训练代码(10条)1. 输入n,计算出n的阶乘。
#include <stdio.h>int main(){int n, i;long long ret = 1;printf("请输入一个正整数:");scanf("%d", &n);for (i=1; i<=n; ++i){ret *= i;}printf("%d的阶乘是%lld\n", n, ret);return 0;}2. 编写一个程序,将一个字符串中的字母全部转换为大写字母。
#include <stdio.h>#include <ctype.h>#define MAX_LEN 100int main(){char str[MAX_LEN + 1];int i;printf("请输入一个字符串:");fgets(str, MAX_LEN, stdin);for (i=0; str[i]!='\0'; ++i){str[i] = toupper(str[i]);}printf("转换后的字符串是:%s", str);return 0;}3. 输入两个正整数m和n,求它们的最大公约数和最小公倍数。
#include <stdio.h>int main(){int m, n, i, gcd, lcm;printf("请输入两个正整数m和n:");scanf("%d %d", &m, &n);for (i=1; i<=m && i<=n; ++i){if (m%i==0 && n%i==0){gcd = i;}}lcm = m*n / gcd;printf("%d和%d的最大公约数是%d,最小公倍数是%d\n", m, n, gcd, lcm);return 0;}4. 输入一组数据,计算它们的平均值以及大于平均值的个数。
用汇编编写的指法打字练习软件TT
Init_boarder macro row,col,char,dhdl,countLocal l1mov cx,countmov dh,rowmov dl,coll1:mov ah,02hmov bh,00hint 10hpush cxmov ah,0ahmov al,charmov bh,00hmov cx,01hint 10hpop cxinc dhdlloop l1endmclear_screen macro top,left,bottom,right,col;清屏宏定义 mov ah,06hmov al,00hmov bh,colmov ch,topmov cl,leftmov dh,bottommov dl,rightint 10hendmsetcusor macro page,row,column;设置光标位置mov ah,02hmov bh,pagemov dl,columnmov dh,rowint 10hendmmenu macro row,col,text;菜单显示宏定义mov ah,02hmov bh,00hmov dh,rowmov dl,colint 10hmov cx,0mov ah,09hlea dx,textint 21hendmdata segment; add your data here!;pkey db "press any key...$"kaishi db " welcome to play the game! $"mes0 db " =========================================$"mes1 db " 1.start game $"mes2 db " 2.select $"mes3 db " 3.exit $"mes4 db " =========================================$"mes5 db " select num of menu:$"mes12 db " =========================================$"mes13 db " 1.100 letters $"mes14 db " 2.200 letters $"mes15 db " 3.300 letters $"mes17 db " =========================================$"mes18 db "Correct Rate:$"mes7 db " press any key to start the game... $"mes8 db " press esc key return main menu $"mes10 db " Select The Letter's Num $"mes19 db " wait... $"mes11 db " when the game was over,press enter to restart$"mes9 db "Used Time:$"mes6 db "The correct number:$"col db 00h,24h,0fdh,0dh;颜色num dw ? ;以输入字母的个数numb dw ? ;输入正确字母的个数score dw ? ;每轮游戏的分数grade dw ?sum dw ?n db 26letters db 500 dup(0)hour db 0minu db 0seco db 0endsstack segmentdw 128 dup(0)endscode segmentstart:; set segment registers:mov ax, datamov ds, axmov es, ax; add your code here;clear_screen 0d,0d,24d,79d,07hFrame1:clear_screen 0d,0d,24d,79d,1eh ;清屏Init_boarder 0d,0d,'*',dl,80d ;显示边框上一排星号Init_boarder 24d,0d,'*',dl,80d ;显示边框下一排星号 Init_boarder 0d,0d,'*',dh,25d ;显示边框左一排星号 Init_boarder 0d,79d,'*',dh,25d ;显示边框右一排星号 menu 5d,20d,mes0menu 6d,26d,kaishi ;显示菜单menu 8d,30d,mes1menu 10d,30d,mes2menu 12d,30d,mes3menu 13d,20d,mes4menu 14d,20d,mes5inputMenuNum:mov ah,7 ;输入功能号,无回显int 21hcmp al,'1'je call num1cmp al,'2'je call num2cmp al,'3'je end1jmp inputMenuNum ;输入不符要求重输Frame2 procmov dl,al ;将选择的功能号显示出来mov ah,2int 21hclear_screen 1d,1d,23d,78d,1eh ;清屏,边框还存在menu 9d,20d,mes7menu 11d,20d,mes8; menu 12d,30d,mes10menu 13d,20d,mes11mov cx,2000h ;隐藏光标mov ah,01h ;设置光标大小int 10hmov ah,7 ;无回显输入字符int 21hmov cx,1010h ;显示光标mov ah,01hint 10hretFrame2 endpnum1 procmov dl,al ;将选择的功能号显示出来mov ah,2int 21hclear_screen 1d,1d,23d,78d,1eh;清屏,但边框存在menu 9d,20d,mes7menu 11d,20d,mes8;menu 12d,30d,mes10menu 13d,20d,mes11mov cx,2000h ;隐藏光标mov ah,01hint 10hmov ah,7 ;无回显输入字符int 21hmov cx,1010h ;显示光标mov ah,01hint 10hmov num,100call playretnum1 endpnum2 procmov dl,al ;将选择的功能号显示出来 mov ah,2int 21hclear_screen 1d,1d,23d,78d,1eh;清屏 menu 7d,20d,mes10menu 8d,20d,mes12menu 10d,20d,mes13menu 11d,20d,mes14menu 12d,20d,mes15menu 14d,20d,mes17menu 15d,20d,mes5inputMenuNum1:mov ah,07hint 21hcmp al,'1'jz m1cmp al,'2'jz m2cmp al,'3'jz m3cmp al,27 ;当输入esc键时退到主菜单 jz Frame1jmp inputMenuNum1m1:call Frame2mov num,100 ;设置字符串个数为100call playjmp m4m2:call Frame2mov num,200call playjmp m4m3:call Frame2mov num,300call playjmp m4m4: retnum2 endpplay procmov numb,0 ;正确字符个数clear_screen 02d,02d,23,78,1eh ;清屏(边框还存在) lea si,lettersmov bx,0call getletter ;调用生成字符串子程序menu 20d,15d,mes19setcusor 0d,3d,10d ;设置光标位置clear_screen 02d,02d,23,78,1eh ;清屏(边框还存在) call outlettersetcusor 0d,4d,10d ;设置光标位置mov ah,2ch ;获取当前时间int 21hmov hour,ch ;获取的小时放入hour中mov minu,cl ;获取的分钟放入minu中mov seco,dh ;获取的秒钟放入seco中call inputlettermenu 20d,5d,mes9call counttimecall outtimemenu 20d,25d,mes6mov ax,numbcall PRINTAXmenu 20d,50d,mes18call CorrectRateinput_quit:mov ah,07hint 21hcmp al,27jz Frame1cmp al,0dhjz call playjmp input_quitretplay endp;*************************************;实现随机产生字符串getletter procoutput_letter:mov ah,2ch ;获取时间 ch为小时,cl为分,dh为秒,dl为1%秒int 21hmov al,dl ;将1%秒放入al中mov ah,0 ;将ah置0,ax当被除数div n ;n为26,将商放到al中,将余数放入ah中mov dl,ah ;将余数放入dl中add dl,61h ;a的ascii码为61,将余数加上61得到随机产生字母的ascii码mov [si],dl ;将随机产生的字符放入到letters中inc si ;letters的偏移量加1inc bxcall DELAY ;计数量加1cmp bx,num ;将已产生的字符量与所需产生的字符数比较jnz output_letter ;当小于所需产生的字符数时,跳转至output_lettermov [si],'$' ;字符串结束retgetletter endp;*************************************;实现字符串的换行输出outletter proclea si,letters ;获取letters的首地址again:mov dl,[si] ;将字符串相应偏移地址里的字符放入dl 中mov ah,02h ;显示字符int 21hinc si ;letters偏移地址加1cmp [si],'$' ;判断是否已经到字符串的末尾jz q2 ;当已到达字符串末尾时跳转至q2,反之顺序执行mov ah,03h ;获取光标当前位置 dh=行号,dl=列号 mov bh,0int 10hcmp dl,75d ;判断光标列号是否为75,即已到达改行末尾jz q1 ;当光标列号是为75跳转至q1jmp againq1: add dh,2d ;将当前光标行号加2,实现隔行输出setcusor 0d,dh,10d ;重新设定光标位置jmp againq2: retoutletter endpinputletter proclea si,letters ;获取字符串的首地址mov cx,num ;将字符串的长度放入cx中input:push cx ;将cx压栈mov ah,03h ;获取光标当前位置 dh=行号,dl=列号 mov bh,0 ;页号为0int 10hcmp dl,75d ;将光标当前列号与75作比较jz l5 ;当光标当前列已是75则跳转到l5l6: mov ah,7 ;输入字符无回显,al接收输入字符的ascii 码int 21hcmp al,08h ;判断输入键是否为退格键(退格键ascii 码为08h)je l3 ;当输入退格键跳转至l3,若不是则往下执行cmp al,27 ;判断输入键是否为esc键(esc键ascii 码为27h)je quit ;当输入的是esc键,跳转至qiut,若不是则往下执行cmp al,[si] ;将输入字符与letters里相应字符比较je l1 ;当相等时跳转至l1,反之往下执行jne l2 ;当输入的字符与letters里相应字符不相等,跳转至l2done: mov dl,al ;将输入的字符放入dl中mov ah,2 ;输出字符int 21hinc si ;letters的偏移量加1pop cxdec cxjnz inputjmp l4l1: add numb,1 ;输入的字符正确,记录输入输入正确个数的numb加1mov ah,09H ;在当前光标位置显示字符,不改变光标位置mov bh,0Hmov bl,2fh ;背景颜色为绿色mov cx,1int 10Hjmp donel2:call SOUND ;输入错误mov ah,09H ;在当前光标位置显示字符,不改变光标位置mov bh,0Hmov bl,4fh ;Z表示颜色。
英文打字练习程序源代码
lbl_score.BackColor = vbGreen
Timer1.Enabled = True
Timer2.Enabled = True
End If
End Sub
Private Sub Form_Load()
If KeyAscii = 27 Then
Timer1.Enabled = False
Timer2.Enabled = False
lbl_score.BackColor = vbYellow
lbl_score.Caption = "成绩: " & right & "分" & " 错误: " & wrong & " 个" & " 正确率: " & Int(right / keynum * 100) & "%" & " 按任意键继续"
With lbl_letter.Font
.Name = "宋体"
.Size = 20
.Bold = True
End With
lbl_letter.ForeColor = vbYellow
lbl_letter.BackColor = Form1.BackColor
Timer2.Enabled = True
Timer1.Interval = 100
Timer2.Interval = 1000
'隐藏命令按钮
Command1.Visible = False
Command2.Visible = False
C语言打字训练系统
void Frame(); void GetCharacter(); void Typing(); int LittleWin(int WinType/*=1, quitgame; =2, Help;=3, About; =4, others;*/) /*when WinType=1, return 0, quit, return 1, not quit*/ { int i; char ch; window(18,6,62,20); textbackground(LIGHTGRAY); textcolor(BLACK); clrscr(); gotoxy(1,1); cprintf("%c",201); for(i=0;i<43;i++) cprintf("%c",205); cprintf("%c",187); for(i=0;i<13;i++) { gotoxy(1,i+2); cprintf("%c",186); gotoxy(45,i+2); cprintf("%c",186); } gotoxy(1,14); cprintf("%c",200); for(i=0;i<43;i++) cprintf("%c",205); cprintf("%c",188); gotoxy(20,1); switch(WinType) { case 1: cprintf(" Exit "); textcolor(LIGHTRED);
circle(x1,y1,r); */
/*步骤二、使用当前颜色绘制一个闭合图形
汉字打字练习_java代码
word=(char)k;
show.setText(""+word);
try{sleep(6000);}
catch(InterruptedException e){}
k++;
if(k>=29968)k=19968;
}
}
}
class MainFrame extends Frame implements ActionListener{
southPanel.add(inputText);
southPanel.add(scoreText);
add(southPanel,BorderLayout.SOUTH);
setBounds(100,100,350,180);
setVisible(true);
validate();
addWindowListener(new WindowAdapter(){
score++;
}
scoreText.setText("得分"+score);
inputText.setText(null);
}
}
}
}
class WordThread extends Thread{
//通过继承Thread类创建线程
char word;
int k=19968;
Label show;Wo来自dThread(Label show){
this.show=show;
}
public void run(){
//重载run函数
k=19968;
Label wordLabel;
打字练习代码
最近发现很对人需要打字程序的代码,新作了一个,还有些小功能可以自己补充。
ZIP发不上来,只能让大家自己复制下去了。
Option ExplicitSub cswz() '产生位置Randomizewz = Rnd() * (Picture1.Width - 200)End SubSub cszm()RandomizeIf nd = 1 Thenzm = Chr(Int(26 * Rnd + 65))'Label1(0).Caption = Chr(Int((90 - 65 + 1) * Rnd + 65)) '产生一个介于65到90之间的随机数ElseIf nd = 2 Thenzm = Chr(Int(58 * Rnd + 65))Elsezm = Chr(Int(75 * Rnd + 48))End IfEnd SubPrivate Sub Command1_Click()df = 0Command4.Visible = FalseCommand1.Visible = Falsesdsd '调用产生速度设定值Timer1.Interval = sd1syt = 200Picture1.SetFocuscswz '调用产生位置子程序Label1(0).Left = wzcswz '调用产生位置子程序Label1(1).Left = wzcswz '调用产生位置子程序Label1(2).Left = wzcswz '调用产生位置子程序Label1(3).Left = wzcswz '调用产生位置子程序Label1(4).Left = wzcswz '调用产生位置子程序Label1(5).Left = wzcszm '调用产生字母子程序Label1(0).Caption = zmcszm '调用产生字母子程序Label1(1).Caption = zmcszm '调用产生字母子程序Label1(2).Caption = zmcszm '调用产生字母子程序Label1(3).Caption = zmcszm '调用产生字母子程序Label1(4).Caption = zmcszm '调用产生字母子程序Label1(5).Caption = zmTimer1.Enabled = True ' 激活Time1控件Timer2.Enabled = True ' 激活Time2控件Label3.Caption = "当前得分:" & dfLabel4.Caption = "剩余时间:" & sytLabel2.Caption = "当前难度等级:" & ndLabel5.Caption = "当前速度等级:" & sdEnd SubPrivate Sub Command2_Click()EndEnd SubPrivate Sub Command4_Click()Form2.ShowEnd SubPrivate Sub Form_Load()RandomizeTimer1.Enabled = False ' Time1控件失效Timer2.Enabled = False ' Time2控件失效Command1.Visible = FalseEnd SubPrivate Sub Picture1_KeyPress(KeyAscii As Integer)If Chr(KeyAscii) = Label1(0).Caption Thendf = df + 1BeepLabel3.Caption = "当前得分:" & dfcszmcswzLabel1(0).Left = wzLabel1(0).Caption = zmLabel1(0).Top = 0ElseIf Chr(KeyAscii) = Label1(1).Caption Thendf = df + 1BeepLabel3.Caption = "当前得分:" & dfcszmcswzLabel1(1).Left = wzLabel1(1).Caption = zmLabel1(1).Top = 0ElseIf Chr(KeyAscii) = Label1(2).Caption Then df = df + 1BeepLabel3.Caption = "当前得分:" & dfcszmcswzLabel1(2).Left = wzLabel1(2).Caption = zmLabel1(2).Top = 0ElseIf Chr(KeyAscii) = Label1(3).Caption Then df = df + 1Label3.Caption = "当前得分:" & dfcszmcswzBeepLabel1(3).Left = wzLabel1(3).Caption = zmLabel1(3).Top = 0ElseIf Chr(KeyAscii) = Label1(4).Caption Then df = df + 1BeepLabel3.Caption = "当前得分:" & dfcszmcswzLabel1(4).Left = wzLabel1(4).Caption = zmLabel1(4).Top = 0ElseIf Chr(KeyAscii) = Label1(5).Caption Then df = df + 1BeepLabel3.Caption = "当前得分:" & dfcszmcswzLabel1(5).Left = wzLabel1(5).Caption = zmLabel1(5).Top = 0End IfEnd SubPrivate Sub Timer1_Timer()Label1(0).Top = Label1(0).Top + Rnd * 300 Label1(1).Top = Label1(1).Top + Rnd * 300 Label1(2).Top = Label1(2).Top + Rnd * 300 Label1(3).Top = Label1(3).Top + Rnd * 300 Label1(4).Top = Label1(4).Top + Rnd * 300 Label1(5).Top = Label1(5).Top + Rnd * 300 If Label1(0).Top > Picture1.Height Then cszmcswzLabel1(0).Left = wzLabel1(0).Caption = zmLabel1(0).Top = 0End IfIf Label1(1).Top > Picture1.Height Then cszmcswzLabel1(1).Left = wzLabel1(1).Caption = zmLabel1(1).Top = 0End IfIf Label1(2).Top > Picture1.Height Then cszmcswzLabel1(2).Left = wzLabel1(2).Caption = zmLabel1(2).Top = 0End IfIf Label1(3).Top > Picture1.Height Then cszmcswzLabel1(3).Left = wzLabel1(3).Caption = zmLabel1(3).Top = 0End IfIf Label1(4).Top > Picture1.Height Then cszmcswzLabel1(4).Left = wzLabel1(4).Caption = zmLabel1(4).Top = 0End IfIf Label1(5).Top > Picture1.Height ThencszmcswzLabel1(5).Left = wzLabel1(5).Caption = zmLabel1(5).Top = 0End IfEnd SubPrivate Sub Timer2_Timer() '剩余时间扣除计时syt = syt - 1 '扣除剩余个数中的一个Label4.Caption = "剩余时间:" & sytIf syt <= 0 ThenTimer1.Enabled = False ' 剩余个数小于等于0的时候结束练习'Label1.Caption = "" '不显示字母' Label6.Caption = ""Select Case dfCase Is <= 80MsgBox vbCrLf + "别放弃,再来一次!" ' 显示信息框Case Is < 120MsgBox vbCrLf + "成绩不错,加油!"Case Is < 150MsgBox vbCrLf + "再努力做的更好一些!"Case Is > 180MsgBox vbCrLf + "好厉害!最高分呀!"End SelectCommand4.Visible = TrueTimer1.Enabled = FalseTimer2.Enabled = FalseLabel1(0).Caption = ""Label1(1).Caption = ""Label1(2).Caption = ""Label1(3).Caption = ""Label1(4).Caption = ""Label1(5).Caption = ""Label1(0).Top = 0Label1(1).Top = 0Label1(2).Top = 0Label1(3).Top = 0Label1(4).Top = 0Label1(5).Top = 0End IfEnd Sub设定窗口代码:Option ExplicitPrivate Sub Command1_Click()If Option1.Value = True Thennd = 1ElseIf Option2.Value = True Thennd = 2Elsend = 3End IfIf Option4.Value = True Thensd = 1ElseIf Option5.Value = True Thensd = 2Elsesd = 3End IfForm2.Hidemand1.Visible = TrueEnd SubPrivate Sub Form_Load()Option1.Value = TrueOption4.Value = TrueEnd SubPrivate Sub Form_Unload(Cancel As Integer)Form2.HideEnd Sub模块代码:Option ExplicitPublic nd, sd, sd1 As Integer '定义公共变量难度和速度Public df, syt, wz As Integer '定义公共变量分数剩余时间Public zm As String '定义随机产生的字母Public Sub sdsd() '定义速度值If sd = 1 Thensd1 = 800ElseIf sd = 2 Thensd1 = 500Elsesd1 = 300 End If End Sub。
汉字打字练习_java代码
southPanel.add(scoreText);
add(southPanel,BorderLayout.SOUTH);
setBounds(100,100,350,180);
setVisible(true);
validate();
addWindowListener(new WindowAdapter(){
Label wordLabel;
Button button;
TextField inputText,scoreText;
WordThread giveWord;
int score=0;
MainFrame(){
wordLabel=new Label(" ",Label.CENTER);
wordLabel.setFont(new Font("",Font.BOLD,72));
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
}
public void actionPerformed(ActionEvent e){
if (e.getSource()==button){
if(!(giveWord.isAlive())){
import java.awt.*;
import java.awt.event.*;
public class E10_1{
public static void main(String[] args){
//TODO Auto-generated method stub
一个简单的打字练习程序
类似于学习机上的指法练习程序,简单⽽实⽤#includemain(){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;}}}。
打字练习软件源代码
打字练习软件源代码12import javax.swing.*;3import java.awt.*;456/**7* This code was edited or generated using CloudGarden's Jigloo8* SWT/Swing GUI Builder, which is free for non-commercial9* use. If Jigloo is being used commercially (ie, by a corporation,10* company or business for any purpose whatever) then you11* should purchase a license for each developer using Jigloo.12* Please visit for details.13* Use of Jigloo implies acceptance of these licensing terms.14* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR15* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED16* LEGALL Y FOR ANY CORPORATE OR COMMERCIAL PURPOSE.*/1718public class Chat extends JInternalFrame{19MainFrame parent;private JTextPane jtp;2021private JTextField txtData;2223public Chat(MainFrame parent){24this.parent=parent;2526setLayer(4);27setBounds(1,326,0,0);28this.setPreferredSize(new java.awt.Dimension(140, 223));29((javax.swing.plaf.basic.BasicInternalFrameUI) this.getUI()).setNorthPane(null);30this.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);31GridBagLayout thisLayout = new GridBagLayout();32thisLayout.rowWeights = new double[] {0.1, 0.1, 0.0, 0.0};thisLayout.rowHeights = new int[] {7, 7, 49, 56};3334thisLayout.columnWeights = new double[] {0.0, 0.0, 0.0, 0.0};35thisLayout.columnWidths = new int[] {0, 45, 45, 48};getContentPane().setLayout(thisLayout);3637setVisible(true);38pack();39{40jtp = new JTextPane();41getContentPane().add(jtp, new GridBagConstraints(1, 0, 4, 5, 0.0, 0.0,42GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));43jtp.setPreferredSize(new Dimension(140, 160));44jtp.setEditable(false);45}46{47txtData = new JTextField();48getContentPane().add(txtData, new GridBagConstraints(1, 7, 3, 1, 0.0, 0.0, 49GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));txtData.setColumns(10);5051}52}53}5455import java.io.*;56public class DistillText {57public static String getData(String fileName,int segment){58int i=0;59if((fileName==null) || (fileName.length()==0))60return"";61File f;62FileReader in=null;63String s="";64try{65f=new File(fileName);66in=new FileReader(f);67char[] buffer=new char[312];68int len;69if(ng.equals("English")){70if(segment>=(int)(f.length()/312))71PublicData.textTag=0;72}73if(ng.equals("Chinese")){74if(segment>=(int)(f.length()/312-1)+1)75PublicData.textTag=0;76}77while((len=in.read(buffer))!=-1){78s=new String(buffer,0,len);79i++;80if(i==segment){81PublicData.textTag++;82break;83}84}85}86catch(IOException e){87System.out.println(e);88}89finally{90try{91if(in!=null)92in.close();93}94catch(IOException e){}95}96return s;97}98}99100import java.awt.FlowLayout;101import java.awt.GridBagConstraints;102import java.awt.GridLayout;103import java.awt.Insets;import java.awt.event.ActionEvent;104105import java.awt.event.ActionListener;106import javax.swing.text.*;107import javax.swing.*;108import java.awt.*;109110import javax.swing.event.*;111112public class Editor extends JInternalFrame implements DocumentListener,Runnable{ 113114Runtime r=Runtime.getRuntime();115Hint parent;116117Document doc;118StyledDocument styledDoc = new DefaultStyledDocument();119Thread th;120121private int hour=0;//时private int minute=0;//分122123private int second=0;//秒124private JLabel lblTime;125126private JTextField txtCount;127private JLabel lblError;private JCheckBox on_off_Hint;128129private JButton btnRight;private JButton btnError;130131private JCheckBox faze;132private JCheckBox grade;private JCheckBox on_off_Assistant;133134private JPanel pCollocate;135private JTextPane txtOriginal;136private JTextPane txtNewText;137private JPanel pShowData;138private JButton btnClose;139private JLabel lblWord;140private JTextField txtMW;141private JLabel lblM;142private JTextField txtError;143private JTextField txtRight;144private JLabel lblRight;private JLabel lblCount;145146private JTextField txtTime;147private JPanel pAttrib;148149//记录输入的正确和错误的个数据150private int rightWord=0;151private int errorWord=0;152private int rightCount=0;153private int errorCount=0;154private int wordCount=0;155//临时156private boolean temp=true;157158159public Editor(Hint parent){160161this.parent=parent;162th=new Thread(this);163164165//组建Editor用户界面....166167setLayer(4);168setBounds(142,0,0,0);169this.setPreferredSize(new java.awt.Dimension(657, 325));//内部窗体大小170((javax.swing.plaf.basic.BasicInternalFrameUI) this.getUI()).setNorthPane(null); 171this.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);getContentPane().setLayout(null);172173this.setVisible(true);{174175pAttrib = new JPanel();176getContentPane().add(pAttrib, new GridBagConstraints(1, 0, 12, 3, 0.0, 0.0, 177GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); 178FlowLayout pAttribLayout = new FlowLayout();179pAttrib.setBorder(BorderFactory.createTitledBorder(""));pAttrib.setLayout(pAttribLayout);180181pAttrib.setBounds(-2, 33, 658, 42);182{lblTime = new JLabel();183184pAttrib.add(lblTime);185lblTime.setText("\u7528\u65f6:");186lblTime.setFont(new java.awt.Font("新宋体", 0, 12));187}188{189txtTime = new JTextField(8);190pAttrib.add(txtTime);191txtTime.setText("00:00:00");192txtTime.setEditable(false);txtTime.setHorizontalAlignment(SwingConstants.CENTER);193194}195{196lblCount = new JLabel();197pAttrib.add(lblCount);198lblCount.setText("\u603b\u5b57\u6570:");199lblCount.setFont(new java.awt.Font("新宋体", 0, 12));200}201{202txtCount = new JTextField();203pAttrib.add(txtCount);txtCount.setColumns(6);204205txtCount.setText("0");206txtCount.setEditable(false);207txtCount.setHorizontalAlignment(SwingConstants.CENTER);208}209{lblRight = new JLabel();210211pAttrib.add(lblRight);212lblRight.setText("\u6b63\u786e:");lblRight.setFont(new java.awt.Font("新宋体", 0, 12));213214}215{txtRight = new JTextField();216217pAttrib.add(txtRight);txtRight.setColumns(4);218219txtRight.setText("0");220txtRight.setEditable(false);221txtRight.setHorizontalAlignment(SwingConstants.CENTER); 222}223{lblError = new JLabel();224225pAttrib.add(lblError);226lblError.setText("\u9519\u8bef:");lblError.setFont(new java.awt.Font("新宋体", 0, 12));227228}229{230txtError = new JTextField();231pAttrib.add(txtError);232txtError.setColumns(4);233txtError.setText("0");234txtError.setEditable(false);235txtError.setHorizontalAlignment(SwingConstants.CENTER); 236}{237238lblM = new JLabel();239pAttrib.add(lblM);240lblM.setText("\u6bcf\u5206\u949f");241lblM.setFont(new java.awt.Font("新宋体", 0, 12));242}243{244txtMW = new JTextField();245pAttrib.add(txtMW);246txtMW.setColumns(4);247txtMW.setText("0");txtMW.setEditable(false);248249txtMW.setHorizontalAlignment(SwingConstants.CENTER); 250}251{252lblWord = new JLabel();253pAttrib.add(lblWord);lblWord.setText("\u4e2a\u5b57");254255lblWord.setFont(new java.awt.Font("新宋体", 0, 12));256}{257258btnClose = new JButton();259pAttrib.add(btnClose);btnClose.setText("\u79bb\u5f00");260261btnClose.setIcon(new ImageIcon(getClass().getClassLoader().getResource("Image/leave.gif")));262263btnClose.setFont(new java.awt.Font("新宋体", 0, 12));264btnClose.addActionListener(new ActionListener() {265public void actionPerformed(ActionEvent evt) {266exitFram();267}});268269}270}{271272pShowData = new JPanel();273getContentPane().add(274pShowData,275new GridBagConstraints(2761,2771,27812,27910,2800.0,0.0,281282GridBagConstraints.CENTER,283GridBagConstraints.BOTH,284new Insets(0, 0, 0, 0),2850,2860));287GridLayout pShowDataLayout = new GridLayout(2, 1);288pShowDataLayout.setHgap(5);289pShowDataLayout.setVgap(5);290pShowDataLayout.setColumns(1);291pShowDataLayout.setRows(2);pShowData.setLayout(pShowDataLayout);292293pShowData.setBounds(5, 82, 644, 231);294{295txtOriginal = new JTextPane(styledDoc);296pShowData.add(txtOriginal);297txtOriginal.setPreferredSize(new java.awt.Dimension(600, 0));txtOriginal.setEditable(false);298299}300{txtNewText = new JTextPane();301302pShowData.add(txtNewText);303txtNewText.setPreferredSize(new java.awt.Dimension(600, 0));Document doc=txtNewText.getDocument();304305doc.addDocumentListener(this);306307}308}309{310pCollocate = new JPanel();311getContentPane().add(312pCollocate,313new GridBagConstraints(3141,31511,31612,3172,3180.0,3190.0,320GridBagConstraints.SOUTH,321GridBagConstraints.BOTH,322new Insets(0, 0, 0, 0),3230,3240));FlowLayout pCollocateLayout = new FlowLayout();325326pCollocate.setBorder(BorderFactory.createTitledBorder(""));327pCollocate.setLayout(pCollocateLayout);328pCollocate.setBounds(-2, -2, 658, 35);329{330on_off_Hint = new JCheckBox();331pCollocate.add(on_off_Hint);332on_off_Hint.setText("\u5173\u95ed\u5b57\u6bcd\u63d0\u793a"); 333on_off_Hint.setSelected(true);334on_off_Hint.setFont(new java.awt.Font("新宋体",0,12));335}{336337on_off_Assistant = new JCheckBox();338pCollocate.add(on_off_Assistant);on_off_Assistant.setText("\u5173\u95ed\u6c49\u5b57\u52a9\u624b"); 339340on_off_Assistant.setSelected(true);341on_off_Assistant.setFont(new java.awt.Font("新宋体",0,12));342}343{344grade = new JCheckBox();pCollocate.add(grade);345346347grade.setText("\u79bb\u5f00\u65f6\u662f\u5426\u663e\u793a\u6210\u7ee9");348grade.setSelected(true);349grade.setFont(new java.awt.Font("新宋体",0,12));}350351{352faze = new JCheckBox();pCollocate.add(faze);353354355faze.setText("\u804a\u5929\u7cfb\u7edf\u5f00\u542f\u65f6\u663e\u793a\u81ea\u5df1\u768 4\u72b6\u6001");356357faze.setSelected(true);358faze.setFont(new java.awt.Font("新宋体",0,12));}359360{361btnError = new JButton();362pCollocate.add(btnError);363//btnError.setIcon(new364ImageIcon(getClass().getClassLoader().getResource("Image/Error.gif")));365btnError.setBackground(new java.awt.Color(255,255,255));366367btnError.setToolTipText("\u9519\u8bef\u6587\u5b57\u7528\u7ea2\u8272\u8868\u793a"); 368btnError.setText("×");btnError.setPreferredSize(new java.awt.Dimension(47, 17));369370btnError.setFont(new java.awt.Font("新宋体",1,12));371btnError.setForeground(new java.awt.Color(219,32,36));372}373{374btnRight = new JButton();375pCollocate.add(btnRight);376//btnRight.setIcon(newImageIcon(getClass().getClassLoader().getResource("Image/Right.gif")));377378btnRight.setBackground(new java.awt.Color(255,255,255));379btnRight.setToolTipText("\u6b63\u786e\u6587\u5b57\u7528\u84dd\u8272\u8868\u793a"); 380381btnRight.setText("\u221a");382btnRight.setFont(new java.awt.Font("新宋体",1,12));383btnRight.setPreferredSize(new java.awt.Dimension(47, 17));384btnRight.setForeground(new java.awt.Color(0,0,255));385}386387txtOriginal.setText(DistillText.getData(PublicData.Text,PublicData.textTag)); 388//PublicData.key=txtOriginal.getText().substring(0,1);Empty empty=new Empty();389390empty.start();391if(txtOriginal.getText().length()!=0){392393if(ng.equals("English")){PublicData.key=txtOriginal.getText().substring(0,1); 394395this.parent.repaint();396}397if(ng.equals("Chinese")){398PublicData.key="";399}}400401}402this.pack();txtNewText.requestFocus();403404th.start();}405406407//判断正确和错误的字.并改变它们的颜色408public void chDocs(int xLen,int yLen,String xStr,String yStr)409{410SimpleAttributeSet attrSet=new SimpleAttributeSet();411rightWord=0;412errorWord=0;413for(int i=1;i<=xLen;i++)414{415if(i<=yLen){//数据验证416if(xStr.substring(i-1,i).equals(yStr.substring(i-1,i))){417rightWord++;418StyleConstants.setForeground(attrSet,Color.BLUE); 419}420else{421errorWord++;422StyleConstants.setForeground(attrSet,Color.RED); 423}StyleConstants.setUnderline(attrSet,true);424425}426else{StyleConstants.setForeground(attrSet,Color.BLACK); 427428StyleConstants.setUnderline(attrSet,false);429}styledDoc.setCharacterAttributes(i-1,1,attrSet,true);430431}432txtRight.setText((rightWord+rightCount)+"");433434txtError.setText((errorWord+errorCount)+"");435int c=0;for(int i=0;i<minute;i++){436437c=c+60;438}439c=c+second;440double s=(double)c/60;441txtMW.setText(""+Math.round(((double)Integer.parseInt(txtRight.getText()))/s)); 442}443444//实现DocumentListener所有的方法..用于监听输入文本...445public void changedUpdate(DocumentEvent e){446if(ng.equals("English")){447PublicData.key=txtOriginal.getText().substring(txtNewText.getText().length(), 448txtNewText.getText().length()+1);449this.parent.repaint();450}451if(ng.equals("Chinese")){452PublicData.key="";453}454}455public void insertUpdate(DocumentEvent e){456if(ng.equals("English")){457try{458459PublicData.key=txtOriginal.getText().substring(txtNewText.getText().length(),460txtNewText.getText().length()+1);461}catch(StringIndexOutOfBoundsException str){}462this.parent.repaint();463}464if(ng.equals("Chinese")){PublicData.key="";465466}467}468469public void removeUpdate(DocumentEvent e){470if(ng.equals("English")){471PublicData.key=txtOriginal.getText().substring(txtNewText.getText().length(), 472txtNewText.getText().length()+1);473this.parent.repaint();474}475if(ng.equals("Chinese")){476PublicData.key="";477}478}479480//数据验证481private void dataValidate(){chDocs(txtOriginal.getText().length(),txtNewText.getText()482483.length(),txtOriginal.getText(),txtNewText.getText());484if(txtOriginal.getText().length()>txtNewText.getText().length()){if(ng.equals("English")){485486487PublicData.key=txtOriginal.getText().substring(txtNewText.getText().length(),txtNewText.getText().length()+1);488489}490if(ng.equals("Chinese")){PublicData.key="";491492}493txtCount.setText((txtNewText.getText().length()+wordCount)+"");494}495else{496wordCount=wordCount+txtOriginal.getText().length();497rightCount=rightCount+rightWord;498errorCount=errorCount+errorWord;499txtOriginal.setText(DistillText.getData(PublicData.Text,PublicData.textTag)); 500501if(ng.equals("English")){502PublicData.key=txtOriginal.getText().substring(0,1);503this.parent.repaint();504}505if(ng.equals("Chinese")){506PublicData.key="";507this.parent.repaint();508}}509510}511//退出时所要关闭的窗体512513private void exitFram(){514PublicData.key="";515PublicData.Text="";516this.parent.repaint();517this.parent.doDefaultCloseAction();518this.doDefaultCloseAction();519PublicData.onChoice=true;520PublicData.textTag=1;521r.gc();522System.gc();523}524525//计时器526public void run(){527try{528while(true){529Thread.sleep(1000);530second++;531if(second==60){532second=0;533minute++;if(minute==60){534535minute=0;536hour++;537if(hour==1000){538second=0;539minute=0;540hour=0;541}542}543}544txtTime.setText(((hour<=9)?"0":"")+hour+":"+((minute<=9)?"0":"")+minute+":"+((second<=9)?"0":"")+second);545546}547}catch (InterruptedException e){}548549}550class Empty extends Thread{551552public void run(){553while(true){554try{555Thread.sleep(100);556dataValidate();557if(txtNewText.getText().length()>=txtOriginal.getText().length()){ 558txtNewText.setText("");559}560}561catch(InterruptedException e){}562}563}564}565}566import java.awt.event.ActionEvent;import java.awt.event.ActionListener;567568import javax.swing.*;569570571572/**573* This code was edited or generated using CloudGarden's Jigloo* SWT/Swing GUI Builder, which is free for non-commercial574575* use. If Jigloo is being used commercially (ie, by a corporation,576* company or business for any purpose whatever) then you577* should purchase a license for each developer using Jigloo.578* Please visit for details.579* Use of Jigloo implies acceptance of these licensing terms.580* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR581* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED582* LEGALL Y FOR ANY CORPORATE OR COMMERCIAL PURPOSE.583*/584public class Etymon extends JInternalFrame{585private Hint parent;586587private JButton btnCelean;588private JLabel lblword;private JPanel p4;589590private JPanel p3;591private JPanel p2;592private JTextField txtMSword;593private JLabel lblRight;594private JTextField txtRight;595private JLabel lblM;596private JTextField txtError;597private JLabel lblError;598private JTextField txtCountWord;599private JLabel countWord;600private JTextField txtTime;601private JLabel lblTime;602private JPanel p1;603private JLabel lblt;604605private JLabel[] ShowWord;606public Etymon(Hint parent){607608this.parent=parent;609setLayer(7);610611setBounds(142,0,0,0);this.setPreferredSize(new java.awt.Dimension(657, 325));//内部窗体大小612613((javax.swing.plaf.basic.BasicInternalFrameUI) this.getUI()).setNorthPane(null);this.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);614615getContentPane().setLayout(null);616this.setVisible(true);617{618lblt = new JLabel();619getContentPane().add(lblt);lblt.setIcon(new ImageIcon(getClass().getClassLoader().getResource( 620621"Image/zgt.gif")));622lblt.setBounds(26, 40, 602, 189);}623624{625p1 = new JPanel();626getContentPane().add(p1);627p1.setBounds(-2, -2, 658, 42);628p1.setBorder(BorderFactory.createTitledBorder(""));629{630lblTime = new JLabel();631p1.add(lblTime);632lblTime.setText("\u7528\u65f6:");lblTime.setPreferredSize(new java.awt.Dimension(30, 14));633634lblTime.setFont(new java.awt.Font("新宋体",0,12));635}636{637txtTime = new JTextField();638p1.add(txtTime);639txtTime.setText("00:00:00");640txtTime.setEditable(false);641txtTime.setPreferredSize(new java.awt.Dimension(69, 20));642txtTime.setFont(new java.awt.Font("新宋体",0,12));643txtTime.setHorizontalAlignment(SwingConstants.CENTER);}644645{646countWord = new JLabel();647p1.add(countWord);648countWord.setText("\u603b\u5b57\u6570:");649countWord.setFont(new java.awt.Font("新宋体",0,12));}650651{652txtCountWord = new JTextField();p1.add(txtCountWord);653654txtCountWord.setText("0");655txtCountWord.setPreferredSize(new java.awt.Dimension(69, 20));txtCountWord.setFont(new java.awt.Font("新宋体",0,12));656657txtCountWord.setHorizontalAlignment(SwingConstants.CENTER);659}660{661lblRight = new JLabel();662p1.add(lblRight);663lblRight.setText("\u6b63\u786e:");664lblRight.setFont(new java.awt.Font("新宋体",0,12));665}666{txtRight = new JTextField();667668p1.add(txtRight);669txtRight.setText("0");670txtRight.setPreferredSize(new java.awt.Dimension(69, 20)); 671txtRight.setFont(new java.awt.Font("新宋体",0,12));672txtRight.setEditable(false);673txtRight.setHorizontalAlignment(SwingConstants.CENTER); 674}675{676lblError = new JLabel();677p1.add(lblError);lblError.setText("\u9519\u8bef:");678679lblError.setFont(new java.awt.Font("新宋体",0,12));680}{681682txtError = new JTextField();683p1.add(txtError);684txtError.setText("0");685txtError.setPreferredSize(new java.awt.Dimension(69, 20)); 686txtError.setFont(new java.awt.Font("新宋体", 0, 12));txtError.setEditable(false);687688txtError.setHorizontalAlignment(SwingConstants.CENTER); 689}{690691lblM = new JLabel();692p1.add(lblM);693lblM.setText("\u6bcf\u5206\u949f");694lblM.setFont(new java.awt.Font("新宋体",0,12));695}696{697txtMSword = new JTextField();698p1.add(txtMSword);699txtMSword.setText("0");txtMSword.setPreferredSize(new java.awt.Dimension(69, 20)); 700701txtMSword.setFont(new java.awt.Font("新宋体",0,12));703txtMSword.setHorizontalAlignment(SwingConstants.CENTER); 704}705{706lblword = new JLabel();707p1.add(lblword);708lblword.setText("\u5b57");709lblword.setFont(new java.awt.Font("新宋体",0,12));710}{711712btnCelean = new JButton();713p1.add(btnCelean);714btnCelean.setText("\u79bb\u5f00");715btnCelean.setFont(new java.awt.Font("新宋体", 0, 12));716btnCelean.setBounds(579, 236, 63, 21);717btnCelean.setBackground(new java.awt.Color(255, 255, 255)); 718btnCelean.addActionListener(new ActionListener() {719public void actionPerformed(ActionEvent evt) {720exit();721}});722723}724}{725726p2 = new JPanel();727getContentPane().add(p2);728p2.setBounds(-2, 229, 658, 28);729p2.setBorder(BorderFactory.createTitledBorder(""));730}{731732p3 = new JPanel();733getContentPane().add(p3);p3.setBounds(-2, 290, 658, 35);734735p3.setBorder(BorderFactory.createTitledBorder(""));736}737{738//ShowWord=new JLabel[20];739//for(int i=0;i<20;i++){740//ShowWord[i].setText("熊");741//}742p4 = new JPanel();743p4.setLayout(null);getContentPane().add(p4);744745p4.setBounds(-2, 257, 658, 35);p4.setBorder(BorderFactory.createTitledBorder(""));746747}748this.pack();749}750private void exit(){751this.parent.doDefaultCloseAction();this.doDefaultCloseAction();752753PublicData.onChoice=true;754PublicData.textTag=1;System.gc();755756}}757758759import javax.swing.*;760import javax.swing.event.*;761import javax.swing.text.html.*;762import java.awt.*;763import java.awt.event.ActionEvent;764import java.awt.event.ActionListener;765import java.io.*;766import .*;767768769/**770* This code was edited or generated using CloudGarden's Jigloo771* SWT/Swing GUI Builder, which is free for non-commercial772* use. If Jigloo is being used commercially (ie, by a corporation,773* company or business for any purpose whatever) then you774* should purchase a license for each developer using Jigloo.775* Please visit for details.776* Use of Jigloo implies acceptance of these licensing terms.777* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR 778* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED 779* LEGALL Y FOR ANY CORPORATE OR COMMERCIAL PURPOSE. 780*/781public class Help extends JInternalFrame{782783JEditorPane html;784private JPanel p;private JButton btnCencel;785786787public Help(){788try {789URL url = null;。
Python编写打字训练小程序
Python编写打字训练⼩程序你眼中的程序猿别⼈眼中的程序猿,是什么样⼦?打字如飞,各种炫酷的页⾯切换,⼀个个好似⿊客般的⽹站破解。
可现实呢?⼆指禅的敲键盘,写⼀⾏代码,查半天百度…那么如何能让我们从外表上变得更像⼀个程序猿呢?当然是训练我们的打字速度了啊!训练打字很羡慕那些盲打速度炒鸡快的⼈,看起来就⽐较炫酷。
但很多IT男打字速度并不快,甚⾄还有些⼆指禅的朋友们,太影响装13效果了。
那么今天我们就来使⽤Python写⼀个打字训练的⼩⼯具吧。
先来看看使⽤效果…我们使⽤Python内置的GUI模块Tkinter来编写⼀个打字测试的⼩⼯具。
点击开始测试,系统随机⽣成20个字符串,然后⽤户按照题⽬进⾏作答后,点击交卷,系统将对⽐我们的输⼊结果,来计算正确率,并使⽤涂⾊将系统与⽤户的答案进⾏对⽐。
⽣成随机数⾸先我们需要⽣成键盘上的字符。
当然我们可以0-9,A-Z,a-z,!-)等等的⼀个个枚举出键盘上的按键。
但有没有更快捷的操作呢?你需要了解下string模块。
这⾥介绍下⼏个string默认提供的内容:import string# 列举数字string.digits>>> '0123456789'# 列举⼩写字母string.ascii_lowercase>>> 'abcdefghijklmnopqrstuvwxyz'# 列举⼤写字母string.ascii_uppercase>>> 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'# 列举所有标点符号string.punctuation>>> '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'# 列举所有空⽩符string.whitespace>>> ' \t\n\r 0b 0c'string.ascii_letters =string.ascii_lowercase + string.ascii_uppercasestring.printable =string.ascii_letters + string.digits+ string.whitespace + string.punctuation剩余的内容,我们只需要进⾏相关读写判断即可,整体代码如下:# -*- coding: utf-8 -*-# @Author : 王翔# @JianShu : 清风Python# @Date : 2019/8/25 20:59# @Software : PyCharm# @version :Python 3.7.3# @File : TypingTest.pyfrom tkinter import *import randomimport stringfrom datetime import datetimeroot = Tk()root.title("Python打字练习题 By:清风Python")Label(root, text='系统题⽬:').grid(row=0)Label(root, text='⽤户作答:').grid(row=1)Label(root, text='考试结果:').grid(row=2)v1 = StringVar()v2 = StringVar()v3 = StringVar()v1.set("点击'开始测试'按钮开始出题")e1 = Entry(root, text=v1, state='disabled', width=40, font=('宋体', 14))e2 = Entry(root, textvariable=v2, width=40, font=('宋体', 14))e3 = Label(root, textvariable=v3, width=40, font=('宋体', 10), foreground='red')e1.grid(row=0, column=1, padx=10, pady=20)e2.grid(row=1, column=1, padx=10, pady=20)e3.grid(row=2, column=1, padx=10, pady=20)text = Text(root, width=80, height=7)text.grid(row=4, column=0, columnspan=2, pady=5)class TypingTest:def __init__(self):self.time_list = []self.letterNum = 20self.letterStr = ''.join(random.sample(string.printable.split(' ')[0], self.letterNum)) self.examination_paper = ''def time_calc(self):self.time_list.append(datetime.now())yielddef create_exam(self):text.delete(0.0, END)# e3.delete(0, END)v1.set(self.letterStr)self.time_calc().__next__()text.insert(END, "开始:%s \n" % str(self.time_list[-1]))user_only1.config(state='active')def score(self):wrong_index = []self.time_calc().__next__()text.insert(END, "结束:%s\n" % str(self.time_list[-1]))use_time = (self.time_list[-1] - self.time_list[-2]).secondsself.examination_paper = v2.get()if len(self.examination_paper) > self.letterNum:v3.set("输⼊数据有误,作答数⼤于考题数")else:right_num = 0for z in range(len(self.examination_paper)):if self.examination_paper[z] == self.letterStr[z]:right_num += 1else:wrong_index.append(z)if right_num == self.letterNum:v3.set("完全正确,正确率%.2f%%⽤时:%s秒" % ((right_num * 1.0) / self.letterNum * 100, use_time))else:v3.set("正确率%.2f%%⽤时:%s 秒" % ((right_num * 1.0) / self.letterNum * 100, use_time))# e2.delete(0, END)text.insert(END, "题⽬:%s\n" % self.letterStr)tag_info = list(map(lambda x: '4.' + str(x + 3), wrong_index))text.insert(END, "作答:%s\n" % self.examination_paper)for i in range(len(tag_info)):text.tag_add("tag1", tag_info[i])text.tag_config("tag1", background='red')user_only1.config(state='disabled')TypingTest = TypingTest()Button(root, text="开始测试", width=10, command=TypingTest.create_exam).grid(row=3, column=0, sticky=W, padx=30, pady=5)user_only1 = Button(root, text="交卷", width=10, command=TypingTest.score, state='disable')user_only1.grid(row=3, column=1, sticky=E, padx=30, pady=5)mainloop()我们将最终的代码,打包成exe⼯具,即可脱离python环境,在单独的电脑上执⾏exe⽂件玩我们⾃⼰的打字练习题了:总结以上所述是⼩编给⼤家介绍的Python编写打字训练⼩程序,希望对⼤家有所帮助,如果⼤家有任何疑问请给我留⾔,⼩编会及时回复⼤家的。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
最近发现很对人需要打字程序的代码,新作了一个,还有些小功能可以自己补充。
ZIP发不上来,只能让大家自己复制下去了。
Option ExplicitSub cswz() '产生位置Randomizewz = Rnd() * (Picture1.Width - 200)End SubSub cszm()RandomizeIf nd = 1 Thenzm = Chr(Int(26 * Rnd + 65))'Label1(0).Caption = Chr(Int((90 - 65 + 1) * Rnd + 65)) '产生一个介于65到90之间的随机数ElseIf nd = 2 Thenzm = Chr(Int(58 * Rnd + 65))Elsezm = Chr(Int(75 * Rnd + 48))End IfEnd SubPrivate Sub Command1_Click()df = 0Command4.Visible = FalseCommand1.Visible = Falsesdsd '调用产生速度设定值Timer1.Interval = sd1syt = 200Picture1.SetFocuscswz '调用产生位置子程序Label1(0).Left = wzcswz '调用产生位置子程序Label1(1).Left = wzcswz '调用产生位置子程序Label1(2).Left = wzcswz '调用产生位置子程序Label1(3).Left = wzcswz '调用产生位置子程序Label1(4).Left = wzcswz '调用产生位置子程序Label1(5).Left = wzcszm '调用产生字母子程序Label1(0).Caption = zmcszm '调用产生字母子程序Label1(1).Caption = zmcszm '调用产生字母子程序Label1(2).Caption = zmcszm '调用产生字母子程序Label1(3).Caption = zmcszm '调用产生字母子程序Label1(4).Caption = zmcszm '调用产生字母子程序Label1(5).Caption = zmTimer1.Enabled = True ' 激活Time1控件Timer2.Enabled = True ' 激活Time2控件Label3.Caption = "当前得分:" & dfLabel4.Caption = "剩余时间:" & sytLabel2.Caption = "当前难度等级:" & ndLabel5.Caption = "当前速度等级:" & sdEnd SubPrivate Sub Command2_Click()EndEnd SubPrivate Sub Command4_Click()Form2.ShowEnd SubPrivate Sub Form_Load()RandomizeTimer1.Enabled = False ' Time1控件失效Timer2.Enabled = False ' Time2控件失效Command1.Visible = FalseEnd SubPrivate Sub Picture1_KeyPress(KeyAscii As Integer)If Chr(KeyAscii) = Label1(0).Caption Thendf = df + 1BeepLabel3.Caption = "当前得分:" & dfcszmcswzLabel1(0).Left = wzLabel1(0).Caption = zmLabel1(0).Top = 0ElseIf Chr(KeyAscii) = Label1(1).Caption Thendf = df + 1BeepLabel3.Caption = "当前得分:" & dfcszmcswzLabel1(1).Left = wzLabel1(1).Caption = zmLabel1(1).Top = 0ElseIf Chr(KeyAscii) = Label1(2).Caption Then df = df + 1BeepLabel3.Caption = "当前得分:" & dfcszmcswzLabel1(2).Left = wzLabel1(2).Caption = zmLabel1(2).Top = 0ElseIf Chr(KeyAscii) = Label1(3).Caption Then df = df + 1Label3.Caption = "当前得分:" & dfcszmcswzBeepLabel1(3).Left = wzLabel1(3).Caption = zmLabel1(3).Top = 0ElseIf Chr(KeyAscii) = Label1(4).Caption Then df = df + 1BeepLabel3.Caption = "当前得分:" & dfcszmcswzLabel1(4).Left = wzLabel1(4).Caption = zmLabel1(4).Top = 0ElseIf Chr(KeyAscii) = Label1(5).Caption Then df = df + 1BeepLabel3.Caption = "当前得分:" & dfcszmcswzLabel1(5).Left = wzLabel1(5).Caption = zmLabel1(5).Top = 0End IfEnd SubPrivate Sub Timer1_Timer()Label1(0).Top = Label1(0).Top + Rnd * 300 Label1(1).Top = Label1(1).Top + Rnd * 300 Label1(2).Top = Label1(2).Top + Rnd * 300 Label1(3).Top = Label1(3).Top + Rnd * 300 Label1(4).Top = Label1(4).Top + Rnd * 300 Label1(5).Top = Label1(5).Top + Rnd * 300 If Label1(0).Top > Picture1.Height Then cszmcswzLabel1(0).Left = wzLabel1(0).Caption = zmLabel1(0).Top = 0End IfIf Label1(1).Top > Picture1.Height Then cszmcswzLabel1(1).Left = wzLabel1(1).Caption = zmLabel1(1).Top = 0End IfIf Label1(2).Top > Picture1.Height Then cszmcswzLabel1(2).Left = wzLabel1(2).Caption = zmLabel1(2).Top = 0End IfIf Label1(3).Top > Picture1.Height Then cszmcswzLabel1(3).Left = wzLabel1(3).Caption = zmLabel1(3).Top = 0End IfIf Label1(4).Top > Picture1.Height Then cszmcswzLabel1(4).Left = wzLabel1(4).Caption = zmLabel1(4).Top = 0End IfIf Label1(5).Top > Picture1.Height ThencszmcswzLabel1(5).Left = wzLabel1(5).Caption = zmLabel1(5).Top = 0End IfEnd SubPrivate Sub Timer2_Timer() '剩余时间扣除计时syt = syt - 1 '扣除剩余个数中的一个Label4.Caption = "剩余时间:" & sytIf syt <= 0 ThenTimer1.Enabled = False ' 剩余个数小于等于0的时候结束练习'Label1.Caption = "" '不显示字母' Label6.Caption = ""Select Case dfCase Is <= 80MsgBox vbCrLf + "别放弃,再来一次!" ' 显示信息框Case Is < 120MsgBox vbCrLf + "成绩不错,加油!"Case Is < 150MsgBox vbCrLf + "再努力做的更好一些!"Case Is > 180MsgBox vbCrLf + "好厉害!最高分呀!"End SelectCommand4.Visible = TrueTimer1.Enabled = FalseTimer2.Enabled = FalseLabel1(0).Caption = ""Label1(1).Caption = ""Label1(2).Caption = ""Label1(3).Caption = ""Label1(4).Caption = ""Label1(5).Caption = ""Label1(0).Top = 0Label1(1).Top = 0Label1(2).Top = 0Label1(3).Top = 0Label1(4).Top = 0Label1(5).Top = 0End IfEnd Sub设定窗口代码:Option ExplicitPrivate Sub Command1_Click()If Option1.Value = True Thennd = 1ElseIf Option2.Value = True Thennd = 2Elsend = 3End IfIf Option4.Value = True Thensd = 1ElseIf Option5.Value = True Thensd = 2Elsesd = 3End IfForm2.Hidemand1.Visible = TrueEnd SubPrivate Sub Form_Load()Option1.Value = TrueOption4.Value = TrueEnd SubPrivate Sub Form_Unload(Cancel As Integer)Form2.HideEnd Sub模块代码:Option ExplicitPublic nd, sd, sd1 As Integer '定义公共变量难度和速度Public df, syt, wz As Integer '定义公共变量分数剩余时间Public zm As String '定义随机产生的字母Public Sub sdsd() '定义速度值If sd = 1 Thensd1 = 800ElseIf sd = 2 Thensd1 = 500Elsesd1 = 300 End If End Sub。