mickey2000
03-14-2001, 08:59 AM
I have some code here for mt tic tac toe game. How would I turn this code so that two live players can play, instead of a one player game against the computer? And if its a draw "Cat's gmae" should display. Also what would be the nicest looking form on how this game should look? (So that it doesnt look like a complicated mess).
Dim Turn As Integer
Sub NewGame()
For Index = 0 To 8
imgSquare(Index).Picture = imgBlank.Picture
Next
Turn = 0
End Sub
Sub Win()
MsgBox "You win!"
NewGame
End Sub
Sub Lose()
MsgBox "You lose!"
NewGame
End Sub
Private Sub imgSquare_Click(Index As Integer)
Randomize
If imgSquare(Index).Picture = None Then
imgSquare(Index).Picture = imgX.Picture
Turn = Turn + 1
If imgSquare(0).Picture = imgX.Picture And imgSquare(1).Picture = imgX.Picture And imgSquare(2).Picture = imgX.Picture Then Win: Exit Sub
If imgSquare(3).Picture = imgX.Picture And imgSquare(4).Picture = imgX.Picture And imgSquare(5).Picture = imgX.Picture Then Win: Exit Sub
If imgSquare(6).Picture = imgX.Picture And imgSquare(7).Picture = imgX.Picture And imgSquare(8).Picture = imgX.Picture Then Win: Exit Sub
If imgSquare(0).Picture = imgX.Picture And imgSquare(4).Picture = imgX.Picture And imgSquare(8).Picture = imgX.Picture Then Win: Exit Sub
If imgSquare(2).Picture = imgX.Picture And imgSquare(4).Picture = imgX.Picture And imgSquare(6).Picture = imgX.Picture Then Win: Exit Sub
If imgSquare(0).Picture = imgX.Picture And imgSquare(3).Picture = imgX.Picture And imgSquare(6).Picture = imgX.Picture Then Win: Exit Sub
If imgSquare(1).Picture = imgX.Picture And imgSquare(4).Picture = imgX.Picture And imgSquare(7).Picture = imgX.Picture Then Win: Exit Sub
If imgSquare(2).Picture = imgX.Picture And imgSquare(5).Picture = imgX.Picture And imgSquare(8).Picture = imgX.Picture Then Win: Exit Sub
If Turn < 5 Then
FindSquare:
Square = Int(9 * Rnd)
If imgSquare(Square).Picture = None Then
imgSquare(Square).Picture = imgO.Picture
Else
GoTo FindSquare
End If
If imgSquare(0).Picture = imgO.Picture And imgSquare(1).Picture = imgO.Picture And imgSquare(2).Picture = imgO.Picture Then Lose: Exit Sub
If imgSquare(3).Picture = imgO.Picture And imgSquare(4).Picture = imgO.Picture And imgSquare(5).Picture = imgO.Picture Then Lose: Exit Sub
If imgSquare(6).Picture = imgO.Picture And imgSquare(7).Picture = imgO.Picture And imgSquare(8).Picture = imgO.Picture Then Lose: Exit Sub
If imgSquare(0).Picture = imgO.Picture And imgSquare(4).Picture = imgO.Picture And imgSquare(8).Picture = imgO.Picture Then Lose: Exit Sub
If imgSquare(2).Picture = imgO.Picture And imgSquare(4).Picture = imgO.Picture And imgSquare(6).Picture = imgO.Picture Then Lose: Exit Sub
If imgSquare(0).Picture = imgO.Picture And imgSquare(3).Picture = imgO.Picture And imgSquare(6).Picture = imgO.Picture Then Lose: Exit Sub
If imgSquare(1).Picture = imgO.Picture And imgSquare(4).Picture = imgO.Picture And imgSquare(7).Picture = imgO.Picture Then Lose: Exit Sub
If imgSquare(2).Picture = imgO.Picture And imgSquare(5).Picture = imgO.Picture And imgSquare(8).Picture = imgO.Picture Then Lose: Exit Sub
End If
End If
If Turn = 5 Then
MsgBox "Game is drawn"
NewGame
End If
End Sub
Private Sub mnuNewGame_Click()
NewGame
End Sub
Private Sub mnuQuit_Click()
Unload frmTicTacToe
End Sub
Dim Turn As Integer
Sub NewGame()
For Index = 0 To 8
imgSquare(Index).Picture = imgBlank.Picture
Next
Turn = 0
End Sub
Sub Win()
MsgBox "You win!"
NewGame
End Sub
Sub Lose()
MsgBox "You lose!"
NewGame
End Sub
Private Sub imgSquare_Click(Index As Integer)
Randomize
If imgSquare(Index).Picture = None Then
imgSquare(Index).Picture = imgX.Picture
Turn = Turn + 1
If imgSquare(0).Picture = imgX.Picture And imgSquare(1).Picture = imgX.Picture And imgSquare(2).Picture = imgX.Picture Then Win: Exit Sub
If imgSquare(3).Picture = imgX.Picture And imgSquare(4).Picture = imgX.Picture And imgSquare(5).Picture = imgX.Picture Then Win: Exit Sub
If imgSquare(6).Picture = imgX.Picture And imgSquare(7).Picture = imgX.Picture And imgSquare(8).Picture = imgX.Picture Then Win: Exit Sub
If imgSquare(0).Picture = imgX.Picture And imgSquare(4).Picture = imgX.Picture And imgSquare(8).Picture = imgX.Picture Then Win: Exit Sub
If imgSquare(2).Picture = imgX.Picture And imgSquare(4).Picture = imgX.Picture And imgSquare(6).Picture = imgX.Picture Then Win: Exit Sub
If imgSquare(0).Picture = imgX.Picture And imgSquare(3).Picture = imgX.Picture And imgSquare(6).Picture = imgX.Picture Then Win: Exit Sub
If imgSquare(1).Picture = imgX.Picture And imgSquare(4).Picture = imgX.Picture And imgSquare(7).Picture = imgX.Picture Then Win: Exit Sub
If imgSquare(2).Picture = imgX.Picture And imgSquare(5).Picture = imgX.Picture And imgSquare(8).Picture = imgX.Picture Then Win: Exit Sub
If Turn < 5 Then
FindSquare:
Square = Int(9 * Rnd)
If imgSquare(Square).Picture = None Then
imgSquare(Square).Picture = imgO.Picture
Else
GoTo FindSquare
End If
If imgSquare(0).Picture = imgO.Picture And imgSquare(1).Picture = imgO.Picture And imgSquare(2).Picture = imgO.Picture Then Lose: Exit Sub
If imgSquare(3).Picture = imgO.Picture And imgSquare(4).Picture = imgO.Picture And imgSquare(5).Picture = imgO.Picture Then Lose: Exit Sub
If imgSquare(6).Picture = imgO.Picture And imgSquare(7).Picture = imgO.Picture And imgSquare(8).Picture = imgO.Picture Then Lose: Exit Sub
If imgSquare(0).Picture = imgO.Picture And imgSquare(4).Picture = imgO.Picture And imgSquare(8).Picture = imgO.Picture Then Lose: Exit Sub
If imgSquare(2).Picture = imgO.Picture And imgSquare(4).Picture = imgO.Picture And imgSquare(6).Picture = imgO.Picture Then Lose: Exit Sub
If imgSquare(0).Picture = imgO.Picture And imgSquare(3).Picture = imgO.Picture And imgSquare(6).Picture = imgO.Picture Then Lose: Exit Sub
If imgSquare(1).Picture = imgO.Picture And imgSquare(4).Picture = imgO.Picture And imgSquare(7).Picture = imgO.Picture Then Lose: Exit Sub
If imgSquare(2).Picture = imgO.Picture And imgSquare(5).Picture = imgO.Picture And imgSquare(8).Picture = imgO.Picture Then Lose: Exit Sub
End If
End If
If Turn = 5 Then
MsgBox "Game is drawn"
NewGame
End If
End Sub
Private Sub mnuNewGame_Click()
NewGame
End Sub
Private Sub mnuQuit_Click()
Unload frmTicTacToe
End Sub