Public Class frmGame Dim a As New Integer 'changes to new integers Dim btn As New Button Private Sub Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click, btn2.Click, btn3.Click, btn4.Click, btn5.Click, btn6.Click, Btn7.Click, btn8.Click, btn9.Click btn = sender Select Case a Case 1 If btn.Text = " " Then 'Player X's Turn a = 2 lblTurn.Text = "Player O's Turn" btn.Text = "X" End If Case 2 If btn.Text = " " Then 'Player O's Turn a = 1 lblTurn.Text = "Player X's Turn" btn.Text = "O" End If End Select 'X Lines----------------------------------------------------------------- If btn1.Text = "X" And btn2.Text = "X" And btn3.Text = "X" Then 'If a line = X then X Wins lblWinner.Text = "X Wins" End If If btn4.Text = "X" And btn5.Text = "X" And btn6.Text = "X" Then lblWinner.Text = "X Wins" End If If Btn7.Text = "X" And btn8.Text = "X" And btn9.Text = "X" Then lblWinner.Text = "X Wins" End If If btn1.Text = "X" And btn4.Text = "X" And Btn7.Text = "X" Then lblWinner.Text = "X Wins" End If If btn2.Text = "X" And btn5.Text = "X" And btn8.Text = "X" Then lblWinner.Text = "X Wins" End If If btn3.Text = "X" And btn6.Text = "X" And btn9.Text = "X" Then lblWinner.Text = "X Wins" End If If btn1.Text = "X" And btn5.Text = "X" And btn9.Text = "X" Then lblWinner.Text = "X Wins" End If If btn3.Text = "X" And btn5.Text = "X" And Btn7.Text = "X" Then lblWinner.Text = "X Wins" End If If lblWinner.Text = "X Wins" Then 'Disables Buttons if X Wins lblTurn.Text = "" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False Btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If 'O Lines---------------------------------------------------------------------- If btn1.Text = "O" And btn2.Text = "O" And btn3.Text = "O" Then 'If a line = O then O Wins lblWinner.Text = "O Wins" End If If btn4.Text = "O" And btn5.Text = "O" And btn6.Text = "O" Then lblWinner.Text = "O Wins" End If If Btn7.Text = "O" And btn8.Text = "O" And btn9.Text = "O" Then lblWinner.Text = "O Wins" End If If btn1.Text = "O" And btn4.Text = "O" And Btn7.Text = "O" Then lblWinner.Text = "O Wins" End If If btn2.Text = "O" And btn5.Text = "O" And btn8.Text = "O" Then lblWinner.Text = "O Wins" End If If btn3.Text = "O" And btn6.Text = "O" And btn9.Text = "O" Then lblWinner.Text = "O Wins" End If If btn1.Text = "O" And btn5.Text = "O" And btn9.Text = "O" Then lblWinner.Text = "O Wins" End If If btn3.Text = "O" And btn5.Text = "O" And Btn7.Text = "O" Then lblWinner.Text = "O Wins" End If If lblWinner.Text = "O Wins" Then 'Disables buttons if O Wins lblTurn.Text = "" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False Btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If If btn1.Text = "X" or btn.1.text = "0" Then ElseIf btn2.Text = "X" Or btn2.Text = "O" Then ElseIf btn3.Text = "X" Or btn3.Text = "O" Then ElseIf btn4.Text = "X" Or btn4.Text = "O" Then ElseIf btn5.Text = "X" Or btn5.Text = "O" Then ElseIf btn6.Text = "X" Or btn6.Text = "O" Then ElseIf Btn7.Text = "X" Or Btn7.Text = "O" Then ElseIf btn8.Text = "X" Or btn8.Text = "O" Then ElseIf btn9.Text = "X" Or btn9.Text = "O" Then lblWinner.Text = "Tie" End If End Sub Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click btn1.Text = " " 'Starts out Buttons/Squares as Blank spaces btn2.Text = " " btn3.Text = " " btn4.Text = " " btn5.Text = " " btn6.Text = " " Btn7.Text = " " btn8.Text = " " btn9.Text = " " btn1.Enabled = True ' Enables the buttons to be pressed btn2.Enabled = True btn3.Enabled = True btn4.Enabled = True btn5.Enabled = True btn6.Enabled = True Btn7.Enabled = True btn8.Enabled = True btn9.Enabled = True lblTurn.Text = "Player X's Turn" a = 1 lblWinner.Text = " " End Sub End Class
I know this won't work, but can't figure out what will
If btn1.Text = "X" or btn.1.text = "0" Then ElseIf btn2.Text = "X" Or btn2.Text = "O" Then ElseIf btn3.Text = "X" Or btn3.Text = "O" Then ElseIf btn4.Text = "X" Or btn4.Text = "O" Then ElseIf btn5.Text = "X" Or btn5.Text = "O" Then ElseIf btn6.Text = "X" Or btn6.Text = "O" Then ElseIf Btn7.Text = "X" Or Btn7.Text = "O" Then ElseIf btn8.Text = "X" Or btn8.Text = "O" Then ElseIf btn9.Text = "X" Or btn9.Text = "O" Then lblWinner.Text = "Tie" End If

New Topic/Question
Reply




MultiQuote




|