For school, I have to create a tic tac toe program but I have found checking for a win seems to be longer than is probably needed. I used the tag property to keep track of who clicked on the square and to make sure that u can't click on one that has already been clicked.
VB Code:
If Index = 0 Then If lblBox(0).Tag = "1" Then If lblBox(3).Tag = "1" And lblBox(6).Tag = "1" Then MsgBox "Player 1 wins", vbOKOnly, "Winner!" ElseIf lblBox(0).Tag = "2" Then If lblBox(3).Tag = "2" And lblBox(6).Tag = "2" Then MsgBox "Player 2 Wins", vbOKOnly, "Winner!" ElseIf lblBox(0).Tag = "1" Then If lblBox(1).Tag = "1" And lblBox(2).Tag = "1" Then MsgBox "Player 1 wins", vbOKOnly, "Winner!" ElseIf lblBox(0).Tag = "2" Then If lblBox(1).Tag = "2" And lblBox(2).Tag = "2" Then MsgBox "Player 2 Wins", vbOKOnly, "Winner!" ElseIf lblBox(0).Tag = "1" Then If lblBox(4).Tag = "1" And lblBox(8).Tag = "1" Then MsgBox "Player 1 wins", vbOKOnly, "Winner!" ElseIf lblBox(0).Tag = "2" Then If lblBox(4).Tag = "2" And lblBox(8).Tag = "2" Then MsgBox "Player 2 Wins", vbOKOnly, "Winner!" End If End If
This is the code I am using now and all that only checks for across the top, down the left, and diangonal left top to right bottom. If theres an easier way to do this could you please help. Thanks.




Reply With Quote