gcorm18
10-23-2000, 10:55 AM
I've created a Tic Tac Toe program and I was informed by my VB instructor that there might be a shorter way to do this... please someone help...
Private Sub optO_Click(Index As Integer)
'code for not cheeting
If optO(Index).Value = True Then
lblDisplay(Index).Caption = "O"
optX(Index).Enabled = False
End If
'Calculate for all possible wins for O
If optO(0).Value = True And optO(1).Value = True And optO(2).Value = True Then
lblWl.Caption = "O WINS"
End If
If optO(3).Value = True And optO(4).Value = True And optO(5).Value = True Then
lblWl.Caption = "O WINS"
End If
If optO(6).Value = True And optO(7).Value = True And optO(8).Value = True Then
lblWl.Caption = "O WINS"
End If
If optO(0).Value = True And optO(3).Value = True And optO(6).Value = True Then
lblWl.Caption = "O WINS"
End If
If optO(1).Value = True And optO(4).Value = True And optO(7).Value = True Then
lblWl.Caption = "O WINS"
End If
If optO(2).Value = True And optO(5).Value = True And optO(8).Value = True Then
lblWl.Caption = "O WINS"
End If
If optO(2).Value = True And optO(4).Value = True And optO(6).Value = True Then
lblWl.Caption = "O WINS"
End If
If optO(0).Value = True And optO(4).Value = True And optO(8).Value = True Then
lblWl.Caption = "O WINS"
End If
End Sub
Private Sub optX_Click(Index As Integer)
'code for not cheeting
If optX(Index).Value = True Then
lblDisplay(Index).Caption = "X"
optO(Index).Enabled = False
End If
'Calculate for all possible wins for X
If optX(0).Value = True And optX(1).Value = True And optX(2).Value = True Then
lblWl.Caption = "X WINS"
End If
If optX(3).Value = True And optX(4).Value = True And optX(5).Value = True Then
lblWl.Caption = "X WINS"
End If
If optX(6).Value = True And optX(7).Value = True And optX(8).Value = True Then
lblWl.Caption = "X WINS"
End If
If optX(0).Value = True And optX(3).Value = True And optX(6).Value = True Then
lblWl.Caption = "X WINS"
End If
If optX(1).Value = True And optX(4).Value = True And optX(7).Value = True Then
lblWl.Caption = "X WINS"
End If
If optX(2).Value = True And optX(5).Value = True And optX(8).Value = True Then
lblWl.Caption = "X WINS"
End If
If optX(2).Value = True And optX(4).Value = True And optX(6).Value = True Then
lblWl.Caption = "X WINS"
End If
If optX(0).Value = True And optX(4).Value = True And optX(8).Value = True Then
lblWl.Caption = "X WINS"
End If
End Sub
Private Sub optO_Click(Index As Integer)
'code for not cheeting
If optO(Index).Value = True Then
lblDisplay(Index).Caption = "O"
optX(Index).Enabled = False
End If
'Calculate for all possible wins for O
If optO(0).Value = True And optO(1).Value = True And optO(2).Value = True Then
lblWl.Caption = "O WINS"
End If
If optO(3).Value = True And optO(4).Value = True And optO(5).Value = True Then
lblWl.Caption = "O WINS"
End If
If optO(6).Value = True And optO(7).Value = True And optO(8).Value = True Then
lblWl.Caption = "O WINS"
End If
If optO(0).Value = True And optO(3).Value = True And optO(6).Value = True Then
lblWl.Caption = "O WINS"
End If
If optO(1).Value = True And optO(4).Value = True And optO(7).Value = True Then
lblWl.Caption = "O WINS"
End If
If optO(2).Value = True And optO(5).Value = True And optO(8).Value = True Then
lblWl.Caption = "O WINS"
End If
If optO(2).Value = True And optO(4).Value = True And optO(6).Value = True Then
lblWl.Caption = "O WINS"
End If
If optO(0).Value = True And optO(4).Value = True And optO(8).Value = True Then
lblWl.Caption = "O WINS"
End If
End Sub
Private Sub optX_Click(Index As Integer)
'code for not cheeting
If optX(Index).Value = True Then
lblDisplay(Index).Caption = "X"
optO(Index).Enabled = False
End If
'Calculate for all possible wins for X
If optX(0).Value = True And optX(1).Value = True And optX(2).Value = True Then
lblWl.Caption = "X WINS"
End If
If optX(3).Value = True And optX(4).Value = True And optX(5).Value = True Then
lblWl.Caption = "X WINS"
End If
If optX(6).Value = True And optX(7).Value = True And optX(8).Value = True Then
lblWl.Caption = "X WINS"
End If
If optX(0).Value = True And optX(3).Value = True And optX(6).Value = True Then
lblWl.Caption = "X WINS"
End If
If optX(1).Value = True And optX(4).Value = True And optX(7).Value = True Then
lblWl.Caption = "X WINS"
End If
If optX(2).Value = True And optX(5).Value = True And optX(8).Value = True Then
lblWl.Caption = "X WINS"
End If
If optX(2).Value = True And optX(4).Value = True And optX(6).Value = True Then
lblWl.Caption = "X WINS"
End If
If optX(0).Value = True And optX(4).Value = True And optX(8).Value = True Then
lblWl.Caption = "X WINS"
End If
End Sub