一个拼图游戏,不知道为什么键盘控制没反应.其他地方有很多错我还没改,大家帮我找找为什么按键没反映的原因,谢谢.
我第一次写程序,可能错很多,希望大家多包容
Option Explicit
Private Sub Form_Load()
Dim a, b, c, d As Double
Dim flag As String
For b = 0 To 8
Picture1(b).Picture = LoadPicture(App.Path & "\pic" & b & ".jpg")
'Picture1.Picture = LoadPicture(App.Path & "\pic" & a & ".jpg")
Next
b = 0
c = 0
'a is no use
'b is used to check
'c is used as flag
'd is used to check
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
Select Case KeyCode
Case 37
If c Mod 3 <> 0 Then
falg = Picture1(c).Picture
Picture1(c - 1).Picture = Picture1(c).Picture
flag = Picture1(c - 1).Picture
falg = 0
End If
'Debug.Print "左"
End If
Case 38
If c > 2 Then
falg = Picture1(c).Picture
Picture1(c - 3).Picture = Picture1(c).Picture
flag = Picture1(c - 3).Picture
falg = 0
End If
'Debug.Print "上"
Case 39
If (c + 1) Mod 3 <> 1 Then
falg = Picture1(c).Picture
Picture1(c + 1).Picture = Picture1(c).Picture
flag = Picture1(c + 1).Picture
falg = 0
End If
'Debug.Print "右"
Case 40
If c < 6 Then
falg = Picture1(c).Picture
Picture1(c + 3).Picture = Picture1(c).Picture
flag = Picture1(c + 3).Picture
falg = 0
'Debug.Print "下"
Case Else 'Debug.Print "按下的不是方向键"
End Select
d = 0
For b = 0 To 8
If Picture1(b).Picture = LoadPicture(App.Path & "pic" & b & ".jpg") Then
d = d + 1
End If
If d = 9 Then
Print "恭喜您胜利"
'game over
End If
End Sub
我第一次写程序,可能错很多,希望大家多包容
Option Explicit
Private Sub Form_Load()
Dim a, b, c, d As Double
Dim flag As String
For b = 0 To 8
Picture1(b).Picture = LoadPicture(App.Path & "\pic" & b & ".jpg")
'Picture1.Picture = LoadPicture(App.Path & "\pic" & a & ".jpg")
Next
b = 0
c = 0
'a is no use
'b is used to check
'c is used as flag
'd is used to check
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
Select Case KeyCode
Case 37
If c Mod 3 <> 0 Then
falg = Picture1(c).Picture
Picture1(c - 1).Picture = Picture1(c).Picture
flag = Picture1(c - 1).Picture
falg = 0
End If
'Debug.Print "左"
End If
Case 38
If c > 2 Then
falg = Picture1(c).Picture
Picture1(c - 3).Picture = Picture1(c).Picture
flag = Picture1(c - 3).Picture
falg = 0
End If
'Debug.Print "上"
Case 39
If (c + 1) Mod 3 <> 1 Then
falg = Picture1(c).Picture
Picture1(c + 1).Picture = Picture1(c).Picture
flag = Picture1(c + 1).Picture
falg = 0
End If
'Debug.Print "右"
Case 40
If c < 6 Then
falg = Picture1(c).Picture
Picture1(c + 3).Picture = Picture1(c).Picture
flag = Picture1(c + 3).Picture
falg = 0
'Debug.Print "下"
Case Else 'Debug.Print "按下的不是方向键"
End Select
d = 0
For b = 0 To 8
If Picture1(b).Picture = LoadPicture(App.Path & "pic" & b & ".jpg") Then
d = d + 1
End If
If d = 9 Then
Print "恭喜您胜利"
'game over
End If
End Sub
Option ExplicitPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyLeft
If c Mod 3 <> 0 Then
falg = Picture1(c).Picture
Picture1(c - 1).Picture = Picture1(c).Picture
flag = Picture1(c - 1).Picture
falg = 0
End If
'Debug.Print "左"
End If
Case vbKeyUp
If c > 2 Then
falg = Picture1(c).Picture
Picture1(c - 3).Picture = Picture1(c).Picture
flag = Picture1(c - 3).Picture
falg = 0
End If
'Debug.Print "上"
Case vbKeyDown
If (c + 1) Mod 3 <> 1 Then
falg = Picture1(c).Picture
Picture1(c + 1).Picture = Picture1(c).Picture
flag = Picture1(c + 1).Picture
falg = 0
End If
'Debug.Print "右"
Case vbKeyRight
If c < 6 Then
falg = Picture1(c).Picture
Picture1(c + 3).Picture = Picture1(c).Picture
flag = Picture1(c + 3).Picture
falg = 0
'Debug.Print "下"
Case Else 'Debug.Print "按下的不是方向键"
End Select
d = 0
For b = 0 To 8
If Picture1(b).Picture = LoadPicture(App.Path & "pic" & b & ".jpg") Then
d = d + 1
End If
If d = 9 Then
Print "恭喜您胜利"
'game over
End If
End SubPrivate Sub Form_Load()
Dim a, b, c, d As Double
Dim flag As String
For b = 0 To 8
Picture1(b).Picture = LoadPicture(App.Path & "\pic" & b & ".jpg")
'Picture1.Picture = LoadPicture(App.Path & "\pic" & a & ".jpg")
Next
b = 0
c = 0
'a is no use
'b is used to check
'c is used as flag
'd is used to check
End Sub