回复 2楼 风吹过b
关键我要使用FOR循环语句,用for循环来判断标签数组控件每个元素的Top是否>8000,如果找到某个TOP>8000,则则弹出Msgbox,提示是否重来,如果按了“是”,则关闭当前窗体,加载游戏设置窗体,我把代码给你,麻烦帮我看一下。(解决?:按了“是”后,还再次弹出msgbox,我不想让他出现。)
第一个窗体:shezhi.frm代码
Option Explicit
Public speed As Integer, nd As Integer
Private Sub CmdExit_Click()
End
End Sub
Private Sub Cmdok_Click()
If (speed <> 1 And speed <> 2 And speed <> 3) Or (nd <> 1 And nd <> 2 And nd <> 3) Then '如果没有选择速度或难度,则弹出消息提示框
MsgBox "请选择速度与难度!", vbOK, ""
Else
Unload Me '卸载游戏设置窗体
Form1.Show '显示游戏窗体
End If
End Sub
Private Sub Form_Load()
End Sub
Private Sub nOption1_Click()
nd = 1
End Sub
Private Sub nOption2_Click()
nd = 2
End Sub
Private Sub nOption3_Click()
nd = 3
End Sub
Private Sub sOption1_Click()
speed = 1
End Sub
Private Sub sOption2_Click()
speed = 2
End Sub
Private Sub sOption3_Click()
speed = 3
End Sub
第二个窗体form1.frm代码
Option Explicit
Dim H As Integer '声明模块级变量-成绩
Public c As Integer '声明模块级变量-随机字符的ASCII码值
Private Sub Form_KeyPress(KeyAscii As Integer)
Dim i As Integer
Dim js
For i = 0 To Label1.Count - 1
If Chr(KeyAscii) = Label1.Item(i).Caption And Label1.Item(i).Top > 0 And Label1.Item(i).Top < 10000 Then '如果用户的按键与窗口出现的字符相同
Randomize '初始化随机数生成器
H = H + 2 '用户每击中一个字符,成绩加2分
Image1.Top = Label1.Item(i).Top '击中效果图片的TOP与当前击中的字符TOP相同
Image1.Left = Label1.Item(i).Left - 100 '击中效果图片的LEFT与当前击中的字符TEFT相同
Image1.Visible = True '击中某个字符,则显示击中效果图片
If shezhi.nd = 1 Then
c = Int((122 - 97 + 1) * Rnd + 97)
ElseIf shezhi.nd = 2 Then
c = Int((90 - 65 + 1) * Rnd + 65)
ElseIf shezhi.nd = 3 Then
c = Int((126 - 48 + 1) * Rnd + 48)
End If
Label1.Item(i).Caption = Chr(c) '将产生的随机字符赋值给标签数组中个标签元素的Caption
Label1.Item(i).Top = 0 - 538 * i
Label1.Item(i).Left = Int(20000 * Rnd + 1) '随机字符在窗体的定位
= "close"
MMControl1.FileName = App.Path & "\HAMMER.WAV"
= "open"
= "play" '用户击中某个显示的字符的瞬间,播放该击中效果音
End If
Next i
Dim Y
If KeyAscii = 27 Then '如果用户按了ESC键
Y = MsgBox("确定要退出吗?", vbYesNo, "退出操作") '弹出消息框
If Y = vbYes Then '如果用户选择“是”按钮
MsgBox "您现在的得分:" & H & "分", , "成绩" '结束程序
End
End If
End If
' Dim g
'If H = 20 Then
' g = MsgBox("第1关顺利过关!是否继续下一关?", vbYesNo, "过关提示")
' If g = vbYes Then
' Dim j As Integer
' Timer1.Interval = 25
' End If
'End If
' Select Case H
' Case 0 To 20
' Timer1.Interval = 100 '如果成绩在0-20之间,则时钟控件每100毫秒刷新一次
' Case 21 To 50
' Timer1.Interval = 80 '如果成绩在21-50之间,则时钟控件每80毫秒刷新一次
' Case 51 To 100
' Timer1.Interval = 60 '如果成绩在51-100之间,则时钟控件每60毫秒刷新一次
' Case Is > 100
' Timer1.Interval = 40 '如果成绩在>100,则时钟控件每40毫秒刷新一次
' End Select
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Image1.Visible = False '用户释放按键,击中效果图片不可见
End Sub
Private Sub Form_Load()
If shezhi.speed = 1 Then
Timer1.Interval = 100
ElseIf shezhi.speed = 2 Then
Timer1.Interval = 50
ElseIf shezhi.speed = 3 Then
Timer1.Interval = 20
End If
MMControl2.Visible = False '游戏时播放背景音乐
= "close"
MMControl2.FileName = App.Path & "\baby.mp3"
= "open"
= "play"
Label2.Top = Form1.ScaleHeight - 500
Label2.Left = Form1.ScaleWidth / 2 - Label2.Width / 2
H = 0
Dim i As Integer
For i = 0 To Label1.Count - 1 ' 加载窗体前,初始化标签数组的各元素的随机字符
Randomize
If shezhi.nd = 1 Then
c = Int((122 - 97 + 1) * Rnd + 97)
ElseIf shezhi.nd = 2 Then
c = Int((90 - 65 + 1) * Rnd + 65)
ElseIf shezhi.nd = 3 Then
c = Int((126 - 48 + 1) * Rnd + 48)
End If
Label1.Item(i).Caption = Chr(c) '产生随机字符
Label1.Item(i).FontSize = 38 '字体大小
Label1.Item(i).FontName = "Times New Roman"
Label1.Item(i).FontBold = True '字体加粗
Label1.Item(i).ForeColor = &HFF& '字体颜色
Label1.Item(i).Top = 0 - 538 * i '字体位置
Label1.Item(i).Left = Int(20000 * Rnd + 1)
Next i
End Sub
Private Sub Timer1_Timer()
Label2.Caption = H
Dim i As Integer
For i = 0 To Label1.Count - 1
Label1.Item(i).Top = Label1.Item(i).Top + 40
Next i
Dim js1
while
If Label1.Item(i).Top > 8000 Then
js1 = MsgBox("游戏结束!再玩一次?", vbYesNo, "游戏结束") '如果某个随机字符下降到一定高度,则弹出“是否重玩”消息框
If js1 = vbYes Then '如果用户按了“是”按钮,重玩游戏
shezhi.Show
Unload Form1
'ElseIf js1 = vbNo Then
' End
End If
End If
'显示实时的打字成绩
End Sub