Čau mam dělam hru tic tac toe , ale mam takový problem,když se na políčko klikne tak ma byt promena positionX true.Takže např. kliknu na policko1 tak position1 = true,a pocitac vyhrazuje nahodna cisla od 1 - 9 a pokud mu padne 1 a 1 už je zaplněná tak to ma losovat znova.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Text = "O"
Dim position1 As Long
Dim position2 As Long
Dim position3 As Long
Dim position4 As Long
Dim position5 As Long
Dim position6 As Long
Dim position7 As Long
Dim position8 As Long
Dim position9 As Long
Dim randomnumber As Random
Dim number As Long
randomnumber = New Random
number = randomnumber.Next(1, 10)
position1 = True
If number = 1 Then
1: Button8.Text = "X"
randomnumber = New Random
number = randomnumber.Next(1, 10)
If number = 1 Then
GoTo 1
End If
End If
2: If number = 2 Then
If position2 = True Then
randomnumber = New Random
number = randomnumber.Next(1, 10)
If number = 1 Then
GoTo 1
End If
If number = 2 Then
GoTo 2
End If
If number = 3 Then
GoTo 3
End If
If number = 4 Then
GoTo 4
End If
If number = 5 Then
GoTo 5
End If
If number = 6 Then
GoTo 6
End If
If number = 7 Then
GoTo 7
End If
If number = 8 Then
GoTo 8
End If
If number = 9 Then
GoTo 9
End If
If number = 2 Then
GoTo 9
End If
End If
Button2.Text = "X"
position2 = True
End If
3: If number = 3 Then
If position3 = True Then
randomnumber = New Random
number = randomnumber.Next(1, 10)
If number = 1 Then
GoTo 1
End If
If number = 2 Then
GoTo 2
End If
If number = 3 Then
GoTo 3
End If
If number = 4 Then
GoTo 4
End If
If number = 5 Then
GoTo 5
End If
If number = 6 Then
GoTo 6
End If
If number = 7 Then
GoTo 7
End If
If number = 8 Then
GoTo 8
End If
If number = 9 Then
GoTo 9
End If
If number = 2 Then
GoTo 9
End If
End If
Button3.Text = "X"
position3 = True
End If
4: If number = 4 Then
If position4 = True Then
randomnumber = New Random
number = randomnumber.Next(1, 10)
If number = 1 Then
GoTo 1
End If
If number = 2 Then
GoTo 2
End If
If number = 3 Then
GoTo 3
End If
If number = 4 Then
GoTo 4
End If
If number = 5 Then
GoTo 5
End If
If number = 6 Then
GoTo 6
End If
If number = 7 Then
GoTo 7
End If
If number = 8 Then
GoTo 8
End If
If number = 9 Then
GoTo 9
End If
If number = 2 Then
GoTo 9
End If
End If
position4 = True
Button4.Text = "X"
End If
5: If number = 5 Then
If position5 = True Then
randomnumber = New Random
number = randomnumber.Next(1, 10)
If number = 1 Then
GoTo 1
End If
If number = 2 Then
GoTo 2
End If
If number = 3 Then
GoTo 3
End If
If number = 4 Then
GoTo 4
End If
If number = 5 Then
GoTo 5
End If
If number = 6 Then
GoTo 6
End If
If number = 7 Then
GoTo 7
End If
If number = 8 Then
GoTo 8
End If
If number = 9 Then
GoTo 9
End If
If number = 2 Then
GoTo 9
End If
End If
position5 = True
Button5.Text = "X"
End If
6: If number = 6 Then
If position6 = True Then
randomnumber = New Random
number = randomnumber.Next(1, 10)
If number = 1 Then
GoTo 1
End If
If number = 2 Then
GoTo 2
End If
If number = 3 Then
GoTo 3
End If
If number = 4 Then
GoTo 4
End If
If number = 5 Then
GoTo 5
End If
If number = 6 Then
GoTo 6
End If
If number = 7 Then
GoTo 7
End If
If number = 8 Then
GoTo 8
End If
If number = 9 Then
GoTo 9
End If
If number = 2 Then
GoTo 9
End If
End If
position6 = True
Button6.Text = "X"
End If
7: If number = 7 Then
If position7 = True Then
randomnumber = New Random
number = randomnumber.Next(1, 10)
If number = 1 Then
GoTo 1
End If
If number = 2 Then
GoTo 2
End If
If number = 3 Then
GoTo 3
End If
If number = 4 Then
GoTo 4
End If
If number = 5 Then
GoTo 5
End If
If number = 6 Then
GoTo 6
End If
If number = 7 Then
GoTo 7
End If
If number = 8 Then
GoTo 8
End If
If number = 9 Then
GoTo 9
End If
If number = 2 Then
GoTo 9
End If
End If
position7 = True
Button7.Text = "X"
End If
8: If number = 8 Then
If position8 = True Then
randomnumber = New Random
number = randomnumber.Next(1, 10)
If number = 1 Then
GoTo 1
End If
If number = 2 Then
GoTo 2
End If
If number = 3 Then
GoTo 3
End If
If number = 4 Then
GoTo 4
End If
If number = 5 Then
GoTo 5
End If
If number = 6 Then
GoTo 6
End If
If number = 7 Then
GoTo 7
End If
If number = 8 Then
GoTo 8
End If
If number = 9 Then
GoTo 9
End If
If number = 2 Then
GoTo 9
End If
End If
position8 = True
Button8.Text = "X"
End If
9: If number = 9 Then
If position9 = True Then
randomnumber = New Random
number = randomnumber.Next(1, 10)
If number = 1 Then
GoTo 1
End If
If number = 2 Then
GoTo 2
End If
If number = 3 Then
GoTo 3
End If
If number = 4 Then
GoTo 4
End If
If number = 5 Then
GoTo 5
End If
If number = 6 Then
GoTo 6
End If
If number = 7 Then
GoTo 7
End If
If number = 8 Then
GoTo 8
End If
If number = 9 Then
GoTo 9
End If
If number = 2 Then
GoTo 9
End If
End If
position9 = True
Button9.Text = "X"
End If
End Sub
|