英文打字练习程序源代码
编程实现输入一串英文
编程实现输入一串英文,统计其中各单词出现的个数(不区分大小写字母),以“000”作为字符串输入结束标志,例如:Twinkle twinkle little star 000(回车)twinkle little star2 1 1((这一学期刚学C语言,课后题如上,我的代码如下,总是出错,也不知道为什么,刚学到指针,请高手帮我找一下错误,若错误太多无法更正,就请附上您的代码,谢谢了。
))#include<stdio.h>#include<string.h>int main(){char str[100],ch;char *s2[30]; /*s2存放单词(不重复)*/char s3[30],*p=s3;inti,j,k=0,flag1,flag2,count1=0,white=1,a[30]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0};FILE *file;file=fopen("string.txt","w+");printf("Input a string of English:\n");gets(str);fputs(str,file);rewind(file);while((ch=fgetc(file))!='0') /*统计文件中有多少个单词*/{if((ch==' ')||(ch=='\t')||(ch=='\n'))white++;else{if(white){white=0;count1++;}}}rewind(file);for(i=0;i<count1;i++){flag1=0; /*是否有重复单词*/flag2=0; /*是否遇到空白字符*/p=s3;while(ch=fgetc(file)){if((ch!=' ')&&(ch!='\t')&&(ch!='0')){if((ch>64)&&(ch<91)) /*大写字母变小写*/{ch=ch+32;}*p++=ch;}else{flag2=1; /*遇到空白字符*/*p='\0';for(j=0;j<k;j++) /*k为s2中的单词个数*/{if(strcmp(s3,s2[j])==0){flag1=1; /*有重复单词*/a[j]++;break;}}if(flag1==0) /*如果单词不重复*/{s2[k]=s3;a[k]++;k++;}}if(flag2==1) /*如果遇到空白字符,则开始查询下一单词,跳出while循环*/{break;}}while(((ch=fgetc(file))==' ')||(ch=='\t')); /*吞掉多余的空白字符*/fseek(file,-1,1); /*后退一格,继续读*/}for(i=0;i<k;i++){printf("%s\t",s2[i]);}printf("\n");for(i=0;i<k;i++){printf("%d\t",a[i]);}printf("\n");fclose(file);return 0;}我来帮他解答2011-10-29 12:03满意回答。
打字程序代码
}
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");
cprintf("Do you really want to quit?");
textcolor(LIGHTGREEN);
gotoxy(18,9);
cprintf("OK? [Y/N]");
/*window(18,20,62,20);
textbackground(LIGHTBLUE);
sound(300); /*输出声音*/
delay(6000);
nosound();
outtextxy(100,250,"Typing Training");
sound(300); /*输出声音*/
delay(6000);
nosound();
outtextxy(150,300,"Software ... ^_^");
/*
练习训练游戏
*/
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <bios.h>
#include <dos.h>
c语言打字母游戏源码
c语言打字母游戏源码#include <graphics.h>#include <conio.h>#include <time.h>// 来自公众号:c语言与cpp编程// 欢迎界面void welcome(){// 输出屏幕提示cleardevice();setcolor(YELLOW);setfont(64, 0, "黑体");outtextxy(160, 50, "打字母游戏");setcolor(WHITE);setfont(16, 0, "宋体");outtextxy(100, 200, "就是很传统的那个掉字母然后按相应键就消失的游戏");outtextxy(100, 240, "只是做了一个简单的实现");outtextxy(100, 280, "功能并不很完善,比如生命数、分数等都没有写");outtextxy(100, 320, "感兴趣的自己加进去吧");// 实现闪烁的“按任意键继续”int c=255;while(!kbhit()){setcolor(RGB(c, 0, 0));outtextxy(280, 400, "按任意键继续");c -= 8;if (c < 0) c = 255;Sleep(20);}getch();cleardevice();}// 退出界面void goodbye(){cleardevice();setcolor(YELLOW);setfont(48, 0, "黑体");outtextxy(104, 180, "多写程序不老青春"); getch();}// 主函数void main(){initgraph(640, 480);// 初始化屏幕为 640x480 welcome();// 显示欢迎界面srand(time(NULL));// 设置随机种子setfont(16, 0, "Arial");// 设置字母的字体和大小setfillstyle(BLACK);// 设置清除字母的填充区域颜色char target;// 目标字母char key;// 用户的按键int x, y;// 字母的位置// 主循环while(true){target = 65 + rand() % 26;// 产生任意大写字母x = rand() % 620;// 产生任意下落位置for (y=0; y<460; y++){setcolor(WHITE);// 设置字母的颜色outtextxy(x, y, target);// 显示字母if(kbhit()){key = getch();// 获取用户按键if((key == target) || (key == target + 32)) {// 按键正确,“击落”字母(画黑色方块擦除)bar(x, y, x + 16, y + 16);break;// 跳出循环,进行下一个字母}else if (key == 27){goto EXIT;// 如果按 ESC,退出游戏主循环}}// 延时,并清除字母Sleep(10);bar(x, y, x + 16, y + 16); }}EXIT:// 退出部分goodbye();// 关闭图形界面closegraph();}。
C#简单打字练习程序CH10
C#简单打字练习程序CH10 using System;using System.Drawing;using System.Collections;using ponentModel;using System.Windows.Forms;using System.Threading;namespace MoveChar{/// <summary>/// frmMoveChar 的摘要说明。
/// </summary>public class frmMoveChar : System.Windows.Forms.Form{private System.Windows.Forms.Button bntStart;private System.Windows.Forms.Button bntExit;private System.Windows.Forms.Timer timerStart;private bel lblChar;private System.Windows.Forms.Panel pnlContainer;private ponentModel.IContainer components;public frmMoveChar(){//// Windows 窗体设计器⽀持所必需的//InitializeComponent();//// TODO: 在 InitializeComponent 调⽤后添加任何构造函数代码//}/// <summary>/// 清理所有正在使⽤的资源。
/// </summary>protected override void Dispose( bool disposing ){if( disposing ){if(components != null){components.Dispose();}}base.Dispose( disposing );}#region Windows 窗体设计器⽣成的代码/// <summary>/// 设计器⽀持所需的⽅法 - 不要使⽤代码编辑器修改/// 此⽅法的内容。
44按键输入英文字符程序
#define KEY_DELAY 2#define CHG_DELAY 200 //单键多值切换延时#define X1 0 //行列标志位(4*4)#define Y1 0#define X2 1#define Y2 1#define X3 2#define Y3 2#define X4 3#define Y4 3#define KEY_DDR DDRA#define KEY_PORT PORTA#define KEY_PIN PINAvolatile unsigned char gb_key_count[4][4]={{1,1,1,1}, {1,1,1,1}, {1,1,1,1}, {1,1,1,1}};//单键多值计数缓冲区volatile unsigned char gb_cs_num_letter = 0;//字母数字选择标志位(0-字母,1-数字)//unsigned char gb_key_count=1;//单键多值计数unsigned char gb_lcd_addr=1;unsigned char gb_addr_num_x=4,gb_addr_num_y;void lcd_scan_show(unsigned char model,unsigned char *pt1,unsigned char lenth1,unsigned char *pt2,unsigned char lenth2){unsigned char i = 0;switch(model){case 1:LCD_set_xy(1,1);for( i = 0;i < lenth2;i ++ ){Wr_Date(*pt2); //写显示数据pt2++; //字符串地址加1}LCD_set_xy(3,3);for( i = 0;i < lenth1;i ++ ){Wr_Date(*pt1 ); //写显示数据pt1++; //字符串地址加1}break;case 2:LCD_set_xy(3,3);for( i = 0;i < lenth1;i ++ ){Wr_Date(*pt1 ); //写显示数据pt1++; //字符串地址加1 }LCD_set_xy(1,1);for( i = 0;i < lenth2;i ++ ){Wr_Date(*pt2); //写显示数据pt2++; //字符串地址加1 } break;break;default:break;}}//==============================================// 函数名称: key_data_change ()// 功能: 4*4矩阵键盘实现键入A-Z,a-z,0-9,-/.// 参数: scan_data--4*4矩阵键盘扫描的数据// 返回值: 代表的字符值//===============================================unsigned char key_data_change(unsigned char scan_data){unsigned char data = 0;switch(scan_data){//矩阵键盘//==============第1行=============case 0x77:// 1 --X1Y1delay_nms(CHG_DELAY);if(gb_cs_num_letter == 1){data = '1';//'1'}elseswitch(gb_key_count[X2][Y1]){case 1:data = 'A';gb_key_count[X2][Y1] ++ ;break;//'A'case 2:data = 'B';gb_key_count[X2][Y1] ++ ;break;//'B'case 3:data = 'C';gb_key_count[X2][Y1] ++ ;break;//'C'case 4:data = 'a';gb_key_count[X2][Y1] ++ ;break;//'a'case 5:data = 'b';gb_key_count[X2][Y1] ++ ;break;//'b'case 6:data = 'c';gb_key_count[X2][Y1] = 1;break;//'c'default:break;}}break;case 0xB7:// 2 (ABCabc)--X2Y1delay_nms(CHG_DELAY);if(gb_cs_num_letter == 1){data = '2';//'2'}else{switch(gb_key_count[X2][Y1]){case 1:data = 'D';gb_key_count[X2][Y1] ++ ;break;//'A'case 2:data = 'E';gb_key_count[X2][Y1] ++ ;break;//'B'case 3:data = 'F';gb_key_count[X2][Y1] ++ ;break;//'C'case 4:data = 'd';gb_key_count[X2][Y1] ++ ;break;//'a'case 5:data = 'e';gb_key_count[X2][Y1] ++ ;break;//'b'case 6:data = 'f';gb_key_count[X2][Y1] = 1;break;//'c'default:break;}}break;case 0xD7: // 3 (DEFdef)--X3Y1delay_nms(CHG_DELAY);if(gb_cs_num_letter == 1){data = '3';//'3'}{switch(gb_key_count[X3][Y1]){case 1:data = 'G';gb_key_count[X3][Y1] ++ ;break;//'D'case 2:data = 'H';gb_key_count[X3][Y1] ++ ;break;//'E'case 3:data = 'I';gb_key_count[X3][Y1] ++ ;break;//'F'case 4:data = 'g';gb_key_count[X3][Y1] ++ ;break;//'d'case 5:data = 'h';gb_key_count[X3][Y1] ++ ;break;//'e'case 6:data = 'i';gb_key_count[X3][Y1] = 1;break;//'f'default:break;}}break;case 0xE7://"选择" --X4Y1delay_nms(CHG_DELAY);data=0x80;break;//========第2行=========case 0x7B: // 4 (GHIghi)--X1Y2delay_nms(CHG_DELAY);if(gb_cs_num_letter == 1){data = '4';//'4'}else{switch(gb_key_count[X1][Y2]){case 1:data = 'J';gb_key_count[X1][Y2] ++ ;break;//'J'case 2:data = 'K';gb_key_count[X1][Y2] ++ ;break;//'K'case 3:data = 'L';gb_key_count[X1][Y2] ++ ;break;//'L'case 4:data = 'j';gb_key_count[X1][Y2] ++ ;break;//'j'case 5:data = 'k';gb_key_count[X1][Y2] ++ ;break;//'k'case 6:data = 'l';gb_key_count[X1][Y2] = 1;break;//'l'default:break;}}break;case 0xBB:// 5 (JKLjkl)--X2Y2if(gb_cs_num_letter == 1){data = '5';//'5'}else{switch(gb_key_count[X2][Y2]){case 1:data = 'M';gb_key_count[X2][Y2] ++ ;break;//'M'case 2:data = 'N';gb_key_count[X2][Y2] ++ ;break;//'N'case 3:data = 'O';gb_key_count[X2][Y2] ++ ;break;//'O'case 4:data = 'm';gb_key_count[X2][Y2] ++ ;break;//'m'case 5:data = 'n';gb_key_count[X2][Y2] ++ ;break;//'n'case 6:data = 'o';gb_key_count[X2][Y2] = 1;break;//'o'default:break;}}break;case 0xDB: // 6 (MNOmno)--X3Y2delay_nms(CHG_DELAY);if(gb_cs_num_letter == 1){data = '6';//'6'}else{switch(gb_key_count[X3][Y2]){case 1:data = 'P';gb_key_count[X3][Y2] ++ ;break;//'P'case 2:data = 'Q';gb_key_count[X3][Y2] ++ ;break;//'Q'case 3:data = 'R';gb_key_count[X3][Y2] ++ ;break;//'R'case 4:data = 'p';gb_key_count[X3][Y2] ++ ;break;//'p'case 5:data = 'q';gb_key_count[X3][Y2] ++ ;break;//'q'case 6:data = 'r';gb_key_count[X3][Y2] =1;break;//'r'default:break;}}break;case 0xEB://"删除" --X4Y2data=0x90;//break;//=======第3行=========case 0x7D: // 7 (PQRS pqrs)--X1Y3delay_nms(CHG_DELAY);if(gb_cs_num_letter == 1){data = '7';//'7'}else{switch(gb_key_count[X1][Y3]){case 1:data = 'S';gb_key_count[X1][Y3] ++ ;break;//'S'case 2:data = 'T';gb_key_count[X1][Y3] ++ ;break;//'T'case 3:data = 'U';gb_key_count[X1][Y3] ++ ;break;//'U'case 4:data = 's';gb_key_count[X1][Y3] ++ ;break;//'s'case 5:data = 't';gb_key_count[X1][Y3] ++ ;break;//'t'case 6:data = 'u';gb_key_count[X1][Y3] =1 ;break;//'u'default:break;}}break;case 0xBD://8 (TUVtuv)--X2Y3delay_nms(CHG_DELAY);if(gb_cs_num_letter == 1){data = '8';//'8'}else{switch(gb_key_count[X2][Y3]){case 1:data = 'V';gb_key_count[X2][Y3] ++ ;break;//'V'case 2:data = 'W';gb_key_count[X2][Y3] ++ ;break;//'W'case 3:data = 'X';gb_key_count[X2][Y3] ++ ;break;//'X'case 4:data = 'v';gb_key_count[X2][Y3] ++ ;break;//'v'case 5:data = 'w';gb_key_count[X2][Y3] ++ ;break;//'w'case 6:data = 'x';gb_key_count[X2][Y3] =1 ;break;//'x'default:break;}}break;case 0xDD://9 (WXYZwxyz)--X3Y3delay_nms(CHG_DELAY);if(gb_cs_num_letter == 1){data = '9';//'9'}else{switch(gb_key_count[X3][Y3]){case 1:data = 'Y';gb_key_count[X3][Y3] ++ ;break;//'Y'case 2:data = 'Z';gb_key_count[X3][Y3] ++ ;break;//'Z'case 3:data = 'y';gb_key_count[X3][Y3] ++ ;break;//'y'case 4:data = 'z';gb_key_count[X3][Y3] = 1;break;//'z'default:break;}}break;case 0xED://-./ --X3Y4delay_nms(CHG_DELAY);if(gb_cs_num_letter == 1){data = '0';//'0'}else{switch(gb_key_count[X3][Y4]){case 1 : data = ' ';gb_key_count[X3][Y4] ++ ;break;//'-'case 2 : data = ';';gb_key_count[X3][Y4] ++ ;break;//'.'case 3 : data = '=';gb_key_count[X3][Y4] ++ ;break;//'/'case 4 : data = '+';gb_key_count[X3][Y4] =1;break;//'/'default:break;}}break;//========第4行========case 0x7E:// <- --X4Y1delay_nms(CHG_DELAY);data = 0xa0;//'<'break;case 0xBE: // ^切换--X4Y2delay_nms(CHG_DELAY);data = 0xb0;//break;case 0xDE:// -> --X4Y3delay_nms(CHG_DELAY);data = 0xc0;//'->'break;case 0xEE:// "确定" --X4Y4delay_nms(CHG_DELAY);data = 0xd0;break;default:break;}return data;}//==============================// 函数名称: key_scan()// 功能: 反转法矩阵键盘扫描// 参数: 无// 返回值: 扫描的键值//==============================unsigned char key_scan(void){unsigned char key_h =0,key_l = 0,key_data = 0xff;KEY_DDR = 0xF0;KEY_PORT = 0x0F;delay_nus(KEY_DELAY);key_h = KEY_PIN & 0x0F;if(key_h != 0x0F){KEY_DDR = 0x0F;KEY_PORT = 0xF0;delay_nus(KEY_DELAY);key_l = KEY_PIN & 0xF0;if(key_l != 0xF0){key_data = key_h + key_l;key_data = key_data_change(key_data);}}return key_data;}//==========================// 函数名称:system_parameter_set()// 功能:系统参数设置(铝板型号、尺寸范围)// 参数:无// 返回值:无//==========================void system_parameter_set(void){unsigned char scan_char = 0;//key扫描数据unsigned char telnum[11] = {0};//铝板型号缓冲区unsigned char al_model_count = 0;//铝板型号计数unsigned char al_small_lenth_set[20] = {0};//铝板长度设定unsigned char al_small_lenth_count = 0;//铝板长度计数unsigned int small = 0;//短长度// unsigned char al_big_lenth_set[4] = {0};//铝板长度设定//unsigned char al_big_lenth_count = 0;//铝板长度计数//unsigned int big = 0;//长长度unsigned char model_cs_count = 1;//长度、型号切换计数unsigned char enter_count = 0;//确定按键计数unsigned char i = 0;unsigned char gb[10] = {0};//铝板型号缓冲区LCD_write_string(0,1,"Abc");//默认提示键入字母//LCD_set_xy(0,3);//光标while( enter_count != 3) //确定两次退出{scan_char=key_scan();//扫描键盘获得键值switch(scan_char){case 0xff://无键盘按下break;case 0x80://"数字字母切换"gb_cs_num_letter ++;if(gb_cs_num_letter == 1) //数字{LCD_write_string(4,1,"123"); //提示键入数字switch(model_cs_count){case 1:LCD_set_xy(1,2);break;//光标case 2:LCD_set_xy(3,3);break;//光标default:break;}}else{LCD_write_string(0,1,"Abc");//提示键入字母LCD_set_xy(0,3);//光标}if(gb_cs_num_letter == 2){gb_cs_num_letter = 0;}break;case 0x90:model_cs_count = 1;enter_count = 0;//重新设置Clear_All();for(i = 0 ;i <20 ;i ++ ){al_small_lenth_set[i] = 0;}for(i = 0;i < 11;i ++){telnum[i] = 0;}al_model_count = 0 ;al_small_lenth_count = 0;gb_cs_num_letter = 0;LCD_write_string(0,1,"Abc");//默认提示键入字母lcd_scan_show(1,telnum,al_model_count,al_small_lenth_set,al_small_lenth_count);break;case 0xa0://<-switch(model_cs_count){case 1:if(al_model_count != 0){al_model_count -- ;lcd_scan_show(1,telnum,al_model_count,al_small_lenth_set,al_small_lenth_count);}break;case 2:if(al_small_lenth_count != 0){al_small_lenth_count -- ;lcd_scan_show(2,telnum,al_model_count,al_small_lenth_set,al_small_lenth_count);}break;default:break;}break;case 0xb0://"切换型号"model_cs_count ++ ;switch(model_cs_count){// case 1:LCD_set_xy(0,4);break;//光标case 2:LCD_set_xy(1,1);break;//光标case 3:LCD_set_xy(3,3);break;//光标default:break;}if(model_cs_count ==3){model_cs_count =1;}break;case 0xc0://->switch(model_cs_count){case 1:al_model_count ++ ;if(al_model_count == 11){al_model_count = 0 ;}lcd_scan_show(1,telnum,al_model_count,al_small_lenth_set,al_small_lenth_count);break;case 2:al_small_lenth_count ++ ;if(al_small_lenth_count == 20){al_small_lenth_count = 0 ;}lcd_scan_show(2,telnum,al_model_count,al_small_lenth_set,al_small_lenth_count);break;}break;case 0xd0://确定delay_nms(300);enter_count ++ ;if(enter_count == 1){Clear_All();LCD_write_string(1,1,"确定?取消?");delay_nms(300);LCD_write_string(1,1," ");delay_nms(100);LCD_write_string(1,1,"确定?取消?");}if(enter_count == 2){{LCD_write_string(1,1," 设置成功!");delay_nms(500);LCD_write_string(1,1," ");delay_nms(500);LCD_write_string(1,1," 设置成功!");delay_nms(500);enter_count ++ ;}}break;default://有除功能键外的键按下switch(model_cs_count){case 1:telnum[al_model_count ++ ] = scan_char;if(al_model_count == 12){al_model_count = 0;}lcd_scan_show(1,telnum,al_model_count,al_small_lenth_set,al_small_lenth_count);break;case 2:al_small_lenth_set[al_small_lenth_count ++] = scan_char;if(al_small_lenth_count == 20){al_small_lenth_count = 0;}lcd_scan_show(2,telnum,al_model_count,al_small_lenth_set,al_small_lenth_count);break;default:break;}break;}}for(i = 0;i <= 10;i ++){EEPROM_write(i,telnum[i]); //保存型号// gb_al_model[i] = telnum[i];}Clear_All();LCD_write_string(2,1,"您输入的号码是:");for(i = 0;i <= 10;i ++){gb[i]=EEPROM_read(i); //保存型号}LCD_write_string(3,2,gb);// Usart_Transmit_Zero_string(gb);delay_nms(2000);for(i =0;i <=al_small_lenth_count;i ++){// EEPROM_write(i,al_small_lenth_set[i-11]); //保存型号ATma[i]=al_small_lenth_set[i];}Clear_All();LCD_write_string(1,1,"您输入的信息:");LCD_write_string(2,1,al_small_lenth_set);delay_nms(2000);Clear_All();LCD_write_string(1,1,"设置成功");}。
用java编写的单词练习程序
用java编写的单词练习程序源代码import java.util.*;publicclass GameWord {//arr2:表示单词库, arr:表示随机出来的单词, arr1:表示随机出来的单词的对应中文注释./*主函数*/publicstaticvoid main(String[] args){String[][] arr2 = {{"hello","你好"},{"word","单词,句子"},{"head","头,头部"},{"public","公共的,公用的"},{"package","包,袋"}}; //将要猜的单词都放在二维数组arr2中;/*System.out.println("你好!请问贵姓?"); //获取玩家姓名Scanner in = new Scanner(System.in);String name = in.next();*///eSystem.out.println(arr2.length);System.out.println(/*name+*/"!^_^你好!请根据提示完成单词!退出请按0\n"); //提示玩家开始游戏getWord(arr2); //调用函数:获取要猜的单词}//getWord函数:将要猜的单词每个字母按顺序依次放入数组arr中publicstaticvoid getWord(String[][] arr2){Random a = new Random(); //随机给出一个单词int h = a.nextInt(arr2.length);String[] arr = new String[arr2[h][0].length()+1];//将随机出来的单词长度放入数组arr中String arr1 = arr2[h][1];//将中文注解释放入以字符串的形式arr1//System.out.print(arr1);//测试用;输出中文解释for(int i=0;i<arr2[h][0].length();i++){//将随机出来的单词每个字母放入数组arr中arr[i]=arr2[h][0].charAt(i)+"";//System.out.print(arr[h]+" "); //测试用,输出随机的一个单词}pro(arr2,arr,arr1); //调用函数:提示单词部分信息}/*prompt函数实现提示玩家单词的首末字母和单词的长度.s*/publicstaticvoid pro(String[][] arr2 ,String[] arr ,String arr1){ System.out.print(arr[0]); //输出单词首字母for(int i=0;i<arr.length-3;i++){ //提示单词长度System.out.print("_ ");}System.out.println(arr[arr.length-2]+":"+arr1);// 输出单词末字母同时输出中文注释arr1;game(arr2,arr,arr1);}/**game函数实现判断玩家输入的字符是否与单词对应字母一样*/publicstaticvoid game(String[][] arr2,String[]arr,String arr1){ //System.out.println("游戏开始");//测试输出boolean flag1 = false;//游戏猜对猜错标记符for(int i=1;i<arr.length-2;i++){flag1=false;Scanner in = new Scanner(System.in); //接收玩家输入信息String shu = in.nextLine();if((shu).equals(arr[i])){ //判断输入的字母是否与对应的单词字母一样System.out.println("^_^! ^_^!真棒,输入正确!");flag1=true;for(int m=0;m<=i;m++){ //输出已猜出的单词字母System.out.print(arr[m]);}for(int k=0;k<arr.length-3-i;k++){ //提示剩余字母长度System.out.print("_ ");}System.out.println(arr[arr.length-2]);// 输出单词末字母}elseif((shu).equals("0")){System.out.println(" v_v 您已退出游戏!");break;/*System.exit(0);*///fun(arr2,arr,arr1);}else { //提示若输入的字母是否与对应的单词字母不一样时就重新开始System.out.println(" v_v 你的输入不正确,请重输!退出请按0");if((shu).equals("0")){System.out.println(" v_v 您已退出游戏!");System.exit(0);}else {pro(arr2,arr,arr1);}}}if(flag1){//out();System.out.println("^_^恭喜!"+"输入完全正确!\n"+"是否继续(Y:输入1, N:输入0)\n");fun(arr2,arr,arr1);}}/*fun函数:实现是否继续游戏*/publicstaticvoid fun(String[][] arr2 ,String[] arr1 ,String arr) { Scanner in = new Scanner(System.in);while(true) {//System.out.println("是否继续(Y:输入1, N:输入0)");int n = in.nextInt();if(n == 0) {System.out.println(" v_v您已经退出游戏!");System.exit(0);}if(n==1){System.out.println("^_^游戏已重新开始!");getWord(arr2);}}}/*public static void out(){System.out.println("^_^恭喜!"+"猜测完全正确加100分!\n"+"是否继续(Y:输入1, N:输入0)\n");}*/}。
一个简单的打字练习程序
类似于学习机上的指法练习程序,简单⽽实⽤#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;}}}。
python制作英文学习字典案列
python制作英⽂学习字典案列def rdic():fr = open('dic.txt','r')for line in fr:line = line.replace("\n",'')v = line.split(':')dic[v[0]] = v[1]keys.append(v[0])fr.close()def centre():n = input("请输⼊进⼊相应模块(添加、查询、退出):")if n =="添加":key = input("请输⼊英⽂单词:")if key not in keys:value = input("请输⼊中⽂单词:")dic[key] = valuekeys.append(key)print("单词已经添加成功")else:print("该单词已经添加⾄字典库")elif n =="查询":key = input("请输⼊英⽂单词:")if key in keys:print("中⽂意思为:"+dic[key])else:print("字典中未找到这个单词")elif n =="退出":return 1else:print("输⼊有误")return 0def wdic():#写⼊⽂件代码通过keys的顺序写⼊with open('dic.txt','w') as fw:for k in keys:fw.write(k+':'+dic[k]+'\n')if __name__=="__main__":keys = [] #⽤来存储读取的顺序dic = {}while True:rdic()n = centre()wdic()if n == 0:continueelif n == 1:break。
scratch第七题打字母代码
scratch第七题打字母代码
Scratch是一个面向儿童的编程工具,它使用图形化的编程语言来让用户编写程序。
如果您想在Scratch中输入字母,您可以使用“文本”积木。
以下是使用Scratch输入字母的代码示例:
1. 首先,您需要选择一个角色(例如猫、狗或人物),然后选择“脚本”选项卡。
2. 在脚本区域中,您将看到一个空白的画布,您可以在其中编写程序。
3. 点击“文本”类别,然后选择“输入文本”积木。
4. 将“输入文本”积木拖动到画布上,并连接到角色。
5. 点击“设置”按钮,然后在弹出的对话框中输入您想要输入的字母。
6. 完成设置后,单击“运行”按钮以运行程序。
7. 您的角色现在应该会在画布上显示您输入的字母。
请注意,您需要使用鼠标单击角色的文本输入框才能输入字母。
如果您无法在角色的文本框中看到任何文本,请尝试更改角色的文本框大小或颜色。
英文打字练习程序源代码
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 game_start()
{
int speed,flag;//速度选择,速度标志
do
{
cout<<"请选择游戏速度>>1-慢速 2-中速 3-快速"<<endl; //显示速度
cin>>speed;
switch(speed)
{
case 1:
flag=1;break;
case 2:
flag=2;break;
case 3:
flag=3;break;
default:
flag=0;
}
}
while(flag==0);
system("cls");
void game_list()
{
cout<<">>>>>>>>>>>>>>>打 字 母<<<<<<<<<<<<<<<"<<endl;
cout<<"===============游戏菜单==============="<<endl;
cout<<"= 1开始游戏 ="<<endl;
break;
default:
system("cls");
game_list();
}
}
//game_help
信息学竞赛字符串练习含源程序
信息学竞赛练习(字符串)1、输入一行英文字符,包含若干应用单词。
相邻两个单词用空格隔开,统计单词的个数。
如,输入:today is a nice day 输出:total: 5program lx131;var st:string;ch1,ch2:char;i,l,num:integer;beginwriteln('input charactors:');readln(st);l:=length(st);i:=1;num:=1;while i<=1 dobeginwhile st[i]=' ' dobegini:=i+1;if i<=1 then num:=num+1;end;while (st[i]<>' ')and (i<=1) do i:=i+1;end;writeln('total:',num);end.2、卡布列克常数:卡布列克是一个数学家,他在研究数字时发现:任意一个不是用完全相同的数字组成的四位数,如果对它们的每位数字重新排序,组成一个最大的数和一个最小的数,然后用最大的数减去最小的数,差不够四位数时补零,类推下去,最后将变为一个固定的常数:6174,这就是卡布列克常数。
例如:Array Program lx132;var s : string;n,n1,n2,i,j,e : integer;c : char;beginrepeatwriteln('Input a number : ');readln(n);until (n > 1000) and (n < 9999);while n <> 6174 do beginstr(n,s);for i := 1 to 3 dofor j := i+1 to 4 doif s[i] < s[j] then beginc := s[i]; s[i] := s[j]; s[j] := c;end;val(s,n1,e);for i := 1 to 2 do beginc := s[i]; s[i] := s[5-i]; s[5-i] := c;end;val(s,n2,e);n := n1-n2;writeln(n1,' - ',n2,' = ',n);if n < 1000 then n := n*10;end;end.3、输入一串字符,其长度小于200。
打字练习程序
打字练习程序功能:1) 从磁盘文件中读入一些字母(程序中只载入一屏306个字符)2) 运行时,可按照屏幕显示的字母输入练习(模拟金山打字,这个实现很有挑战性哦,先拷贝过去运行下看看效果哦)3) 输完结束或按ESC结束.结束时可显示出练习输入的时间,并显示出正确率.说明:该程序主要分成(刮弧中为相应主要的函数块)1)打字事例文件加载模块(LoadFile )注:加载文件的时候提供绝地路径,而且文件中字符不宜太少,最好多于306个。
2)打字屏幕提示及打字窗口模块(clew_char,isFullLine )注:这里是算法的集中点,注意提示功能和退格功能的实现,特别注意退格时候对字符统计的影响的处理。
3)打字时间及正误统计模块(TONGJI) 注:这里主要注意的是时间的显示和正确率的计算,试试哦自己独立实现下,很有趣的呢。
4)打字结果计算与显示模块( UseTimeAndOut,RightRata_out) 注:怎么把结果显示在屏幕上的呢,汇编中只能输出字符(串)呀,这里的技巧啊,先想想哦(整数123,虽然是一个数可在屏幕上输出'1''2''3'可不简单呢,还有带小数的(如98.34)怎么输出呀?嘿嘿想想吧,肯定是要转换的,但这算法.....);--------------------------------------------------------------------;------------------------------------------ COLORCHAR MACRO char,colorpush axpush bxpush cxpush dxmov ah,9hmov al,charmov bh,0mov bl,colormov cx,1int 10hmov ah,03hmov bh,0int 10hmov ah,02add dl,1int 10hpop dxpop cxpop bxpop axENDMBACKCHAR MACRO char,colormov ah,02hmov dl,08hint 21hCOLORCHAR char,colorENDMCLEARSCREAM MACRO alz,bhz,chz,clz, dhz,dlzpush axpush bxpush cxpush dxmov al,alzmov bh,bhzmov ch,chzmov cl,clzmov dh,dhzmov dl,dlzmov ah,6hint 10hpop dxpop cxpop bxpop axENDMSETGBTYPE MACRO chz,clzpush axpush bxpush cxpush dxmov ch,chzmov cl,clzmov ah,1int 10hpop dxpop cxpop bxpop axENDMSETGB MACRO bhz,dhz,dlzpush axpush bxpush cxpush axmov bh,bhzmov dh,dhzmov dl,dlzmov ah,2int 10hpop dxpop cxpop bxpop axENDMREADGB MACRO bhzpush axpush bxpush cxpush dxmov bh,bhzmov ah,3int 10hmov gbattr[0],dhmov gbattr[1],dlpop dxpop cxpop bxpop axENDMLINEFULL MACRO lmax,lactpush axpush bxpush cxpush dxmov ax,lactcmp ax,0jz LFEXITmov dx,0cwdmov bx,lmaxdiv bxcmp dx,0jz LNFUjmp LFEXITLNFU: mov FullFlag,1 LFEXIT: pop dxpop cxpop bxpop axENDMTISHI MACRO row,col,addrpush axpush dxSETGB 0,row,colmov ah,09hlea dx,addrint 21hpop dxpop axENDM;------------------------------------------ data segmentaddr db 400 dup('$')addrtp db 400 dup('$')Anumber dw 0Enumber dw 0Rnumber dw 0LineMax dw 0LineAct dw 0FullFlag db 0gbattr db 4 dup(0)oldgba db 4 dup(0)newirupt dw 2 dup(0)oldirupt dw 2 dup(0)count db 0Stime db 3 dup(0)Utime db 3 dup(0)temp db 50 dup(0)tempw dw 50 dup(0)path db 50 dup(0)ts00 db 'Load File$'ts01 db 'Load:$'ts02 db 'OK?$'ts03 db 'Path Error! Press any key to reinput!$'ts1 db 'Stime:$'ts2 db 'Rrate:$'ts3 db 'Total Use-Time:$'ts4 db 'Total Characters:$'ts5 db 'Correct-Reta:$'ts6 db 'Press any key to end!$' data endscode segmentassume ds:data,cs:codestart:mov ax,datamov ds,axmov ah,0hmov al,03h ;80*25/16int 10h;------------------------------------------CLEARSCREAM 0,07H,0,0,24,79CLEARSCREAM 0,5eh,9,14,14,65TISHI 10,35,ts00TISHI 12,25,ts01call LoadFileTISHI 13,45,ts02mov ah,01hint 21h;------------------------------------------CLEARSCREAM 0,07h,0,0,24,79CLEARSCREAM 0,57h,2,10,23,69CLEARSCREAM 0,17H,3,12,22,66CLEARSCREAM 0,70h,4,14,22,6 4CLEARSCREAM 0,70h,4,14,11,64CLEARSCREAM 0,17H,12,14,14, 64CLEARSCREAM 0,70h,13,18,13,35CLEARSCREAM 0,70H,13,43,13,60SETGB 0,4,14SETGBTYPE 0,24mov di,0mov cx,0ffffhAD: mov dl,addr[di]cmp dl,'$'jz A2push dxmov bp,diCALL isFullLinepop dxmov ah,02hint 21hinc diloop ADA2: mov ah,2chint 21hmov Stime[0],chmov Stime[1],clmov Stime[2],dhSETGB 0,15,14CALL TONGJImov cx,0ffffhmov di,0hAS: cmp addr[di],'$'jnz ASnt00jmp AENDASnt00: mov bp,diCALL isFullLinemov bp,diCALL clew_char;================================ ==========;READGB 0reinput:READGB 0mov ah,01int 21hcmp al,27jnz al27ntjmp exit;------------------------------------------ al27nt: cmp al,0dhjnz al0dntSETGB 0,gbattr[0],gbattr[1]jmp reinputal0dnt: cmp al,08jnz ASnextcmp gbattr[1],14jnz ASnz;inc gbattr[1]SETGB 0,gbattr[0],gbattr[1]jmp reinputASnz:mov ah,02hmov dl,' 'int 21hmov ah,02hmov dl,08hint 21hdec di;---------------dec Anumberpush axmov al,addrtp[di]cmp al,addr[di]jnz AS1ntdec RnumberAS1nt: pop axCALL TONGJI;----------------mov bp,diCALL clew_charjmp reinput ;------------------------------------------;================================ ==========ASnext:inc AnumberCALL TONGJImov addrtp[di],alcmp al,addr[di]jnz AERinc RnumberCALL TONGJIA3: inc di;loop ASdec cxcmp cx,0jz AENDjmp ASAEND: jmp exitAER: inc Enumbermov temp[1],alBACKCHAR temp[1],074hjmp A3exit: CLEARSCREAM 0,07,8,16,17,63 CLEARSCREAM 0,57,10,20,15,59TISHI 11,24,ts3call UseTimeAndOutTISHI 12,24,ts4mov bx,Anumbercall btod_outTISHI 13,24,ts5call RightRata_outTISHI 14,30,ts6mov ah,08int 21h;CALL reset_interruptmov ah,4chint 21h;--------------------------------------------------- LoadFile proc nearmov si,0LFROTA: mov ah,01hint 21hcmp al,0dhjz LoadNextcmp al,08hjz LFBKmov path[si],alinc sijmp LFROTAjmp LoadNextLFBK: cmp si,0jnz lfnzREADGB 0inc gbattr[1]SETGB 0,gbattr[0],gbattr[1]jmp LFROTAlfnz: mov path[si],0dec simov ah,02hmov dl,' 'int 21hmov ah,02hmov dl,08hint 21hjmp LFROTALoadNext:mov ah,3dhmov dx,seg pathmov ds,dxmov dx,offset pathmov al,00int 21hjc LoadERROR;bx use to save file code mov bx,axmov si,0mov dx,seg addrmov ds,dxmov dx,offset addrmov cx,1LROT: mov ah,3fhint 21hcmp addr[si],0ahjz LROTcmp addr[si],0dhjz LROTinc dxinc sicmp si,306jb LROTjmp lfretLoadERROR:TISHI 14,20,ts03mov ah,01hint 21hCLEARSCREAM 0,5eh,9,14,14,65TISHI 10,35,ts00TISHI 12,25,ts01mov si,0jmp LFROTAlfret: retLoadFile endp;--------------------------------------------------- RightRata_out proc nearpush axpush bxpush cxpush dxmov ax,Rnumbermov cx,100mul cxdiv Anumbermov bx,axCALL btod_outpush dxmov ah,02hmov dl,'.'int 21hpop dxmov ax,dxmul cxdiv Anumbermov bx,axCALL btod_outmov ah,2hmov dl,'%'int 21hpop dxpop cxpop bxpop axretRightRata_out endp;--------------------------------------------------- UseTimeAndOut proc nearmov ah,2chint 21hsub dh,Stime[2]jns SecUnBlowjz SecUnBlowadd dh,60dec clSecUnBlow:sub cl,Stime[1]jns MinUnBlowjz SecUnBlowadd cl,60dec chMinUnBlow:sub ch,Stime[0]CALL OutTimeretUseTimeAndOut endp;-----------------------------------------------OutTime proc near;ch:cl:dhmov al,chcbwmov bx,axCALL btod_outmov ah,2hmov dl,'-'int 21hmov al,clcbwmov bx,axCALL btod_outmov ah,2hmov dl,'-'int 21hmov al,dhcbwmov bx,axCALL btod_outretOutTime endp;--------------------------------------------------- TONGJI proc nearpush axpush bxpush cxpush dxmov ax,seg addrmov ds,axREADGB 0SETGB 0,13,20CLEARSCREAM 0,70h,13,18,13, 35mov ah,09hlea dx,ts1int 21hmov ah,2chint 21hCALL OutTimeSETGB 0,13,45mov ah,09hlea dx,ts2int 21hmov ax,Rnumbermov bx,axcall btod_outmov ah,2hmov dl,'/'int 21hmov ax,Anumbermov bx,axcall btod_outSETGB 0,gbattr[0],gbattr[1] pop dxpop cxpop bxpop axretTONGJI endp;---------------------------------------------- btod_out proc near ;num store in bx push axpush cxpush dxpush bpmov ax,bxmov si,4rota1: mov bl,10div blmov temp[si],ahand ax,00ffhdec sicmp si,0jnz rota1mov bp,1mov si,1rota2: mov dl,temp[si]add dl,'0'cmp dl,'0'jz btodealmov bp,0btrt1: mov ah,02hint 21hbtrt2: inc sicmp si,4jna rota2cmp bp,1jnz RTmov ah,2hint 21hjmp RTbtodeal: cmp bp,1jz btrt2jmp btrt1RT: pop bppop dxpop cxpop axretbtod_out endp;-------------------------------------------------- isFullLine proc near ;bp is the parament push axpush bxmov ah,gbattr[0]mov al,gbattr[1]mov LineMax,51mov LineAct,bpLINEFULL LineMax,LineActmov bl,FullFlagcmp bl,0jz isfexitREADGB 0add gbattr[0],1sub gbattr[1],51SETGB 0,gbattr[0],gbattr[1]mov FullFlag,0isfexit: mov gbattr[0],ahmov gbattr[1],alpop bxpop axretisFullLine endp;-------------------------------------------------- clew_char proc near ; bp is the parament push axpush bxpush cxpush dxpush siREADGB 0mov dh,gbattr[0]mov dl,gbattr[1]mov oldgba[0],dhmov oldgba[1],dl;4/14,4/64,15/14,15/64mov ax,bpmov bl,51div blmov dh,4mov dl,14add dh,aladd dl,ahmov temp[0],dhmov temp[1],dlSETGB 0,temp[0],temp[1]COLORCHAR addr[bp],5Ehcmp bp,0jz resetgbcmp temp[1],14jz clew2sub temp[1],1clew1: mov bx,bpdec bxSETGB 0,temp[0],temp[1]COLORCHAR addr[bx],07dhjmp resetgbclew2: sub temp[0],1add temp[1],50jmp clew1resetgb:SETGB 0,oldgba[0],oldgba[1]pop sipop dxpop cxpop bxpop axretclew_char endp;-------------------------------------------------- code endsend start。
打字练习软件源代码
打字练习软件源代码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;。
打字练习代码
最近发现很对人需要打字程序的代码,新作了一个,还有些小功能可以自己补充。
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。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
■ 初学者英文打字练习程序
————————————————以下为程序代码—————————————
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) & "%" & " 按任意键继续"
Else
rtn = sndPlaySound(App.Path & "\wrong.wav", SND_ASYNC)
wrong = wrong + 1
End If
lbl_score.Caption = "成绩: " & right & "分" & " 错误: " & wrong & " 个" & " 正确率: " & Int(right / keynum * 100) & "%"
Timer1.Enabled = True '启动定时器
Timer2.Enabled = True
Timer1.Interval = 100
Timer2.Interval = 1000
'隐藏命令按钮
Command1.Visible = False
Command2.Visible = False
.Size = 20
.Bold = True
End With
lbl_letter.ForeColor = vbYellow
lbl_letter.BackColor = Form1.BackColor
lbl_score.BackColor = vbGreen
lbl_score.Alignment = 0
Form1.Top = (Screen.Height - Form1.Height) / 2
Form1.BorderStyle = 1
Form1.BackColor = vbBlack
Form1.Caption = "英文打字练习程序"
Command1.Default = True
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
If lbl_letter.Top >= Form1.Height Then
letterInit
End If
End Sub
Private Sub Timer2_Timer()
lbl_time.Caption = Val(lbl_time.Caption) - 1 & " 秒"
lbl_time.Caption = "时间120秒"
Timer1.Enabled = False
Timer2.Enabled = False
Randomize '初始化
End Sub
Private Sub Timer1_Timer()
lbl_letter.Top = lbl_letter.Top + speed
Private Const SND_ASYNC = &H1
Dim rtn As Long
Sub letterInit() '初始化每个字母
lbl_letter.Caption = Chr(Int(Rnd * 26) + 97) '随机产生字母,如果要产生大写字母只要把97改成65即可
Private Sub Command1_Click()
letterInit
lbl_score.Caption = "成绩: " & 0 & " 分" & " 错误: " & 0 & " 个" & " 正确率: " & 0 & "%"
Case Is <= 120
MsgBox "成绩: 良!再加加油你就可以成为高手了!", vbOKOnly, "练习结束!"
Case Is >= 150
MsgBox "成绩: 优秀! 太棒了,恭喜你再也不会为打字发愁了!", vbOKOnly, "练习结束!"
End Select
Comman为可见状态
Command2.Visible = True
right = 0
wrong = 0
keynum = 0
End If
End Sub
Case Is <= 80
MsgBox "成绩: 不及格! 不过别灰心,请多多练习!", vbOKOnly, "练习结束!"
Case Is <= 100
MsgBox "成绩: 及格! 还要继续加油努力啊!", vbOKOnly, "练习结束!"
Command1.Caption = "开始"
Command2.Caption = "退出"
'设置lbl_letter中显示的字符的字体、样式、字号,请同时调整lbl_letter的大小与字符大小相等
With lbl_letter.Font
.Name = "宋体"
If Val(lbl_time.Caption) <= 0 Then '判断时间是否已经用完
Timer1.Enabled = False
Timer2.Enabled = False
lbl_letter.Caption = ""
Select Case (right * (right / keynum))
speed = Int(Rnd * 100 + 200)
lbl_letter.Left = Int(Rnd * (Form1.Width - lbl_letter.Width)) '随机产生字母出现的位置
lbl_letter.Top = lbl_score.Height
End Sub
lbl_score.Caption = "敲回
车键开始打字练习,按ESC键暂停"
lbl_time.BackColor = lbl_score.BackColor