文章目录:
C语言程序设计 (英文打字练习)
Option Explicit
Dim speed, right, wrong, keynum As Integer '定义速度,正确次数,错误次数,击键次数
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Const SND_ASYNC = H1
Dim rtn As LongSub letterInit() '初始化每个字母
lbl_letter.Caption = Chr(Int(Rnd * 26) + 97) '随机产生字母,如果要产生大写字母只要把97改成65即可
speed = Int(Rnd * 100 + 200)
lbl_letter.Left = Int(Rnd * (Form1.Width - lbl_letter.Width)) '随机产生字母出现的位置
lbl_letter.Top = lbl_score.Height
End SubPrivate Sub Command1_Click()
letterInit
lbl_score.Caption = "成绩: " 0 " 分" " 错误: " 0 " 个" " 正确率: " 0 "%"
Timer1.Enabled = True '启动定时器
Timer2.Enabled = True
Timer1.Interval = 100
Timer2.Interval = 1000
'隐藏命令按钮
Command1.Visible = False
Command2.Visible = False
lbl_time.Caption = 120 " 秒"
End SubPrivate Sub Command2_Click()
Unload Me
End SubPrivate Sub Form_KeyPress(KeyAscii As Integer)
keynum = keynum + 1 If Chr(KeyAscii) = lbl_letter.Caption Then '判断所按键位是否与产生的字母相符
letterInit
rtn = sndPlaySound(App.Path "\right.wav", SND_ASYNC)
right = right + 1
Else
rtn = sndPlaySound(App.Path "\wrong.wav", SND_ASYNC)
wrong = wrong + 1
End If
lbl_score.Caption = "成绩: " right "分" " 错误: " wrong " 个" " 正确率: " Int(right / keynum * 100) "%" If KeyAscii = 27 Then
Timer1.Enabled = False
Timer2.Enabled = False
lbl_score.BackColor = vbYellow
lbl_score.Caption = "成绩: " right "分" " 错误: " wrong " 个" " 正确率: " Int(right / keynum * 100) "%" " 按任意键继续"
Else
lbl_score.BackColor = vbGreen
Timer1.Enabled = True
Timer2.Enabled = True
End If
End SubPrivate Sub Form_Load()
Form1.Left = (Screen.Width - Form1.Width) / 2
Form1.Top = (Screen.Height - Form1.Height) / 2
Form1.BorderStyle = 1
Form1.BackColor = vbBlack
Form1.Caption = "英文打字练习程序"
Command1.Default = True
Command1.Caption = "开始"
Command2.Caption = "退出"
'设置lbl_letter中显示的字符的字体、样式、字号,请同时调整lbl_letter的大小与字符大小相等
With lbl_letter.Font
.Name = "宋体"
.Size = 20
.Bold = True
End With
lbl_letter.ForeColor = vbYellow
lbl_letter.BackColor = Form1.BackColor
lbl_score.BackColor = vbGreen
lbl_score.Alignment = 0
lbl_score.Caption = "敲回车键开始打字练习,按ESC键暂停"
lbl_time.BackColor = lbl_score.BackColor
lbl_time.Alignment = 2
lbl_time.Caption = "时间120秒"
Timer1.Enabled = False
Timer2.Enabled = False
Randomize '初始化
End SubPrivate Sub Timer1_Timer()
lbl_letter.Top = lbl_letter.Top + speed
If lbl_letter.Top = Form1.Height Then
letterInit
End If
End Sub Private Sub Timer2_Timer()
lbl_time.Caption = Val(lbl_time.Caption) - 1 " 秒"
If Val(lbl_time.Caption) = 0 Then '判断时间是否已经用完
Timer1.Enabled = False
Timer2.Enabled = False
lbl_letter.Caption = ""
Select Case (right * (right / keynum))
Case Is = 80
MsgBox "成绩: 不及格! 不过别灰心,请多多练习!", vbOKOnly, "练习结束!"
Case Is = 100
MsgBox "成绩: 及格! 还要继续加油努力啊!", vbOKOnly, "练习结束!"
Case Is = 120
MsgBox "成绩: 良!再加加油你就可以成为高手了!", vbOKOnly, "练习结束!"
Case Is = 150
MsgBox "成绩: 优秀! 太棒了,恭喜你再也不会为打字发愁了!", vbOKOnly, "练习结束!"
End Select Command1.Visible = True '命令按钮恢复为可见状态
Command2.Visible = True
right = 0
wrong = 0
keynum = 0
End If
End Sub哥哥帮你,对你好吧!也不搞点分来啊
谁有创意CAI英文打字练习软件啊?好像是DOS系统那时候就有的软件。急啊!!!!!
找到了。这个网页可以下载 win7可以用的。网页链接下载完,解压后直接点击 开始游戏.exe,就能用了。
求纯C语言打字游戏源代码及解析
# include "Typer.h"
# include stdio.h
# include stdlib.h
# include graphics.h
//download by
void main()
{
BOOL bQuit=FALSE; /* 是否退出 */
BOOL bPause=FALSE; /* 是否暂停 */
int tm1,tm2;
BYTE Key;
randomize(); /* 初始化随机数种子 */
SetGraphMode();
SelectLevel();
ShowBar();
tm1=CreateTimer(1,MoveLetter); /* 创建移动字符对象时钟 */
tm2=CreateTimer(Interval,CreateLetter); /* 创建产生字符对象时钟 */
CreateLetter();
Key=AscKey();
while (!bQuit)
{
TimerEvent();
switch (Key)
{
case NULL:
break;
case KEY_ESC:
bQuit=TRUE;
break;
case KEY_SPACE:
bPause=!bPause;
tmTM[tm1].Enable=!bPause;
tmTM[tm2].Enable=!bPause;
break;
default:
if (!bPause) Check(Key);
}
Key=AscKey();
}
CloseGraphMode();
}
void SetGraphMode()
{
int Device=VGA,Mode=VGAHI;
initgraph(Device,Mode,"");
settextstyle(TRIPLEX_FONT,HORIZ_DIR,1);
setfillstyle(SOLID_FILL,0);
setcolor(7);
}
void CloseGraphMode()
{
restorecrtmode();
}
/* 从键盘缓冲区内直接读出ASC码 */
BYTE AscKey(void)
{
int start,end;
WORD key=0;
start=peek(0,0x41a);
end=peek(0,0x41c);
if (start==end) return(0);
else
{
key=peek(0x40,start);
start+=2;
if (start==0x3e) start=0x1e;
poke(0x40,0x1a,start);
return(key0xff);
}
}
void MoveLetter(void)
{
int i;
for (i=0;iMAX_LETTER;i++)
{
if (Letter[i].Used)
{
HideLetter(i);
Letter[i].y+=Step;
ShowLetter(i);
/* 字符对象下落到最底部 */
if (Letter[i].yMAX_HEIGHT) KillLetter(i);
}
}
}
void KillLetter(int LetterID)
{
if (Letter[LetterID].Used)
{
Letter[LetterID].Used=FALSE;
LetterUsed--;
HideLetter(LetterID);
}
/* 删除字符对象后马上再创建一个 */
CreateLetter();
}
void CreateLetter()
{
int i=0;
int x;
BYTE val;
if (LetterUsed==MAX_LETTER) return; /* 无字符对象可用则返回 */
while (Letter[++i].Used); /* 找到第一个空闲的字符对象,产生一个字符对象 */
x=i;
Letter[i].x=x*640/MAX_LETTER;
Letter[i].y=0;
Letter[i].val=random(26)+'A';
Letter[i].Used=TRUE;
LetterUsed++;
}
void HideLetter(int ID)
{
/* 用填充矩形来消隐字符 */
bar(Letter[ID].x,Letter[ID].y,Letter[ID].x+16,Letter[ID].y+20);
}
void ShowLetter(int ID)
{
char str[2]={0,0};
str[0]=Letter[ID].val;
outtextxy(Letter[ID].x,Letter[ID].y,str);
}
void Check(BYTE Key)
{
int i;
char str[6];
Hits++;
for (i=0;iMAX_LETTER;i++)
/* 击中 */
if (Letter[i].UsedLetter[i].val==toupper(Key))
{
sound(1000);
delay(10);
KillLetter(i);
Right++;
nosound();
}
/* 显示状态 */
setfillstyle(SOLID_FILL,5);
bar(260,430,320,450);
bar(410,430,470,450);
setcolor(2);
sprintf(str," %4ld",Hits);
outtextxy(260,430,str);
sprintf(str," %4ld",Right);
outtextxy(410,430,str);
setcolor(7);
setfillstyle(SOLID_FILL,0);
}
void ShowBar()
{
FILE *bmp;
BYTE r,g,b,t;
int i,x,y;
bmp=fopen("bar.bmp","rb");
fseek(bmp,54,SEEK_SET);
for (i=0;i16;i++)
{
setpalette(i,i);
b=fgetc(bmp)2;
g=fgetc(bmp)2;
r=fgetc(bmp)2;
t=fgetc(bmp)2;
setrgbpalette(i,r,g,b);
}
for (y=0;y80;y++)
for (x=0;x320;x++)
{
t=fgetc(bmp);
putpixel(x*2,479-y,t4);
putpixel(x*2+1,479-y,t15);
}
fclose(bmp);
}
void SelectLevel()
{
int Steps[3]={1,2,4};
int Intervals[3]={18,9,5};
int Sel=0;
FILE *bmp;
BYTE r,g,b,t,Key;
int i,x,y;
bmp=fopen("sel.bmp","rb");
fseek(bmp,54,SEEK_SET);
for (i=0;i16;i++)
{
setpalette(i,i);
b=fgetc(bmp)2;
g=fgetc(bmp)2;
r=fgetc(bmp)2;
t=fgetc(bmp)2;
setrgbpalette(i,r,g,b);
}
for (y=0;y200;y++)
for (x=0;x160;x++)
{
t=fgetc(bmp);
putpixel(x*2+160,339-y,t4);
putpixel(x*2+161,339-y,t15);
}
fclose(bmp);
while (TRUE)
{
Key=toupper(AscKey());
if (Key=='A') Sel=1;
if (Key=='B') Sel=2;
if (Key=='C') Sel=3;
if (Sel) break;
}
Step=Steps[Sel-1];
Interval=Intervals[Sel-1];
cleardevice();
}
/*********************************************************/
/* 文件:TIMER.H */
/*********************************************************/
/*********************************************************/
/* 系统可用计时器的最大数目 */
# define MAXTIMER 10
# ifndef NULL
# define NULL 0
# endif
/* 计时器结构 */
struct TM
{
DWORD Interval; /* 间隔 */
DWORD LastTimer; /* 上次事件发生时间*/
BOOL Enable; /* 活动 */
BOOL Used; /* 可用 */
void (*Pointer)(); /* 事件远指针 */
};
struct TM tmTM[MAXTIMER+1];
int TimerUsed=0;
/* 获取BIOS计数器数值 */
DWORD BiosTimer(void)
{
DWORD BIOSTIMER=0;
BIOSTIMER=peek(0x0,0x46e);
BIOSTIMER=8;
BIOSTIMER+=peek(0x0,0x46c);
return (BIOSTIMER);
}
/* 时间事件(时钟系统核心) */
void TimerEvent()
{
int i;
DWORD TimerDiff;
for (i=1;i=MAXTIMER;i++)
{
if (tmTM[i].UsedtmTM[i].Enable)
{
TimerDiff=BiosTimer()-tmTM[i].LastTimer;
if (tmTM[i].Interval=TimerDiff)
{
tmTM[i].Pointer();
tmTM[i].LastTimer=BiosTimer();
}
}
}
}
/* 创建一个时钟(成功返回时钟的句柄,否则返回NULL) */
int CreateTimer(DWORD Interval,void (*Pointer)())
{
int i=0;
if (TimerUsed==MAXTIMER) return NULL;
while (tmTM[++i].Used);
tmTM[i].Pointer=Pointer;
tmTM[i].Interval=Interval;
tmTM[i].Enable=TRUE;
tmTM[i].Used=TRUE;
tmTM[i].LastTimer=BiosTimer();
TimerUsed++;
return i;
}
/* 删除一个时钟 */
void KillTimer(int *TimerID)
{
if (tmTM[*TimerID].Used)
{
TimerUsed--;
tmTM[*TimerID].Used=FALSE;
}
*TimerID=0;
}
/* 删除所有时钟 */
void KillAllTimer()
{
int i;
for (i=0;i=MAXTIMER;i++) tmTM[i].Used=FALSE;
TimerUsed=0;
}
osound(); } /* 显示状态 */ setfillstyle(SOLID_FILL,5); bar(260,430,320,450); bar(410,430,470,450); setcol