Public Class Form3
Private intzet As Integer = 0
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
Button1.Text = ""
Button1.Enabled = True
Button2.Text = ""
Button2.Enabled = True
Button3.Text = ""
Button3.Enabled = True
Button4.Text = ""
Button4.Enabled = True
Button5.Text = ""
Button5.Enabled = True
Button6.Text = ""
Button6.Enabled = True
Button7.Text = ""
Button7.Enabled = True
Button8.Text = ""
Button8.Enabled = True
Button9.Text = ""
Button9.Enabled = True
intzet = 0
End Sub
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Text = ""
Button1.Enabled = True
Button2.Text = ""
Button2.Enabled = True
Button3.Text = ""
Button3.Enabled = True
Button4.Text = ""
Button4.Enabled = True
Button5.Text = ""
Button5.Enabled = True
Button6.Text = ""
Button6.Enabled = True
Button7.Text = ""
Button7.Enabled = True
Button8.Text = ""
Button8.Enabled = True
Button9.Text = ""
Button9.Enabled = True
intzet = 0
End Sub
Sub computerplays()
Dim objRandom As New Random
Dim intRandom As Integer
intRandom = Integer.Parse(objRandom.Next(1, 9))
If intRandom = 1 And Button1.Enabled = True Then
Button1.Text = "0"
Button1.Enabled = False
Exit Sub
Else
intRandom = Integer.Parse(objRandom.Next(2, 9))
End If
If intRandom = 2 And Button2.Enabled = True Then
Button2.Text = "0"
Button2.Enabled = False
Exit Sub
Else
intRandom = Integer.Parse(objRandom.Next(3, 9))
End If
If intRandom = 3 And Button3.Enabled = True Then
Button3.Text = "0"
Button3.Enabled = False
Exit Sub
Else
intRandom = Integer.Parse(objRandom.Next(4, 9))
End If
If intRandom = 4 And Button4.Enabled = True Then
Button4.Text = "0"
Button4.Enabled = False
Exit Sub
Else
intRandom = Integer.Parse(objRandom.Next(5, 9))
End If
If intRandom = 5 And Button5.Enabled = True Then
Button5.Text = "0"
Button5.Enabled = False
Exit Sub
Else
intRandom = Integer.Parse(objRandom.Next(6, 9))
End If
If intRandom = 6 And Button6.Enabled = True Then
Button6.Text = "0"
Button6.Enabled = False
Exit Sub
Else
intRandom = Integer.Parse(objRandom.Next(7, 9))
End If
If intRandom = 7 And Button7.Enabled = True Then
Button7.Text = "0"
Button7.Enabled = False
Exit Sub
Else
intRandom = Integer.Parse(objRandom.Next(8, 9))
End If
If intRandom = 8 And Button8.Enabled = True Then
Button8.Text = "0"
Button8.Enabled = False
Exit Sub
Else
intRandom = Integer.Parse(objRandom.Next(1, 7))
End If
If intRandom = 9 And Button9.Enabled = True Then
Button9.Text = "0"
Button9.Enabled = False
Exit Sub
Else
intRandom = Integer.Parse(objRandom.Next(1, 8))
End If
computerplays()
End Sub
Private Sub Youplays(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click
sender.text = "X"
sender.enabled = False
intzet = 1
CheckWinner()
computerplays()
intzet = 1
End Sub
Sub CheckWinner()
If intzet >= 5 Then
If MessageBox.Show("Ничья!") = vbOK Then
Me.Close()
Form1.Show()
End If
ElseIf Button1.Text = "O" And Button2.Text = "O" And Button3.Text = "O" _
Or Button4.Text = "O" And Button5.Text = "O" And Button6.Text = "O" _
Or Button7.Text = "O" And Button8.Text = "O" And Button9.Text = "O" _
Or Button1.Text = "O" And Button4.Text = "O" And Button7.Text = "O" _
Or Button2.Text = "O" And Button5.Text = "O" And Button8.Text = "O" _
Or Button3.Text = "O" And Button6.Text = "O" And Button9.Text = "O" _
Or Button1.Text = "O" And Button5.Text = "O" And Button9.Text = "O" _
Or Button7.Text = "O" And Button5.Text = "O" And Button3.Text = "O" Then
If MessageBox.Show("Компьютер победил") = vbOK Then
Me.Close()
Form1.Show()
End If
ElseIf Button1.Text = "X" And Button2.Text = "X" And Button3.Text = "X" _
Or Button4.Text = "X" And Button5.Text = "X" And Button6.Text = "X" _
Or Button7.Text = "X" And Button8.Text = "X" And Button9.Text = "X" _
Or 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" _
Or Button1.Text = "X" And Button5.Text = "X" And Button9.Text = "X" _
Or Button7.Text = "X" And Button5.Text = "X" And Button3.Text = "X" Then
If MessageBox.Show("игрок победил") = vbOK Then
Me.Close()
Form1.Show()
End If
End If
End Sub
End Class