|
Newbie
Join Date: Sep 2005
Posts: 7
Rep Power: 0 
|
Yea, I had a problem in the code were it was doing the incorrect function after clicking the button, but I finally got it right after several tries last night and after I found the error LOL.
Here's the final code:
Public Class Form1
Dim turn As Integer = 2
Dim mat(2, 2) As String
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub checkdraw()
Dim returnval As Boolean
Dim drawarray(2, 2) As Boolean
Dim i As Integer
Dim j As Integer
For i = 0 To 2
For j = 0 To 2
If mat(i, j) = "" Then
returnval = False
drawarray(i, j) = returnval
Else
returnval = True
drawarray(i, j) = returnval
End If
Next
Next
If drawarray(0, 0) = True And drawarray(1, 0) = True And drawarray(2, 0) = True And drawarray(0, 1) = True And drawarray(1, 1) = True And drawarray(2, 1) = True And drawarray(0, 2) = True And drawarray(1, 2) = True And drawarray(2, 2) = True Then
MsgBox("Empate")
MsgBox("Gracias por jugar")
Me.Close()
End If
'If String.IsNullOrEmpty(mat(0, 0)) = returnval Then
'Dim i As Integer
'Dim j As Integer
'For i = 0 To 2
' For j = 0 To 2
' returnValue = String.IsNullOrEmpty(mat(i, j))
' Next
'Next
'If mat(0, 0) = Not "" And mat(0, 1) = Not "" And mat(0, 2) = Not "" And mat(1, 0) = Not "" And mat(1, 1) = Not "" And mat(1, 2) = Not "" And mat(2, 0) = Not "" And mat(2, 1) = Not "" And mat(2, 2) = Not "" Then
' MsgBox("Empate")
'End If
'if (mat(0,0) = "X" or if mat (0,0) = "O") and (mat(1,0) = "X" or if mat (1,0) = "O") and (mat(2,0) = "X" or if mat (2,0) = "O") and (mat(0,1) = "X" or if mat (0,1) = "O") and (mat(0,2) = "X" or if mat (0,2) = "O") and (mat(0,0) = "X" or if mat (2,0) = "O") and (mat(2,0) = "X" or if mat (2,0) = "O") and (mat(2,2) = "X" or if mat (2,2) = "O") and (mat(1,1) = "X" or if mat (1,1) = "O")
'End If
'Dim i As Integer
'Dim j As Integer
'For i = 0 To 2
' For j = 0 To 2
' If mat(i, j) = "X" And mat(i, j) = "O" Then
' MsgBox("Empate :(")
' End If
' Next
'Next
End Sub
Private Sub checkx()
If mat(0, 0) = "X" And mat(0, 1) = "X" And mat(0, 2) = "X" Then
MsgBox("Jugador 1 Gana")
MsgBox("Gracias por jugar")
Me.Close()
End If
If mat(1, 0) = "X" And mat(1, 1) = "X" And mat(1, 2) = "X" Then
MsgBox("Jugador 1 Gana")
MsgBox("Gracias por jugar")
Me.Close()
End If
If mat(2, 0) = "X" And mat(2, 1) = "X" And mat(2, 2) = "X" Then
MsgBox("Jugador 1 Gana")
MsgBox("Gracias por jugar")
Me.Close()
End If
If mat(0, 0) = "X" And mat(1, 0) = "X" And mat(2, 0) = "X" Then
MsgBox("Jugador 1 Gana")
MsgBox("Gracias por jugar")
Me.Close()
End If
If mat(0, 1) = "X" And mat(1, 1) = "X" And mat(2, 1) = "X" Then
MsgBox("Jugador 1 Gana")
MsgBox("Gracias por jugar")
Me.Close()
End If
If mat(0, 2) = "X" And mat(1, 2) = "X" And mat(2, 2) = "X" Then
MsgBox("Jugador 1 Gana")
MsgBox("Gracias por jugar")
Me.Close()
End If
If mat(0, 0) = "X" And mat(1, 1) = "X" And mat(2, 2) = "X" Then
MsgBox("Jugador 1 Gana")
MsgBox("Gracias por jugar")
Me.Close()
End If
If mat(0, 2) = "X" And mat(1, 1) = "X" And mat(2, 0) = "X" Then
MsgBox("Jugador 1 Gana")
MsgBox("Gracias por jugar")
Me.Close()
End If
End Sub
Private Sub checko()
If mat(0, 0) = "O" And mat(0, 1) = "O" And mat(0, 2) = "O" Then
MsgBox("Jugador 2 Gana")
MsgBox("Gracias por jugar")
Me.Close()
End If
If mat(1, 0) = "O" And mat(1, 1) = "O" And mat(1, 2) = "O" Then
MsgBox("Jugador 2 Gana")
MsgBox("Gracias por jugar")
Me.Close()
End If
If mat(2, 0) = "O" And mat(2, 1) = "O" And mat(2, 2) = "O" Then
MsgBox("Jugador 2 Gana")
MsgBox("Gracias por jugar")
Me.Close()
End If
If mat(0, 0) = "O" And mat(1, 0) = "O" And mat(2, 0) = "O" Then
MsgBox("Jugador 2 Gana")
MsgBox("Gracias por jugar")
Me.Close()
End If
If mat(0, 1) = "O" And mat(1, 1) = "O" And mat(2, 1) = "O" Then
MsgBox("Jugador 2 Gana")
MsgBox("Gracias por jugar")
Me.Close()
End If
If mat(0, 2) = "O" And mat(1, 2) = "O" And mat(2, 2) = "O" Then
MsgBox("Jugador 2 Gana")
MsgBox("Gracias por jugar")
Me.Close()
End If
If mat(0, 0) = "O" And mat(1, 1) = "O" And mat(2, 2) = "O" Then
MsgBox("Jugador 2 Gana")
MsgBox("Gracias por jugar")
Me.Close()
End If
If mat(0, 2) = "O" And mat(1, 1) = "O" And mat(2, 0) = "O" Then
MsgBox("Jugador 2 Gana")
MsgBox("Gracias por jugar")
Me.Close()
End If
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 = "O"
turn = 1
mat(0, 0) = "O"
Else
b00.Text = "X"
turn = 0
mat(0, 0) = "X"
End If
b00.Enabled = False
checkx()
checko()
checkdraw()
'If mat(0, 1) And mat(0, 2) = mat(0, 0) Then
' MsgBox("You Win!")
'Else
' If mat(1, 0) And mat(2, 0) = mat(0, 0) Then
' MsgBox("You Win!")
' Else
' If mat(1, 1) And 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) = "O"
Else
b01.Text = "X"
turn = 0
mat(0, 1) = "X"
End If
b01.Enabled = False
checkx()
checko()
checkdraw()
'If mat(0, 2) And mat(0, 0) = mat(0, 1) Then
' MsgBox("You Win!")
'Else
' If mat(1, 1) And 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) = "O"
Else
b02.Text = "X"
turn = 0
mat(0, 2) = "X"
End If
b02.Enabled = False
checkx()
checko()
checkdraw()
'If mat(0, 0) And mat(0, 1) = mat(0, 2) Then
' MsgBox("You Win!")
'Else
' If mat(1, 2) And mat(2, 2) = mat(0, 2) Then
' MsgBox("You Win!")
' Else
' If mat(1, 1) And 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) = "O"
Else
b10.Text = "X"
turn = 0
mat(1, 0) = "X"
End If
b10.Enabled = False
checkx()
checko()
checkdraw()
'If mat(0, 0) And mat(2, 0) = mat(1, 0) Then
' MsgBox("You Win!")
'Else
' If mat(1, 1) And 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) = "O"
Else
b11.Text = "X"
turn = 0
mat(1, 1) = "X"
End If
b11.Enabled = False
checkx()
checko()
checkdraw()
'If mat(0, 1) And mat(2, 1) = mat(1, 1) Then
' MsgBox("You Win!")
'Else
' If mat(1, 0) And 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) = "O"
Else
b12.Text = "X"
turn = 0
mat(1, 2) = "X"
End If
b12.Enabled = False
checkx()
checko()
checkdraw()
'If mat(1, 0) And mat(1, 1) = mat(1, 2) Then
' MsgBox("You Win!")
'Else
' If mat(0, 2) And 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) = "O"
Else
b20.Text = "X"
turn = 0
mat(2, 0) = "X"
End If
b20.Enabled = False
checkx()
checko()
checkdraw()
'If mat(0, 0) And mat(1, 0) = mat(2, 0) Then
' MsgBox("You Win!")
'Else
' If mat(2, 1) And mat(2, 2) = mat(2, 0) Then
' MsgBox("You Win!")
' Else
' If mat(1, 1) And 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) = "O"
Else
b21.Text = "X"
turn = 0
mat(2, 1) = "X"
End If
b21.Enabled = False
checkx()
checko()
checkdraw()
'If mat(0, 1) And mat(1, 1) = mat(2, 1) Then
' MsgBox("You Win!")
'Else
' If mat(2, 0) And 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) = "O"
Else
b22.Text = "X"
turn = 0
mat(2, 2) = "X"
End If
b22.Enabled = False
checkx()
checko()
checkdraw()
'If mat(0, 0) And mat(1, 1) = mat(2, 2) Then
' MsgBox("You Win!")
'Else
' If mat(2, 0) And mat(2, 1) = mat(2, 2) Then
' MsgBox("You Win!")
' Else
' If mat(0, 2) And mat(1, 2) = mat(2, 2) Then
' MsgBox("You Win!")
' End If
' End If
'End If
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
End Class
|