If turn.Caption = "X" And s(y).Caption = "" And cwon = False And iwon = False And tie = False Then
s(y).Caption = "X"
turn.Caption = "O"
Call check
lblnum = Val(lblnum.Caption) + 2
End If
End Sub
Private Sub Timer1_Timer()
'Checks to see if anyone has one
If s(0).Caption = "X" And s(1).Caption = "X" And s(2).Caption = "X" Then
iwon = True
cwon = False
tie = False
Line5(0).Visible = True
End If
If s(3).Caption = "X" And s(4).Caption = "X" And s(5).Caption = "X" Then
iwon = True
cwon = False
tie = False
Line5(1).Visible = True
End If
If s(6).Caption = "X" And s(7).Caption = "X" And s(8).Caption = "X" Then
iwon = True
cwon = False
tie = False
Line5(2).Visible = True
End If
If s(0).Caption = "X" And s(3).Caption = "X" And s(6).Caption = "X" Then
iwon = True
cwon = False
tie = False
Line5(3).Visible = True
End If
If s(1).Caption = "X" And s(4).Caption = "X" And s(7).Caption = "X" Then
iwon = True
cwon = False
tie = False
Line5(4).Visible = True
End If
If s(2).Caption = "X" And s(5).Caption = "X" And s(8).Caption = "X" Then
iwon = True
cwon = False
tie = False
Line5(5).Visible = True
End If
If s(0).Caption = "X" And s(4).Caption = "X" And s(8).Caption = "X" Then
iwon = True
cwon = False
tie = False
Line5(6).Visible = True
End If
If s(2).Caption = "X" And s(4).Caption = "X" And s(6).Caption = "X" Then
iwon = True
cwon = False
tie = False
Line5(7).Visible = True
End If
If s(0).Caption = "O" And s(1).Caption = "O" And s(2).Caption = "O" Then
iwon = False
cwon = True
tie = False
Line5(0).Visible = True
End If
If s(3).Caption = "O" And s(4).Caption = "O" And s(5).Caption = "O" Then
iwon = False
cwon = True
tie = False
Line5(1).Visible = True
End If
If s(6).Caption = "O" And s(7).Caption = "O" And s(8).Caption = "O" Then
iwon = False
cwon = True
tie = False
Line5(2).Visible = True
End If
If s(0).Caption = "O" And s(3).Caption = "O" And s(6).Caption = "O" Then
iwon = False
cwon = True
tie = False
Line5(3).Visible = True
End If
If s(1).Caption = "O" And s(4).Caption = "O" And s(7).Caption = "O" Then
iwon = False
cwon = True
tie = False
Line5(4).Visible = True
End If
If s(2).Caption = "O" And s(5).Caption = "O" And s(8).Caption = "O" Then
iwon = False
cwon = True
tie = False
Line5(5).Visible = True
End If
If s(0).Caption = "O" And s(4).Caption = "O" And s(8).Caption = "O" Then
iwon = False
cwon = True
tie = False
Line5(6).Visible = True
End If
If s(2).Caption = "O" And s(4).Caption = "O" And s(6).Caption = "O" Then
iwon = False
cwon = True
tie = False
Line5(7).Visible = True
End If
If s(0) <> "" And s(1) <> "" And s(2) <> "" And s(3) <> "" And s(4) <> "" And s(5) <> "" And s(6) <> "" And s(7) <> "" And s(8) <> "" And cwon = False And iwon = False Then
tie = True
iwon = False
cwon = False
End If
End Sub
Private Sub Timer2_Timer()
'this is where the computer "thinks"
If iwon = False And cwon = False And tie = False Then
If turn.Caption = "O" And s(0).Caption = "X" And s(1).Caption = "X" And s(2).Caption = "" Or s(0).Caption = "O" And s(1).Caption = "O" And s(2).Caption = "" Then
s(2).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(0).Caption = "X" And s(2).Caption = "X" And s(1).Caption = "" Or s(0).Caption = "O" And s(2).Caption = "O" And s(1).Caption = "" Then
s(1).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(1).Caption = "X" And s(2).Caption = "X" And s(0).Caption = "" Or s(1).Caption = "O" And s(2).Caption = "O" And s(0).Caption = "" Then
s(0).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(3).Caption = "X" And s(4).Caption = "X" And s(5).Caption = "" Or s(3).Caption = "O" And s(4).Caption = "O" And s(5).Caption = "" Then
s(5).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(3).Caption = "X" And s(5).Caption = "X" And s(4).Caption = "" Or s(0).Caption = "O" And s(5).Caption = "O" And s(4).Caption = "" Then
s(4).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(4).Caption = "X" And s(5).Caption = "X" And s(3).Caption = "" Or s(4).Caption = "O" And s(5).Caption = "O" And s(3).Caption = "" Then
s(3).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(6).Caption = "X" And s(7).Caption = "X" And s(8).Caption = "" Or s(6).Caption = "O" And s(7).Caption = "O" And s(8).Caption = "" Then
s(8).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(6).Caption = "X" And s(8).Caption = "X" And s(7).Caption = "" Or s(6).Caption = "O" And s(8).Caption = "O" And s(7).Caption = "" Then
s(7).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(7).Caption = "X" And s(8).Caption = "X" And s(6).Caption = "" Or s(7).Caption = "O" And s(8).Caption = "O" And s(6).Caption = "" Then
s(6).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(0).Caption = "X" And s(3).Caption = "X" And s(6).Caption = "" Or s(0).Caption = "O" And s(3).Caption = "O" And s(6).Caption = "" Then
s(6).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(0).Caption = "X" And s(6).Caption = "X" And s(3).Caption = "" Or s(0).Caption = "O" And s(6).Caption = "O" And s(3).Caption = "" Then
s(3).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(3).Caption = "X" And s(6).Caption = "X" And s(0).Caption = "" Or s(3).Caption = "O" And s(6).Caption = "O" And s(0).Caption = "" Then
s(0).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(1).Caption = "X" And s(4).Caption = "X" And s(7).Caption = "" Or s(1).Caption = "O" And s(4).Caption = "O" And s(7).Caption = "" Then
s(7).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(1).Caption = "X" And s(7).Caption = "X" And s(4).Caption = "" Or s(1).Caption = "O" And s(7).Caption = "O" And s(4).Caption = "" Then
s(4).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(4).Caption = "X" And s(7).Caption = "X" And s(1).Caption = "" Or s(4).Caption = "O" And s(7).Caption = "O" And s(1).Caption = "" Then
s(1).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(2).Caption = "X" And s(5).Caption = "X" And s(8).Caption = "" Or s(2).Caption = "O" And s(5).Caption = "O" And s(8).Caption = "" Then
s(8).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(2).Caption = "X" And s(8).Caption = "X" And s(5).Caption = "" Or s(2).Caption = "O" And s(8).Caption = "O" And s(5).Caption = "" Then
s(5).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(5).Caption = "X" And s(8).Caption = "X" And s(2).Caption = "" Or s(5).Caption = "O" And s(8).Caption = "O" And s(2).Caption = "" Then
s(2).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(0).Caption = "X" And s(4).Caption = "X" And s(8).Caption = "" Or s(0).Caption = "O" And s(4).Caption = "O" And s(8).Caption = "" Then
s(8).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(0).Caption = "X" And s(8).Caption = "X" And s(4).Caption = "" Or s(0).Caption = "O" And s(8).Caption = "O" And s(4).Caption = "" Then
s(4).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(4).Caption = "X" And s(8).Caption = "X" And s(0).Caption = "" Or s(4).Caption = "O" And s(8).Caption = "O" And s(0).Caption = "" Then
s(0).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(2).Caption = "X" And s(4).Caption = "X" And s(6).Caption = "" Or s(2).Caption = "O" And s(4).Caption = "O" And s(6).Caption = "" Then
s(6).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
ElseIf turn.Caption = "O" And s(2).Caption = "X" And s(6).Caption = "X" And s(4).Caption = "" Or s(2).Caption = "O" And s(6).Caption = "O" And s(4).Caption = "" Then
s(4).Caption = "O"
turn.Caption = "X"
Timer2.Interval = 0
Else:
Timer2.Interval = 0
Timer3.Interval = 1
End If
End If
End Sub
Private Sub check()
If lblnum.Caption < 4 Then
Timer3.Interval = 1
End If
If lblnum.Caption >= 5 Then
Timer2.Interval = 1
End If
End Sub
Private Sub Timer3_Timer()
choose:
Randomize
x = Int(Rnd * 9) + 1
Select Case x
Case 1
If s(0).Caption = "" Then
s(0).Caption = "O"
turn.Caption = "X"
Timer3.Interval = 0
ElseIf s(0).Caption = "X" Or s(0).Caption = "O" Then
GoTo choose
End If
Case 2
If s(1).Caption = "" Then
s(1).Caption = "O"
turn.Caption = "X"
Timer3.Interval = 0
ElseIf s(1).Caption = "X" Or s(1).Caption = "O" Then
GoTo choose
End If
Case 3
If s(2).Caption = "" Then
s(2).Caption = "O"
turn.Caption = "X"
Timer3.Interval = 0
ElseIf s(2).Caption = "X" Or s(2).Caption = "O" Then
GoTo choose
End If
Case 4
If s(3).Caption = "" Then
s(3).Caption = "O"
turn.Caption = "X"
Timer3.Interval = 0
ElseIf s(3).Caption = "X" Or s(3).Caption = "O" Then
GoTo choose
End If
Case 5
If s(4).Caption = "" Then
s(4).Caption = "O"
turn.Caption = "X"
Timer3.Interval = 0
ElseIf s(4).Caption = "X" Or s(4).Caption = "O" Then
GoTo choose
End If
Case 6
If s(5).Caption = "" Then
s(5).Caption = "O"
turn.Caption = "X"
Timer3.Interval = 0
ElseIf s(5).Caption = "X" Or s(5).Caption = "O" Then
GoTo choose
End If
Case 7
If s(6).Caption = "" Then
s(6).Caption = "O"
turn.Caption = "X"
Timer3.Interval = 0
ElseIf s(6).Caption = "X" Or s(6).Caption = "O" Then
GoTo choose
End If
Case 8
If s(7).Caption = "" Then
s(7).Caption = "O"
turn.Caption = "X"
Timer3.Interval = 0
ElseIf s(7).Caption = "X" Or s(7).Caption = "O" Then
GoTo choose
End If
Case 9
If s(8).Caption = "" Then
s(8).Caption = "O"
turn.Caption = "X"
Timer3.Interval = 0
ElseIf s(8).Caption = "X" Or s(8).Caption = "O" Then
GoTo choose
End If
End Select
End Sub
Private Sub Timer4_Timer()
If cwon = True Then
Timer1.Interval = 0
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
lost = MsgBox("The computer beat you!", vbExclamation, "Tic Tac Toe")
Label1(3).Caption = Val(Label1(3)) + 1
turn.Caption = ""
End If
If iwon = True Then
Timer1.Interval = 0
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
win = MsgBox("You Beat the computer!", vbExclamation, "Tic Tac Toe")
Label1(2).Caption = Val(Label1(2)) + 1
turn.Caption = ""
End If
If tie = True Then
Timer1.Interval = 0
Timer2.Interval = 0
Timer3.Interval = 0
Timer4.Interval = 0
atie = MsgBox("There is no winner. The game is a tie!", vbExclamation, "Tic Tac Toe")