求大佬解释以下vb代码,每一步的详细解释!!!
OptionExplicitDimsheet(),key,snake(),lastkey,block(1To2),movingAsBoolean,pauseAsBoole...
Option Explicit
Dim sheet(), key, snake(), lastkey, block(1 To 2), moving As Boolean, pause As Boolean, tm
Private Sub Form_Activate()
Caption = "贪吃蛇简易版 By pt98 (SPACE-开始或暂停,Q-退出,F-手工添加青蛙 带加速减速功能)"
AutoRedraw = True: BackColor = vbBlack: ForeColor = vbGreen '定义form属性
block(1) = "■": block(2) = "¤" '蛇身及食物标志
End Sub
Function initsnake()
Dim x, y
ReDim sheet(1 To 50, 1 To 50) '定义表格尺寸
x = Int(UBound(sheet, 1) / 2): y = Int(UBound(sheet, 2) / 2) '第一次蛇身出现位置
ReDim Preserve snake(1 To 2)
snake(1) = x: snake(2) = y: sheet(x, y) = block(1)
Randomize: key = 37 + Int(Rnd * 4) '随机产生移动方向
lastkey = key: addfood 1: tm = 200
End Function
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 70 Then Randomize: addfood Int(Rnd * 10 + 1) '手工添加五只青蛙
If KeyCode = 81 Then End
If KeyCode = 32 Then
If moving Then
pause = Not pause '移动中pause轮流切换
Else
moving = True: initsnake: movestep '非移动中直接开始游戏
End If
End If
If KeyCode >= 37 And KeyCode <= 40 And moving Then '有效键
If Abs(KeyCode - lastkey) = 2 Then tm = 600: Exit Sub '连续方向键为相反方向就减速
If KeyCode = lastkey Then '连续方向键相同方向就加速
If tm >= 60 Then tm = tm - 20
Else
tm = 200 '复位速度
End If
key = KeyCode: lastkey = key
End If
End Sub
Function movestep()
Dim i, j, s, t, foodflag As Boolean
Do
Select Case key
Case 38, 40 '上、下
If snake(1) = IIf(key = 38, 1, UBound(sheet, 1)) Then Exit Do '碰壁
If sheet(snake(1) + IIf(key = 38, 展开
Dim sheet(), key, snake(), lastkey, block(1 To 2), moving As Boolean, pause As Boolean, tm
Private Sub Form_Activate()
Caption = "贪吃蛇简易版 By pt98 (SPACE-开始或暂停,Q-退出,F-手工添加青蛙 带加速减速功能)"
AutoRedraw = True: BackColor = vbBlack: ForeColor = vbGreen '定义form属性
block(1) = "■": block(2) = "¤" '蛇身及食物标志
End Sub
Function initsnake()
Dim x, y
ReDim sheet(1 To 50, 1 To 50) '定义表格尺寸
x = Int(UBound(sheet, 1) / 2): y = Int(UBound(sheet, 2) / 2) '第一次蛇身出现位置
ReDim Preserve snake(1 To 2)
snake(1) = x: snake(2) = y: sheet(x, y) = block(1)
Randomize: key = 37 + Int(Rnd * 4) '随机产生移动方向
lastkey = key: addfood 1: tm = 200
End Function
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 70 Then Randomize: addfood Int(Rnd * 10 + 1) '手工添加五只青蛙
If KeyCode = 81 Then End
If KeyCode = 32 Then
If moving Then
pause = Not pause '移动中pause轮流切换
Else
moving = True: initsnake: movestep '非移动中直接开始游戏
End If
End If
If KeyCode >= 37 And KeyCode <= 40 And moving Then '有效键
If Abs(KeyCode - lastkey) = 2 Then tm = 600: Exit Sub '连续方向键为相反方向就减速
If KeyCode = lastkey Then '连续方向键相同方向就加速
If tm >= 60 Then tm = tm - 20
Else
tm = 200 '复位速度
End If
key = KeyCode: lastkey = key
End If
End Sub
Function movestep()
Dim i, j, s, t, foodflag As Boolean
Do
Select Case key
Case 38, 40 '上、下
If snake(1) = IIf(key = 38, 1, UBound(sheet, 1)) Then Exit Do '碰壁
If sheet(snake(1) + IIf(key = 38, 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询