|
Newbie
Join Date: Sep 2005
Posts: 7
Rep Power: 0 
|
Actually yes, I do what variables and arrays are.
I already did what you mentioned, about using button.enable = false
after it's clicked.
Now I'm trying to actually do all the checks, but it's not working that well, it randomly (I think), tells me the game is over
Check it out
Public Class Form1
Dim turn As Integer
Dim mat(2, 2) As Integer
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub b00_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b00.Click
If turn = 0 Then
b00.Text = "X"
turn = 0
mat(0, 0) = 0
Else
b00.Text = "O"
turn = 1
mat(0, 0) = 1
End If
b00.Enabled = False
If mat(0, 1) & mat(0, 2) = mat(0, 0) Then
MsgBox("You Win!")
Else
If mat(1, 0) & mat(2, 0) = mat(0, 0) Then
MsgBox("You Win!")
Else
If mat(1, 1) & mat(2, 2) = mat(0, 0) Then
MsgBox("You Win!")
End If
End If
End If
End Sub
Private Sub b01_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b01.Click
If turn = 0 Then
b01.Text = "O"
turn = 1
mat(0, 1) = 1
Else
b01.Text = "X"
turn = 0
mat(0, 1) = 0
End If
b01.Enabled = False
If mat(0, 2) & mat(0, 0) = mat(0, 1) Then
MsgBox("You Win!")
Else
If mat(1, 1) & mat(2, 1) = mat(0, 1) Then
MsgBox("You Win!")
End If
End If
End Sub
Private Sub b02_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b02.Click
If turn = 0 Then
b02.Text = "O"
turn = 1
mat(0, 2) = 1
Else
b02.Text = "X"
turn = 0
mat(0, 2) = 0
End If
b02.Enabled = False
If mat(0, 0) & mat(0, 1) = mat(0, 2) Then
MsgBox("You Win!")
Else
If mat(1, 2) & mat(2, 2) = mat(0, 2) Then
MsgBox("You Win!")
Else
If mat(1, 1) & mat(2, 0) = mat(0, 2) Then
MsgBox("You Win!")
End If
End If
End If
End Sub
Private Sub b10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b10.Click
If turn = 0 Then
b10.Text = "O"
turn = 1
mat(1, 0) = 1
Else
b10.Text = "X"
turn = 0
mat(1, 0) = 0
End If
b10.Enabled = False
If mat(0, 0) & mat(2, 0) = mat(1, 0) Then
MsgBox("You Win!")
Else
If mat(1, 1) & mat(1, 2) = mat(1, 0) Then
MsgBox("You Win!")
End If
End If
End Sub
Private Sub b11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b11.Click
If turn = 0 Then
b11.Text = "O"
turn = 1
mat(1, 1) = 1
Else
b11.Text = "X"
turn = 0
mat(1, 1) = 0
End If
b11.Enabled = False
If mat(0, 1) & mat(2, 1) = mat(1, 1) Then
MsgBox("You Win!")
Else
If mat(1, 0) & mat(1, 2) = mat(1, 1) Then
MsgBox("You Win!")
End If
End If
End Sub
Private Sub b12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b12.Click
If turn = 0 Then
b12.Text = "O"
turn = 1
mat(1, 2) = 1
Else
b12.Text = "X"
turn = 0
mat(1, 2) = 0
End If
b12.Enabled = False
If mat(1, 0) & mat(1, 1) = mat(1, 2) Then
MsgBox("You Win!")
Else
If mat(0, 2) & mat(2, 2) = mat(1, 2) Then
MsgBox("You Win!")
End If
End If
End Sub
Private Sub b20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b20.Click
If turn = 0 Then
b20.Text = "O"
turn = 1
mat(2, 0) = 1
Else
b20.Text = "X"
turn = 0
mat(2, 0) = 0
End If
b20.Enabled = False
If mat(0, 0) & mat(1, 0) = mat(2, 0) Then
MsgBox("You Win!")
Else
If mat(2, 1) & mat(2, 2) = mat(2, 0) Then
MsgBox("You Win!")
Else
If mat(1, 1) & mat(0, 2) = mat(2, 0) Then
MsgBox("You Win!")
End If
End If
End If
End Sub
Private Sub b21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b21.Click
If turn = 0 Then
b21.Text = "O"
turn = 1
mat(2, 1) = 1
Else
b21.Text = "X"
turn = 0
mat(2, 1) = 0
End If
b21.Enabled = False
If mat(0, 1) & mat(1, 1) = mat(2, 1) Then
MsgBox("You Win!")
Else
If mat(2, 0) & mat(2, 2) = mat(2, 1) Then
MsgBox("You Win!")
End If
End If
End Sub
Private Sub b22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b22.Click
If turn = 0 Then
b22.Text = "O"
turn = 1
mat(2, 2) = 1
Else
b22.Text = "X"
turn = 0
mat(2, 2) = 0
End If
b22.Enabled = False
If mat(0, 0) & mat(1, 1) = mat(2, 2) Then
MsgBox("You Win!")
Else
If mat(2, 0) & mat(2, 1) = mat(2, 2) Then
MsgBox("You Win!")
Else
If mat(0, 2) & mat(1, 2) = mat(2, 2) Then
MsgBox("You Win!")
End If
End If
End If
End Sub
End Class
Any ideas? Thanks
Also, how do you stop the program after it displays the "You win!" message?
|