I am a newb in visual basic and my teacher asked me to make a nougats and crosses game and that works flawlessly, since I finished my half term homework so early I decided to make an AI for my game, just to show what I was capable of. After spending more than 4 days at it I have finally come to ask you the forum for help.
The computer code works well when it can attack (if there is 2 crosses in line then it know where to put the next cross)
If can also defend (if there is 2 nougats in line then it know where to put the next cross)
But the problem starts when it can neither attack or defend, then it goes all buggy and glitchy
I have tried to fix this problem by adding a random function(it randomly chooses where to put the next cross) but it doesn't seem to be helping. I have attached the program but if it doesnt work here is the mirror link
https://rapidshare.c...and-Crosses.exe
Any suggestion, hints or answer will be greatly appreciated.
The computer code works well when it can attack (if there is 2 crosses in line then it know where to put the next cross)
If can also defend (if there is 2 nougats in line then it know where to put the next cross)
But the problem starts when it can neither attack or defend, then it goes all buggy and glitchy
I have tried to fix this problem by adding a random function(it randomly chooses where to put the next cross) but it doesn't seem to be helping. I have attached the program but if it doesnt work here is the mirror link
https://rapidshare.c...and-Crosses.exe
Any suggestion, hints or answer will be greatly appreciated.
VB.NET:
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim p1 As String
p1 = InputBox("Please enter the name for Player1, if you want the game to look aesthetically pleasing then please do not exceed more than 10 characters", "Player1Name", )
If p1 = "" Then Player1.Text = "Player1" Else Player1.Text = p1
If p1 = "" Then TextBox1.Text = "Player1" & "'s turn" Else TextBox1.Text = p1 & "'s turn"
End Sub
Private Sub attack()
If Label1.Text = "X" And Label2.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label3.Text = " " Then Label3.Text = "X"
If Label1.Text = "X" And Label2.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label1.Text = "X" And Label2.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label3.Text = "X" Then Exit Sub
If Label3.Text = "X" And Label2.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label1.Text = " " Then Label1.Text = "X"
If Label3.Text = "X" And Label2.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label3.Text = "X" And Label2.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label1.Text = "X" Then Exit Sub
If Label1.Text = "X" And Label3.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label2.Text = " " Then Label2.Text = "X"
If Label1.Text = "X" And Label3.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label1.Text = "X" And Label3.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label2.Text = "X" Then Exit Sub
If Label4.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label6.Text = " " Then Label6.Text = "X"
If Label4.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label4.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label6.Text = "X" Then Exit Sub
If Label6.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label4.Text = " " Then Label4.Text = "X"
If Label6.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label6.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label4.Text = "X" Then Exit Sub
If Label4.Text = "X" And Label6.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label5.Text = " " Then Label5.Text = "X"
If Label4.Text = "X" And Label6.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label4.Text = "X" And Label6.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label5.Text = "X" Then Exit Sub
If Label7.Text = "X" And Label8.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label9.Text = " " Then Label9.Text = "X"
If Label7.Text = "X" And Label8.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label7.Text = "X" And Label8.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label9.Text = "X" Then Exit Sub
If Label9.Text = "X" And Label8.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label7.Text = " " Then Label7.Text = "X"
If Label9.Text = "X" And Label8.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label9.Text = "X" And Label8.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label7.Text = "X" Then Exit Sub
If Label7.Text = "X" And Label9.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label8.Text = " " Then Label8.Text = "X"
If Label7.Text = "X" And Label9.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label7.Text = "X" And Label9.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label8.Text = "X" Then Exit Sub
If Label1.Text = "X" And Label4.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label7.Text = " " Then Label7.Text = "X"
If Label1.Text = "X" And Label4.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label1.Text = "X" And Label4.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label7.Text = "X" Then Exit Sub
If Label7.Text = "X" And Label4.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label1.Text = " " Then Label1.Text = "X"
If Label7.Text = "X" And Label4.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label7.Text = "X" And Label4.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label1.Text = "X" Then Exit Sub
If Label1.Text = "X" And Label7.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label4.Text = " " Then Label4.Text = "X"
If Label1.Text = "X" And Label7.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label1.Text = "X" And Label7.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label4.Text = "X" Then Exit Sub
If Label2.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label8.Text = " " Then Label8.Text = "X"
If Label2.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label2.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label8.Text = "X" Then Exit Sub
If Label8.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label2.Text = " " Then Label2.Text = "X"
If Label8.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label8.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label2.Text = "X" Then Exit Sub
If Label2.Text = "X" And Label8.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label5.Text = " " Then Label5.Text = "X"
If Label2.Text = "X" And Label8.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label2.Text = "X" And Label8.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label5.Text = "X" Then Exit Sub
If Label3.Text = "X" And Label6.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label9.Text = " " Then Label9.Text = "X"
If Label3.Text = "X" And Label6.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label3.Text = "X" And Label6.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label9.Text = "X" Then Exit Sub
If Label9.Text = "X" And Label6.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label3.Text = " " Then Label3.Text = "X"
If Label9.Text = "X" And Label6.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label9.Text = "X" And Label6.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label3.Text = "X" Then Exit Sub
If Label3.Text = "X" And Label9.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label6.Text = " " Then Label6.Text = "X"
If Label3.Text = "X" And Label9.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label3.Text = "X" And Label9.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label6.Text = "X" Then Exit Sub
If Label1.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label9.Text = " " Then Label9.Text = "X"
If Label1.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label1.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label9.Text = "X" Then Exit Sub
If Label9.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label1.Text = " " Then Label1.Text = "X"
If Label9.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label9.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label1.Text = "X" Then Exit Sub
If Label1.Text = "X" And Label9.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label5.Text = " " Then Label5.Text = "X"
If Label1.Text = "X" And Label9.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label1.Text = "X" And Label9.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label5.Text = "X" Then Exit Sub
If Label3.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label7.Text = " " Then Label7.Text = "X"
If Label3.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label3.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label7.Text = "X" Then Exit Sub
If Label7.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label3.Text = " " Then Label3.Text = "X"
If Label7.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label7.Text = "X" And Label5.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label3.Text = "X" Then Exit Sub
If Label3.Text = "X" And Label7.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label5.Text = " " Then Label5.Text = "X"
If Label3.Text = "X" And Label7.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label3.Text = "X" And Label7.Text = "X" And TextBox1.Text = Player2.Text & "'s turn" And Label5.Text = "X" Then Exit Sub
Call defence()
End Sub
Private Sub defence()
If Label1.Text = "O" And Label2.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label3.Text = " " Then Label3.Text = "X"
If Label1.Text = "O" And Label2.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label1.Text = "O" And Label2.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label3.Text = "O" Then Exit Sub
If Label3.Text = "O" And Label2.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label1.Text = " " Then Label1.Text = "X"
If Label3.Text = "O" And Label2.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label3.Text = "O" And Label2.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label1.Text = "O" Then Exit Sub
If Label1.Text = "O" And Label3.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label2.Text = " " Then Label2.Text = "X"
If Label1.Text = "O" And Label3.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label1.Text = "O" And Label3.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label2.Text = "O" Then Exit Sub
If Label4.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label6.Text = " " Then Label6.Text = "X"
If Label4.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label4.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label6.Text = "O" Then Exit Sub
If Label6.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label4.Text = " " Then Label4.Text = "X"
If Label6.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label6.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label4.Text = "O" Then Exit Sub
If Label4.Text = "O" And Label6.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label5.Text = " " Then Label5.Text = "X"
If Label4.Text = "O" And Label6.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label4.Text = "O" And Label6.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label5.Text = "O" Then Exit Sub
If Label7.Text = "O" And Label8.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label9.Text = " " Then Label9.Text = "X"
If Label7.Text = "O" And Label8.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label7.Text = "O" And Label8.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label9.Text = "O" Then Exit Sub
If Label9.Text = "O" And Label8.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label7.Text = " " Then Label7.Text = "X"
If Label9.Text = "O" And Label8.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label9.Text = "O" And Label8.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label7.Text = "O" Then Exit Sub
If Label7.Text = "O" And Label9.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label8.Text = " " Then Label8.Text = "X"
If Label7.Text = "O" And Label9.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label7.Text = "O" And Label9.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label8.Text = "O" Then Exit Sub
If Label1.Text = "O" And Label4.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label7.Text = " " Then Label7.Text = "X"
If Label1.Text = "O" And Label4.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label1.Text = "O" And Label4.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label7.Text = "O" Then Exit Sub
If Label7.Text = "O" And Label4.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label1.Text = " " Then Label1.Text = "X"
If Label7.Text = "O" And Label4.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label7.Text = "O" And Label4.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label1.Text = "O" Then Exit Sub
If Label1.Text = "O" And Label7.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label4.Text = " " Then Label4.Text = "X"
If Label1.Text = "O" And Label7.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label1.Text = "O" And Label7.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label4.Text = "O" Then Exit Sub
If Label2.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label8.Text = " " Then Label8.Text = "X"
If Label2.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label2.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label8.Text = "O" Then Exit Sub
If Label8.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label2.Text = " " Then Label2.Text = "X"
If Label8.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label8.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label2.Text = "O" Then Exit Sub
If Label2.Text = "O" And Label8.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label5.Text = " " Then Label5.Text = "X"
If Label2.Text = "O" And Label8.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label2.Text = "O" And Label8.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label5.Text = "O" Then Exit Sub
If Label3.Text = "O" And Label6.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label9.Text = " " Then Label9.Text = "X"
If Label3.Text = "O" And Label6.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label3.Text = "O" And Label6.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label9.Text = "O" Then Exit Sub
If Label9.Text = "O" And Label6.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label3.Text = " " Then Label3.Text = "X"
If Label9.Text = "O" And Label6.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label9.Text = "O" And Label6.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label3.Text = "O" Then Exit Sub
If Label3.Text = "O" And Label9.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label6.Text = " " Then Label6.Text = "X"
If Label3.Text = "O" And Label9.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label3.Text = "O" And Label9.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label6.Text = "O" Then Exit Sub
If Label1.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label9.Text = " " Then Label9.Text = "X"
If Label1.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label1.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label9.Text = "O" Then Exit Sub
If Label9.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label1.Text = " " Then Label1.Text = "X"
If Label9.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label9.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label1.Text = "O" Then Exit Sub
If Label1.Text = "O" And Label9.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label5.Text = " " Then Label5.Text = "X"
If Label1.Text = "O" And Label9.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label1.Text = "O" And Label9.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label5.Text = "O" Then Exit Sub
If Label3.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label7.Text = " " Then Label7.Text = "X"
If Label3.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label3.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label7.Text = "O" Then Exit Sub
If Label7.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label3.Text = " " Then Label3.Text = "X"
If Label7.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label7.Text = "O" And Label5.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label3.Text = "O" Then Exit Sub
If Label3.Text = "O" And Label7.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label5.Text = " " Then Label5.Text = "X"
If Label3.Text = "O" And Label7.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
Call win()
If Label3.Text = "O" And Label7.Text = "O" And TextBox1.Text = Player2.Text & "'s turn" And Label5.Text = "O" Then Exit Sub
Call Random()
End Sub
Private Sub win()
If Label1.Text = "O" And Label2.Text = "O" And Label3.Text = "O" Then MessageBox.Show(Player1.Text & " won", "Win")
If Label1.Text = "O" And Label2.Text = "O" And Label3.Text = "O" Then Call Owin()
If Label1.Text = "O" And Label2.Text = "O" And Label3.Text = "O" Then Call clear()
If Label4.Text = "O" And Label5.Text = "O" And Label6.Text = "O" Then Call MessageBox.Show(Player1.Text & " won", "Win")
If Label4.Text = "O" And Label5.Text = "O" And Label6.Text = "O" Then Call Owin()
If Label4.Text = "O" And Label5.Text = "O" And Label6.Text = "O" Then Call clear()
If Label7.Text = "O" And Label8.Text = "O" And Label9.Text = "O" Then MessageBox.Show(Player1.Text & " won", "Win")
If Label7.Text = "O" And Label8.Text = "O" And Label9.Text = "O" Then Call Owin()
If Label7.Text = "O" And Label8.Text = "O" And Label9.Text = "O" Then Call clear()
If Label1.Text = "O" And Label4.Text = "O" And Label7.Text = "O" Then MessageBox.Show(Player1.Text & " won", "Win")
If Label1.Text = "O" And Label4.Text = "O" And Label7.Text = "O" Then Call Owin()
If Label1.Text = "O" And Label4.Text = "O" And Label7.Text = "O" Then Call clear()
If Label2.Text = "O" And Label5.Text = "O" And Label8.Text = "O" Then MessageBox.Show(Player1.Text & " won", "Win")
If Label2.Text = "O" And Label5.Text = "O" And Label8.Text = "O" Then Call Owin()
If Label2.Text = "O" And Label5.Text = "O" And Label8.Text = "O" Then Call clear()
If Label3.Text = "O" And Label6.Text = "O" And Label9.Text = "O" Then MessageBox.Show(Player1.Text & " won", "Win")
If Label3.Text = "O" And Label6.Text = "O" And Label9.Text = "O" Then Call Owin()
If Label3.Text = "O" And Label6.Text = "O" And Label9.Text = "O" Then Call clear()
If Label1.Text = "O" And Label5.Text = "O" And Label9.Text = "O" Then MessageBox.Show(Player1.Text & " won", "Win")
If Label1.Text = "O" And Label5.Text = "O" And Label9.Text = "O" Then Call Owin()
If Label1.Text = "O" And Label5.Text = "O" And Label9.Text = "O" Then Call clear()
If Label3.Text = "O" And Label5.Text = "O" And Label7.Text = "O" Then MessageBox.Show(Player1.Text & " won", "Win")
If Label3.Text = "O" And Label5.Text = "O" And Label7.Text = "O" Then Call Owin()
If Label3.Text = "O" And Label5.Text = "O" And Label7.Text = "O" Then Call clear()
If Label1.Text = "X" And Label2.Text = "X" And Label3.Text = "X" Then MessageBox.Show(Player2.Text & " won", "Win")
If Label1.Text = "X" And Label2.Text = "X" And Label3.Text = "X" Then Call Xwin()
If Label1.Text = "X" And Label2.Text = "X" And Label3.Text = "X" Then Call clear()
If Label4.Text = "X" And Label5.Text = "X" And Label6.Text = "X" Then MessageBox.Show(Player2.Text & " won", "Win")
If Label4.Text = "X" And Label5.Text = "X" And Label6.Text = "X" Then Call Xwin()
If Label4.Text = "X" And Label5.Text = "X" And Label6.Text = "X" Then Call clear()
If Label7.Text = "X" And Label8.Text = "X" And Label9.Text = "X" Then MessageBox.Show(Player2.Text & " won", "Win")
If Label7.Text = "X" And Label8.Text = "X" And Label9.Text = "X" Then Call Xwin()
If Label7.Text = "X" And Label8.Text = "X" And Label9.Text = "X" Then Call clear()
If Label1.Text = "X" And Label4.Text = "X" And Label7.Text = "X" Then MessageBox.Show(Player2.Text & " won", "Win")
If Label1.Text = "X" And Label4.Text = "X" And Label7.Text = "X" Then Call Xwin()
If Label1.Text = "X" And Label4.Text = "X" And Label7.Text = "X" Then Call clear()
If Label2.Text = "X" And Label5.Text = "X" And Label8.Text = "X" Then MessageBox.Show(Player2.Text & " won", "Win")
If Label2.Text = "X" And Label5.Text = "X" And Label8.Text = "X" Then Call Xwin()
If Label2.Text = "X" And Label5.Text = "X" And Label8.Text = "X" Then Call clear()
If Label3.Text = "X" And Label6.Text = "X" And Label9.Text = "X" Then MessageBox.Show(Player2.Text & " won", "Win")
If Label3.Text = "X" And Label6.Text = "X" And Label9.Text = "X" Then Call Xwin()
If Label3.Text = "X" And Label6.Text = "X" And Label9.Text = "X" Then Call clear()
If Label1.Text = "X" And Label5.Text = "X" And Label9.Text = "X" Then MessageBox.Show(Player2.Text & " won", "Win")
If Label1.Text = "X" And Label5.Text = "X" And Label9.Text = "X" Then Call Xwin()
If Label1.Text = "X" And Label5.Text = "X" And Label9.Text = "X" Then Call clear()
If Label3.Text = "X" And Label5.Text = "X" And Label7.Text = "X" Then MessageBox.Show(Player2.Text & " won", "Win")
If Label3.Text = "X" And Label5.Text = "X" And Label7.Text = "X" Then Call Xwin()
If Label3.Text = "X" And Label5.Text = "X" And Label7.Text = "X" Then Call clear()
End Sub
Private Sub Owin()
score1.Text = Val(score1.Text) + 1
End Sub
Private Sub Xwin()
score2.Text = Val(score2.Text) + 1
End Sub
Private Sub random()
Dim choose As New Random
Dim number As Integer
number = choose.Next(0, 9)
Do Until TextBox1.Text = Player1.Text & "'s turn"
If number = 1 And TextBox1.Text = Player2.Text & "'s turn" And Label1.Text = " " Then Label1.Text = "X"
If number = 1 And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
If number = 1 Then Exit Sub
If number = 2 And TextBox1.Text = Player2.Text & "'s turn" And Label2.Text = " " Then Label2.Text = "X"
If number = 2 And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
If number = 2 Then Exit Sub
If number = 3 And TextBox1.Text = Player2.Text & "'s turn" And Label3.Text = " " Then Label3.Text = "X"
If number = 3 And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
If number = 3 Then Exit Sub
If number = 4 And TextBox1.Text = Player2.Text & "'s turn" And Label4.Text = " " Then Label4.Text = "X"
If number = 4 And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
If number = 4 Then Exit Sub
If number = 5 And TextBox1.Text = Player2.Text & "'s turn" And Label5.Text = " " Then Label5.Text = "X"
If number = 5 And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
If number = 5 Then Exit Sub
If number = 6 And TextBox1.Text = Player2.Text & "'s turn" And Label6.Text = " " Then Label6.Text = "X"
If number = 6 And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
If number = 6 Then Exit Sub
If number = 7 And TextBox1.Text = Player2.Text & "'s turn" And Label7.Text = " " Then Label7.Text = "X"
If number = 7 And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
If number = 7 Then Exit Sub
If number = 8 And TextBox1.Text = Player2.Text & "'s turn" And Label8.Text = " " Then Label8.Text = "X"
If number = 8 And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
If number = 8 Then Exit Sub
If number = 9 And TextBox1.Text = Player2.Text & "'s turn" And Label9.Text = " " Then Label9.Text = "X"
If number = 9 And TextBox1.Text = Player2.Text & "'s turn" Then TextBox1.Text = Player1.Text & "'s turn"
If number = 9 Then Exit Sub
Loop
Call draw()
End Sub
Private Sub draw()
If Not Label1.Text = " " Then If Not Label2.Text = " " Then If Not Label3.Text = " " Then If Not Label4.Text = " " Then If Not Label5.Text = " " Then If Not Label6.Text = " " Then If Not Label7.Text = " " Then If Not Label8.Text = " " Then If Not Label9.Text = " " Then MessageBox.Show("Game Draw", "Draw")
If Not Label1.Text = " " Then If Not Label2.Text = " " Then If Not Label3.Text = " " Then If Not Label4.Text = " " Then If Not Label5.Text = " " Then If Not Label6.Text = " " Then If Not Label7.Text = " " Then If Not Label8.Text = " " Then If Not Label9.Text = " " Then Call clear() Else
End Sub
Private Sub clear()
Label1.Text = " "
Label2.Text = " "
Label3.Text = " "
Label4.Text = " "
Label5.Text = " "
Label6.Text = " "
Label7.Text = " "
Label8.Text = " "
Label9.Text = " "
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
If TextBox1.Text = Player1.Text & "'s turn" And Label1.Text = " " Then Label1.Text = "O"
If TextBox1.Text = Player1.Text & "'s turn" Then TextBox1.Text = Player2.Text & "'s turn"
If TextBox1.Text = Player2.Text & "'s turn" Then Call attack()
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
If TextBox1.Text = Player1.Text & "'s turn" And Label2.Text = " " Then Label2.Text = "O"
If TextBox1.Text = Player1.Text & "'s turn" Then TextBox1.Text = Player2.Text & "'s turn"
If TextBox1.Text = Player2.Text & "'s turn" Then Call attack()
End Sub
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
If TextBox1.Text = Player1.Text & "'s turn" And Label3.Text = " " Then Label3.Text = "O"
If TextBox1.Text = Player1.Text & "'s turn" Then TextBox1.Text = Player2.Text & "'s turn"
If TextBox1.Text = Player2.Text & "'s turn" Then Call attack()
End Sub
Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
If TextBox1.Text = Player1.Text & "'s turn" And Label4.Text = " " Then Label4.Text = "O"
If TextBox1.Text = Player1.Text & "'s turn" Then TextBox1.Text = Player2.Text & "'s turn"
If TextBox1.Text = Player2.Text & "'s turn" Then Call attack()
End Sub
Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
If TextBox1.Text = Player1.Text & "'s turn" And Label5.Text = " " Then Label5.Text = "O"
If TextBox1.Text = Player1.Text & "'s turn" Then TextBox1.Text = Player2.Text & "'s turn"
If TextBox1.Text = Player2.Text & "'s turn" Then Call attack()
End Sub
Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.Click
If TextBox1.Text = Player1.Text & "'s turn" And Label6.Text = " " Then Label6.Text = "O"
If TextBox1.Text = Player1.Text & "'s turn" Then TextBox1.Text = Player2.Text & "'s turn"
If TextBox1.Text = Player2.Text & "'s turn" Then Call attack()
End Sub
Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click
If TextBox1.Text = Player1.Text & "'s turn" And Label7.Text = " " Then Label7.Text = "O"
If TextBox1.Text = Player1.Text & "'s turn" Then TextBox1.Text = Player2.Text & "'s turn"
If TextBox1.Text = Player2.Text & "'s turn" Then Call attack()
End Sub
Private Sub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label8.Click
If TextBox1.Text = Player1.Text & "'s turn" And Label8.Text = " " Then Label8.Text = "O"
If TextBox1.Text = Player1.Text & "'s turn" Then TextBox1.Text = Player2.Text & "'s turn"
If TextBox1.Text = Player2.Text & "'s turn" Then Call attack()
End Sub
Private Sub Label9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label9.Click
If TextBox1.Text = Player1.Text & "'s turn" And Label9.Text = " " Then Label9.Text = "O"
If TextBox1.Text = Player1.Text & "'s turn" Then TextBox1.Text = Player2.Text & "'s turn"
If TextBox1.Text = Player2.Text & "'s turn" Then Call attack()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Val(score1.Text) > Val(score2.Text) Then MessageBox.Show(Player1.Text & " Won The Game", Player1.Text)
If Val(score2.Text) > Val(score1.Text) Then MessageBox.Show(Player2.Text & " Won The Game", Player2.Text)
If Val(score1.Text) = Val(score2.Text) Then MessageBox.Show("The Game Was A Draw")
score1.Text = ""
score2.Text = ""
Call clear()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Form1.Show()
Me.Hide()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Val(score1.Text) > Val(score2.Text) Then MessageBox.Show(Player1.Text & " Won The Game", Player1.Text)
If Val(score2.Text) > Val(score1.Text) Then MessageBox.Show(Player2.Text & " Won The Game", Player2.Text)
If Val(score1.Text) = Val(score2.Text) Then MessageBox.Show("The Game Was A Draw")
End
End Sub
End Class