指法练习小游戏(指法练习小游戏大全)

admin 2021-02-05 传奇手游三端 78 ℃ 请在这里放置你的在线分享代码
正文

多于的就不说了,只发重点,进入EXCEL,在菜单栏上单击"工具","宏","Visual Basic编辑器",在资源管理器上单击右键,"插入","用户窗体",

在窗体上添加一个图片框,在左边的属性框里找到"Picture",添加一张背景图,添加6个标签控件,标签1,2,3放在图片框上,作为显示字母的控件,标签4作为开始游戏按钮,标签5作为结束按钮,

图1

双击窗体,进入代码编辑框,编写以下代码:

Option Explicit

Dim lb(2) As MSForms.Label

Dim mPs As Integer

Dim mCorrect As Integer

Dim mError As Integer

Dim mStart As Boolean

Private Sub Label4_Click()

On Error GoTo net

mStart = True

Dim i As Integer

Do While (mStart False)

DoEvents

sleep 0.7

For i = 0 To 2

lb(i).Left = lb(i).Left - mPs

If lb(i).Left (0 - lb(i).Width) Then

lb(i).Left = UserForm1.Width

End If

Next i

Loop

net:

End Sub

Private Sub Label5_Click()

mStart = False

End Sub

图2

Private Sub UserForm_Initialize() '初始化'

Dim i As Integer

mPs = 5 ' 初始化移动速度

Set lb(0) = UserForm1.Label1 '初始化标签控件'

Set lb(1) = UserForm1.Label2

Set lb(2) = UserForm1.Label3

For i = 0 To 2

lb(i).Caption = Randchar

lb(i).Left = UserForm1.Width

Next i

Label6.Caption = "正确;" mCorrect " / " "错误:" mError

End Sub

Private Sub Initlabel(ByVal ascii As Integer)

Dim i As Integer

Dim b As Boolean

For i = 0 To 2

If ascii = Asc(lb(i).Caption) Then

mCorrect = mCorrect + 1

lb(i).Caption = Randchar

lb(i).Left = UserForm1.Width

b = True

GoTo net

End If

Next i

net:

If b = False Then

mError = mError + 1

End If

b = False

Label6.Caption = "正确;" mCorrect " / " "错误:" mError

End Sub

图3

'随机字母'

Private Function Randchar() As String

Dim i As Integer

i = Int(Rnd() * 26 + 97)

Randchar = Chr(i)

End Function

'延时

Private Sub sleep(ByVal value As Integer)

Dim tim As Long

tim = Timer + value

Do While Timer tim

DoEvents

Loop

End Sub

'键盘打字'

Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

Initlabel KeyAscii

End Sub

Private Sub UserForm_Terminate()

mStart = False

End Sub

图4

编写完代码直接按F5运行,接着我们就能练习打字了,是不是很简单,

图5

本文TAG:

网站分类
最近发表
标签列表
传奇手游发布网站