VB “玩家得分累加50”的 代码 怎么写

来源:百度知道 编辑:UC知道 时间:2024/09/20 23:27:31
是打字母游戏 打一个 字母 50分 分数怎么累加 求代码
什么是全局变量? 二楼的? 我不太懂VB!

'一个Timer控件
Dim lngS As Long '分数
Dim intLetter As Integer
Dim blnPlaying As Boolean
Private Sub Form_Click()
'单击开始游戏
lngS = 0
intLetter = GetLetter
blnPlaying = True
SetFocus
Timer1.Enabled = True
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
Debug.Print KeyAscii
If blnPlaying Then
If KeyAscii = 27 Then
blnPlaying = False '按ESC键游戏结束
Timer1.Enabled = False
Cls
Print "得分:"; lngS
Else
If KeyAscii = intLetter Then
lngS = lngS + 50 '字母一致,分数累计
End If
intLetter = GetLetter '产生新的字母
End If
End If
End Sub

Private Sub Form_Load()
AutoRedraw = True
Timer1.Enabled = False
Timer1.Interval = 1000
End Sub

Private Function GetLetter() As Integer
Randomize
GetLetter = Int(Rnd * 26) + 97 'a--z的ASCII码
Cls
CurrentX = Wi