I made a game of 15 which works just fine with mouse clicks. I want it to respond to keyboard clicks such as left, right, up and down keys. How do add that feature to this code? I tried KeyDown, KeyUp, KeyPress and they just won't reaspond. I tried it on both the actual form and the button cmd15.
Code:
Private Sub Form_Load()
Call NewGame
End Sub
Private Sub Cmd15_Click(Index As Integer)
Dim I%, Test%
If Index + 4 <= 15 Then
If Cmd15(Index + 4).Caption = "" Then
Cmd15(Index + 4).Caption = Cmd15(Index).Caption
Cmd15(Index).Caption = ""
GoTo Check
End If
End If
If Index - 4 >= 0 Then
If Cmd15(Index - 4).Caption = "" Then
Cmd15(Index - 4).Caption = Cmd15(Index).Caption
Cmd15(Index).Caption = ""
GoTo Check
End If
End If
If Index + 1 <= 15 Then
If Cmd15(Index + 1).Caption = "" Then
Test = 1
For I = 4 To 3
If Index + 1 = I Then Test = 0
I = I + 3
Next I
If Test = 1 Then
Cmd15(Index + 1).Caption = Cmd15(Index).Caption
Cmd15(Index).Caption = ""
End If
GoTo Check
End If
End If
If Index - 1 >= 0 Then
If Cmd15(Index - 1).Caption = "" Then
Test = 1
For I = 3 To 4
If Index - 1 = I Then Test = 0
I = I + 3
Next I
If Test = 1 Then
Cmd15(Index - 1).Caption = Cmd15(Index).Caption
Cmd15(Index).Caption = ""
End If
End If
End If
Check: Call CheckEndGame
End Sub
Private Sub NewGame()
Dim I As Integer
Dim Help As Integer, Test As Integer, J As Integer
For I = 0 To 14
Cmd15(I).Caption = 0
Next I
For I = 0 To 14
Test = 1
While Test = 1
Help = (Rnd * 14) + 1
For J = 0 To 14
If Help = Cmd15(J).Caption Then Test = 0
Next J
If Test = 0 Then
Test = 1
Else: Test = 0
End If
Wend
Cmd15(I).Caption = Help
Next I
Cmd15(15).Caption = ""
End Sub
Private Sub Resign()
Dim I As Integer
For I = 0 To 14
Cmd15(I).Caption = I + 1
Next I
Cmd15(15).Caption = ""
End Sub
Private Sub CheckEndGame()
Dim I As Integer, Test As Integer
Test = 1
For I = 0 To 14
If Cmd15(I).Caption <> "" Then
If Cmd15(I).Caption <> I + 1 Then Test = 0
Else: Test = 0
End If
Next I
If Test = 1 Then
End
End If
End Sub
Private Sub mnuAbout_Click()
frmAbout.Show
End Sub
Private Sub mnuExit_Click()
End
End Sub
Private Sub mnuNewGame_Click()
Call NewGame
End Sub
Private Sub mnuResign_Click()
Call Resign
End Sub