Professional Documents
Culture Documents
Tic Tac Toe
Tic Tac Toe
Tic Tac Toe is a popular game which you can play at any time and anywhere as long as you have a piece
of paper and a pen, or you could draw it on sand or any surface. Now, we have programmed it in VB so
that you can play the game virtually. First of all, you need to draw the interface with four straight lines,
then insert nine image controls and make them an array, Image1(0) to Image1(8). Secondly, insert two
pictures, one is a circle and the other one is a cross to represent player 1 and player2.
To check whether a position is empty or not, we use two arrays, cross(8) and ball(8) (We use
ball instead of circle because circle is an internal function of VB) and set them as Boolean. If
cross(n)=false and ball(n)=false, that means position n is not occupied by a cross or a ball,
where n is any integer between 0 and 8.
In addition, you need to insert eight straight lines that would cross out three crosses or three
circles if they are aligned in a straight line side by side, as shown in the diagram. You need to
make these lines invisible at start-up and make one of the lines appear whenever the above
condition is fulfilled.
The Interface
Sub check_status()
If ball(0) = True And ball(1) = True And ball(2) = True Then
Line10.Visible = True
End If
If ball(3) = True And ball(4) = True And ball(5) = True Then
Line9.Visible = True
End If
If ball(6) = True And ball(7) = True And ball(8) = True Then
Line8.Visible = True
End If
If ball(0) = True And ball(3) = True And ball(6) = True Then
Line5.Visible = True
End If
For m = 0 To 8
cross(m) = False
End If
Next
End Sub
Private Sub Image1_Click(Index As Integer)
check_position
check_position
check_status
End Sub
Private Sub Image2_Click()
player = 1
End Sub