Hey guys , well i have the Tic Tac Toe project , i wrote some codes, but i don't know why isn't working . Hopefully you can help me
my project contain 9 labels , 2 texboxs ( first player , second player ) , button ( new game ), 2 radio buttons ( human vs human ) and ( human vs computer)
my code that i wrote is like that :
Public Class Form1
Dim isFirstPlayerTurn As Boolean = True
Dim isSecondPlayerTurn As Boolean = False
Dim isPlayerWon As Boolean = False
Function placeplayermark() As Char
If isFirstPlayerTurn = True Then
Return "X"
ElseIf isSecondPlayerTurn = True Then
Return "O"
End If
End Function
Sub setplayerturn()
If isFirstPlayerTurn = True Then
isFirstPlayerTurn = False
isSecondPlayerTurn = False
txtfirstplayer.BackColor = Color.LightGreen
txtsecondplayer.BackColor = Color.White
ElseIf isSecondPlayerTurn = True Then
isSecondPlayerTurn = False
isFirstPlayerTurn = False
txtsecondplayer.BackColor = Color.LightGreen
txtfirstplayer.BackColor = Color.White
End If
End Sub
Sub resetvalues()
lblbox1.Text = " "
lblbox1.ForeColor = Color.Black
lblbox1.BackColor = Color.Transparent
txtfirstplayer.BackColor = Color.White
lblbox2.Text = " "
lblbox2.ForeColor = Color.Black
lblbox2.BackColor = Color.Transparent
txtfirstplayer.BackColor = Color.White
lblbox3.Text = " "
lblbox3.ForeColor = Color.Black
lblbox3.BackColor = Color.Transparent
txtfirstplayer.BackColor = Color.White
lblbox4.Text = " "
lblbox4.ForeColor = Color.Black
lblbox4.BackColor = Color.Transparent
txtfirstplayer.BackColor = Color.White
lblbox5.Text = " "
lblbox5.ForeColor = Color.Black
lblbox5.BackColor = Color.Transparent
txtfirstplayer.BackColor = Color.White
lblbox6.Text = " "
lblbox6.ForeColor = Color.Black
lblbox6.BackColor = Color.Transparent
txtfirstplayer.BackColor = Color.White
lblbox7.Text = " "
lblbox7.ForeColor = Color.Black
lblbox7.BackColor = Color.Transparent
txtfirstplayer.BackColor = Color.White
lblbox8.Text = " "
lblbox8.ForeColor = Color.Black
lblbox8.BackColor = Color.Transparent
txtfirstplayer.BackColor = Color.White
lblbox9.Text = " "
lblbox9.ForeColor = Color.Black
lblbox9.BackColor = Color.Transparent
txtfirstplayer.BackColor = Color.White
End Sub
Sub iswon()
If lblbox1.Text = lblbox2.Text And lblbox2.Text = lblbox3.Text And lblbox1.Text <> lblbox2.Text Then
lblbox1.ForeColor = Color.Red
lblbox2.ForeColor = Color.Red
lblbox3.ForeColor = Color.Red
lblbox1.BackColor = Color.Yellow
lblbox2.BackColor = Color.Yellow
lblbox3.BackColor = Color.Yellow
ElseIf lblbox4.Text = lblbox5.Text And lblbox5.Text = lblbox6.Text And lblbox4.Text <> lblbox5.Text Then
lblbox4.ForeColor = Color.Red
lblbox5.ForeColor = Color.Red
lblbox6.ForeColor = Color.Red
lblbox4.BackColor = Color.Yellow
lblbox5.BackColor = Color.Yellow
lblbox6.BackColor = Color.Yellow
ElseIf lblbox7.Text = lblbox8.Text And lblbox8.Text = lblbox9.Text And lblbox7.Text <> lblbox8.Text Then
lblbox7.ForeColor = Color.Red
lblbox8.ForeColor = Color.Red
lblbox9.ForeColor = Color.Red
lblbox7.BackColor = Color.Yellow
lblbox8.BackColor = Color.Yellow
lblbox9.BackColor = Color.Yellow
ElseIf lblbox1.Text = lblbox4.Text And lblbox4.Text = lblbox7.Text And lblbox1.Text <> lblbox3.Text Then
lblbox1.ForeColor = Color.Red
lblbox4.ForeColor = Color.Red
lblbox7.ForeColor = Color.Red
lblbox1.BackColor = Color.Yellow
lblbox4.BackColor = Color.Yellow
lblbox7.BackColor = Color.Yellow
ElseIf lblbox2.Text = lblbox5.Text And lblbox5.Text = lblbox8.Text And lblbox2.Text <> lblbox5.Text Then
lblbox2.ForeColor = Color.Red
lblbox5.ForeColor = Color.Red
lblbox8.ForeColor = Color.Red
lblbox2.BackColor = Color.Yellow
lblbox5.BackColor = Color.Yellow
lblbox8.BackColor = Color.Yellow
ElseIf lblbox3.Text = lblbox6.Text And lblbox6.Text = lblbox9.Text And lblbox3.Text <> lblbox6.Text Then
lblbox3.ForeColor = Color.Red
lblbox6.ForeColor = Color.Red
lblbox9.ForeColor = Color.Red
lblbox3.BackColor = Color.Yellow
lblbox6.BackColor = Color.Yellow
lblbox9.BackColor = Color.Yellow
ElseIf lblbox1.Text = lblbox5.Text And lblbox5.Text = lblbox9.Text And lblbox1.Text <> lblbox5.Text Then
lblbox1.ForeColor = Color.Red
lblbox5.ForeColor = Color.Red
lblbox9.ForeColor = Color.Red
lblbox1.BackColor = Color.Yellow
lblbox5.BackColor = Color.Yellow
lblbox9.BackColor = Color.Yellow
ElseIf lblbox3.Text = lblbox5.Text And lblbox5.Text = lblbox7.Text And lblbox3.Text <> lblbox5.Text Then
lblbox3.ForeColor = Color.Red
lblbox5.ForeColor = Color.Red
lblbox7.ForeColor = Color.Red
lblbox3.BackColor = Color.Yellow
lblbox5.BackColor = Color.Yellow
lblbox7.BackColor = Color.Yellow
MessageBox.Show("player", "Player Won", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf lblbox1.Text = lblbox2.Text Or lblbox2.Text = lblbox3.Text Or lblbox3.Text = lblbox4.Text Or lblbox4.Text = lblbox5.Text Or lblbox5.Text = lblbox6.Text Or lblbox6.Text = lblbox7.Text Or lblbox7.Text = lblbox8.Text Or lblbox8.Text = lblbox9.Text Then
MessageBox.Show("it is a tie ", "tie", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub btnnewgame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnewgame.Click
MessageBox.Show("Play a new game?", "New Game", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
resetvalues()
End Sub
Private Sub Radhumanvshuman_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Radhumanvshuman.CheckedChanged
placeplayermark()
setplayerturn()
iswon()
End Sub
End Class
but there is something missing and i don't know why isn't working , so hopefully you can help me , thank you .