I'm creating a two-player Tic-Tac-Toe game. I have the game programmed up until the point that someone wins. I'm not sure how to code this. My board is set as an array - board(2,2). My code is below. Can anyone give me an idea of how to proceed? I'm sure I probably need to set a loop in the code somehow but unsure of where and how to do it. Thanks!!!
[code=vbnet]
Public Class Form1
Public player1 As Boolean
'start button starts game and sets first player as X's
Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles startbutton.Cli ck
Dim firstplayer As Char
Dim secondplayer As Char
Dim x As Char
Dim O As Char
firstplayer = x
secondplayer = O
Dim board(2, 2) As Integer
MessageBox.Show ("First player, please type an X in a square", "Tic-Tac-Toe", MessageBoxButto ns.OK)
End Sub
Private Sub TextBox1_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox1.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox1.Text = "X"
Else
TextBox1.Text = "O"
End If
End Sub
Private Sub TextBox2_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox2.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox2.Text = "X"
Else
TextBox2.Text = "O"
End If
End Sub
Private Sub TextBox3_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox3.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox3.Text = "X"
Else
TextBox3.Text = "O"
End If
End Sub
Private Sub TextBox4_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox4.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox4.Text = "X"
Else
TextBox4.Text = "O"
End If
End Sub
Private Sub TextBox5_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox5.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox5.Text = "X"
Else
TextBox5.Text = "O"
End If
End Sub
Private Sub TextBox6_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox6.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox6.Text = "X"
Else
TextBox6.Text = "O"
End If
End Sub
Private Sub TextBox7_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox7.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox7.Text = "X"
Else
TextBox7.Text = "O"
End If
End Sub
Private Sub TextBox8_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox8.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox8.Text = "X"
Else
TextBox8.Text = "O"
End If
End Sub
Private Sub TextBox9_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox9.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox9.Text = "X"
Else
TextBox9.Text = "O"
End If
End Sub
End Class[/code]
[code=vbnet]
Public Class Form1
Public player1 As Boolean
'start button starts game and sets first player as X's
Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles startbutton.Cli ck
Dim firstplayer As Char
Dim secondplayer As Char
Dim x As Char
Dim O As Char
firstplayer = x
secondplayer = O
Dim board(2, 2) As Integer
MessageBox.Show ("First player, please type an X in a square", "Tic-Tac-Toe", MessageBoxButto ns.OK)
End Sub
Private Sub TextBox1_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox1.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox1.Text = "X"
Else
TextBox1.Text = "O"
End If
End Sub
Private Sub TextBox2_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox2.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox2.Text = "X"
Else
TextBox2.Text = "O"
End If
End Sub
Private Sub TextBox3_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox3.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox3.Text = "X"
Else
TextBox3.Text = "O"
End If
End Sub
Private Sub TextBox4_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox4.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox4.Text = "X"
Else
TextBox4.Text = "O"
End If
End Sub
Private Sub TextBox5_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox5.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox5.Text = "X"
Else
TextBox5.Text = "O"
End If
End Sub
Private Sub TextBox6_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox6.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox6.Text = "X"
Else
TextBox6.Text = "O"
End If
End Sub
Private Sub TextBox7_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox7.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox7.Text = "X"
Else
TextBox7.Text = "O"
End If
End Sub
Private Sub TextBox8_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox8.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox8.Text = "X"
Else
TextBox8.Text = "O"
End If
End Sub
Private Sub TextBox9_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox9.Click
Dim y As String
y = Checkwin()
player1 = Not player1
If player1 = True Then
TextBox9.Text = "X"
Else
TextBox9.Text = "O"
End If
End Sub
End Class[/code]
Comment