I think I'm having some problems with my private sub win()
This is my code broken down:
Declaring Variables
Code:Public Class Form2 'Sets the score, initially set at 0 'For both x and 0 Dim x As Integer = 0 Dim o As Integer = 0
My win sub
Button for x's and o's I have 9 of themCode:Private Sub win() 'Possible wins 'horizontal 123 465 789 'vertical 147 258 369 'Diagonal 159 357 If Button1.Text = "X" And Button2.Text = "X" And Button3.Text = "X" Or Button4.Text = "X" And Button6.Text = "X" And Button5.Text = "X" Or Button7.Text = "X" And Button8.Text = "X" And Button9.Text = "X" Then MsgBox("X Wins!") x = x + 1 Label1.Text = x Button11.PerformClick() End If If Button1.Text = "X" And Button4.Text = "X" And Button7.Text = "X" Or Button2.Text = "X" And Button5.Text = "X" And Button8.Text = "X" Or Button3.Text = "X" And Button6.Text = "X" And Button9.Text = "X" Then MsgBox("X Wins!") x = x + 1 Label1.Text = x End If If Button1.Text = "X" And Button5.Text = "X" And Button9.Text = "X" Or Button3.Text = "X" And Button5.Text = "X" And Button7.Text = "X" Then MsgBox("X Wins!") x = x + 1 Label1.Text = x Button11.PerformClick() End If If Button1.Text = "0" And Button2.Text = "0" And Button3.Text = "0" Or Button4.Text = "0" And Button6.Text = "0" And Button5.Text = "0" Or Button7.Text = "0" And Button8.Text = "0" And Button9.Text = "0" Then MsgBox("0 Wins!") o = o + 1 Label1.Text = o Button11.PerformClick() End If If Button1.Text = "0" And Button4.Text = "0" And Button7.Text = "0" Or Button2.Text = "0" And Button5.Text = "0" And Button8.Text = "0" Or Button3.Text = "0" And Button6.Text = "0" And Button9.Text = "0" Then MsgBox("0 Wins!") o = o + 1 Label1.Text = o Button11.PerformClick() End If If Button1.Text = "0" And Button5.Text = "0" And Button9.Text = "0" Or Button3.Text = "0" And Button5.Text = "0" And Button7.Text = "0" Then MsgBox("0 Wins!") o = o + 1 Label1.Text = o Button11.PerformClick() End If End Sub
I have a seperate label that starts as .text = 0 so that x will start any time a button is clicked it changes the .text to = x and Vis-Versa.Code:Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'Sets the button's text to x or 0 If Label6.Text = "0" Then Button2.Text = "X" Label6.Text = "X" Else : Label6.Text = "X" Button2.Text = "0" Label6.Text = "0" End If Button2.Enabled = False Call win() End Sub
x and 0's score
Score ResetCode:Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click 'Shows the score for x Label4.Text = x End Sub Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click 'Shows the score for 0 Label5.Text = o End Sub
Game ResetCode:Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click 'Resets the score back to 0 x = 0 o = 0 'Resets current game so people can't cheat Button11.PerformClick() End Sub
I think its my win sub. But when the game is over, it doesn't change my score, msgbox doesn't come up and the game isn't reset. What up with that?Code:Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click 'Resets the game w/o reseting the score Button2.Enabled = True Button3.Enabled = True Button4.Enabled = True Button5.Enabled = True Button6.Enabled = True Button7.Enabled = True Button8.Enabled = True Button9.Enabled = True Button10.Enabled = True Button2.Text = "" Button3.Text = "" Button4.Text = "" Button5.Text = "" Button6.Text = "" Button7.Text = "" Button8.Text = "" Button9.Text = "" Button10.Text = "" End Sub




Reply With Quote