没大的问题,只是数据变量定义的问题。
修改的地方拉红,你仔细看看。
-----------------------------
Option Explicit
Dim n As Integer
Dim h As Integer
Private Function suiji() '随机产生字母和随机选取单词函数(3.1.1随机产生字母和选取单词函数)
Dim a As Integer
Dim b As String
Dim word As Variant
Randomize
word = Array("sway", "sneak", "naked", "maple", "ample", "lough", "plasma", "tude", "plague", "pledge", "play", "prowl", "pluckbandit", "gangster", "commemorate", "solar", "elipse", "luna", "lunatic", "tumble", "mortal", "moral", "fade", "flinch", "spout", "sprout", "spurn", "spoil", "sparrow", "sprain", "plasma", "mare", "malady", "glisten", "bereave", "glimme", "rslim", "crave", "amiable", "able", "blizzard", "lizard", "bruise", "bromide", "place", "bale") '存放供练习的单词
b = Int(Rnd * (UBound(word) + 1)) '产生单词序号
a = Int((122 - 97 + 1) * Rnd + 97) '产生97到122之间的整数
If Option1.Value Then
suiji = Chr(a) '如果选择简单单选框则函数的返回值为小写字母
Else
suiji = word(b) '如果选择复杂单选框则函数的返回值为单词
End If
End Function
Private Sub Form_Load()
'3.1.2窗体
Dim i As Integer
Text1.Top = -1000
Label6.Caption = "正确率ム"
Label4.Caption = "时间 00:00:00"
Timer2.Enabled = False
Timer1.Enabled = False
Label2.BackStyle = 0
Label3.BackStyle = 0
Label4.BackStyle = 0
Label5.BackStyle = 0
Label6.BackStyle = 0 '将标签2到6的背景设为透明
For i = 0 To Label1.Count - 1
7
Label1(i).Visible = False '将标签Label1(1)到Label1(5)的初始状态设为不可见
Label1(i).Top = 600 * (i + 1) '设置字母或单词的的位置
Label1(i).Caption = suiji '最初出现的字母或者单词
Label1(i).FontSize = 25 '设置字体大小
Label1(i).AutoSize = True '标签大小自动可调
Label1(i).BackStyle = 0 '透明
Next
Label3.Caption = "掉落个数:" & n
Label5.Caption = "当前得分:" & h
Label2.ForeColor = RGB(0, 255, 0)
Label5.ForeColor = RGB(0, 255, 0)
Label3.ForeColor = RGB(0, 255, 0)
Label6.ForeColor = RGB(255, 0, 0)
Label4.ForeColor = RGB(255, 0, 255) '设置字体颜色
End Sub
Public Sub Command1_Click() '开始按钮(3.1.3开始按钮)
Dim i%
If Option2.Value Then
i = MsgBox("输入单词后,请按空格键确认", , "注意") '操作提示
End If
For i = 0 To Label1.Count - 1
Label1(i).Visible = True
Label1(i).Caption = suiji
Label1(i).ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) '随机产生字母嗠词鳠犘辂机
Next
Timer1.Enabled = True
Timer2.Enabled = True
HScroll1.Enabled = False
Option1.Enabled = False
Option2.Enabled = False
Command1.Enabled = False '将计时器速度调节难度选择和开始按钮禁用
Text1.SetFocus '将焦点转移到文本框
End Sub
Private Sub Command2_Click() '暂停按钮(8 3.1.4暂停按钮)
Timer1.Enabled = False
Timer2.Enabled = False
If MsgBox("是否继续?", vbYesNo, "提示!") = vbYes Then
Timer1.Enabled = True
Timer2.Enabled = True
Else
MsgBox "得分" & h & "分", , "成绩" '退出提示
Unload Me '关闭窗体
End If
End Sub
Private Sub Command3_Click() '退出按钮(3.1.5退出按钮 )
If MsgBox("确定要退出?", vbYesNo, "提示!") = vbYes Then
MsgBox "得分" & h & "分", , "成绩" '退出提示
Unload Me '关闭窗体
End If
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
'3.1.6键盘事件
Dim b As Integer
Dim c As Integer
Dim i As Integer
Static ci As String
If KeyAscii >= 97 And KeyAscii <= 122 Then
ci = ci + Chr(KeyAscii) '将输入的单词赋值给空字符串ci
End If
b = -1
c = -1
If Option1.Value Then '选择简单
Text1.Locked = True
For i = 0 To Label1.Count - 1 '遍历所有产生字母
If Label1(i).Caption = Chr(KeyAscii) Then '判断产生的字母和输入的字母是否相等
If Label1(i).Top > b Then '判断字母是否已经落出
c = i
End If
End If
Next i
Else
'复杂
Text1.Locked = True
If KeyAscii = 32 Then '如果敲了空格则进行单词比较操作
For i = 0 To Label1.Count - 1 '遍历所有产生字母
9
If Label1(i).Caption = ci Then '判断产生的单词和输入的单词是否相等
If Label1(i).Top > b Then '判断字母是否已经落出
c = i
End If
End If
Next
ci = ""
End If
End If
If c > -1 Then
Label1(c).Top = -10 '如果输入正确则将字母标签隐藏到顶部
Label1(c).Caption = suiji '字母标签随机产生字母
h = h + 1 '如果输入正确则得分加1
Label5.Caption = "当前得分:" & h '显示当前得分
End If
End Sub
Private Sub Timer1_Timer()
'3.1.7计时器1
Dim i As Integer
Timer2.Interval = 250
For i = 0 To Label1.Count - 1
Label1(i).Top = Label1(i).Top + HScroll1.Value '控制字母嗠词移动以及移动速度
If Label1(i).Top > Form1.Height Then
n = n + 1 '记录掉落个数
Label3.Caption = "掉落个数:" & n
Label1(i).Top = -10
Randomize
Label1(i).ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) '产生颜色
End If
If n = 26 Then
If MsgBox("已经错过" & n & "个,重新开始", vbYesNo) = vbYes Then '提示框
Form_Load
Else
Form_Load '控制重新游戏还是结束游戏
End If
10
End If
Next
End Sub
Private Sub Timer2_Timer()
'3.1.8计时器2
Timer2.Interval = 1000
If (n + h) <> 0 Then
Label6.Caption = "正确率" & h / (n + h) * 100 \ 1 & "%" '显示正确率
End If
Static s
s = s + 1
Dim miao As String
Dim fen As String
Dim shi As String
If s Mod 60 < 10 Then
miao = 0
Else
miao = ""
End If
If (s Mod 3600) \ 60 < 10 Then
fen = 0
Else
fen = ""
End If
If s \ 3600 < 10 Then
shi = 0
Else
shi = ""
End If
Label4.Caption = "时间 " & shi & s \ 3600 & ":" & fen & (s Mod 3600) \ 60 & ":" & miao & s Mod 60 '显示已用时间
End Sub