VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



The Smallest Tic Tac Toe code I could ever come up with (just for 2 players)

by ACMOA (7 Submissions)
Category: Games
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 20th January 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

The Smallest Tic Tac Toe code I could ever come up with (just for 2 players)

API Declarations


set the index between 1 and 9 and allign them in terms of index as follows
1 2 3
4 5 6
7 8 9

Rate The Smallest Tic Tac Toe code I could ever come up with (just for 2 players)



Dim P(1 To 2) As String
Dim TURN As Integer
Dim COUNTT As Integer
Private Sub Form_Load()
TURN = 1
COUNTT = 0
P(1) = "X"
P(2) = "O"
End Sub

Private Sub play_Click(Index As Integer)
play(Index).Caption = P(TURN)
COUNTT = COUNTT + 1
play(Index).Enabled = False
WINCOND(Index) = P(TURN)
Call WIN("XXX")
Call WIN("OOO")
TURN = TURN + 1
If TURN > 2 Then TURN = 1
If COUNTT = 9 Then
For i = 1 To 9
  If play(i).Enabled = False Then DRAW
Next
End If

End Sub

Public Function WIN(X As String)
Select Case X
 Case WINCOND(1) + WINCOND(2) + WINCOND(3)
 WINNER
 Case WINCOND(4) + WINCOND(5) + WINCOND(6)
 WINNER
 Case WINCOND(7) + WINCOND(8) + WINCOND(9)
 WINNER
 Case WINCOND(1) + WINCOND(4) + WINCOND(7)
 WINNER
 Case WINCOND(2) + WINCOND(5) + WINCOND(8)
 WINNER
 Case WINCOND(3) + WINCOND(6) + WINCOND(9)
 WINNER
 Case WINCOND(1) + WINCOND(5) + WINCOND(9)
 WINNER
 Case WINCOND(3) + WINCOND(5) + WINCOND(7)
 WINNER
End Select
End Function

Public Function WINNER()
MsgBox (P(TURN) & " IS THE WINNER"), , "Tic-Tac-Toe"
RESET
End Function

Public Function RESET()
For i = 1 To 9
   WINCOND(i) = Empty
   play(i).Caption = Empty
   play(i).Enabled = True
Next
COUNTT = 0
End Function

Public Function DRAW()
MsgBox ("NO WINNERS"), , "Tic-Tac-Toe"
RESET
End Function


Download this snippet    Add to My Saved Code

The Smallest Tic Tac Toe code I could ever come up with (just for 2 players) Comments

No comments have been posted about The Smallest Tic Tac Toe code I could ever come up with (just for 2 players). Why not be the first to post a comment about The Smallest Tic Tac Toe code I could ever come up with (just for 2 players).

Post your comment

Subject:
Message:
0/1000 characters