שלום בניתי משחק איקס עיגול ושמתי לב שלפעמים הבוט של המחשב לא קורא את המצבים ולפעמים הוא לא משחק בכלל..
אני יפרסם את הפונקציות של הבוט וגם של השיחוק..
קוד:
Sub bot()
If playerlbl.Text = "its O turn" Then
Dim place As Integer
Dim found As Boolean = False
While found = False
If lbl1_1.Text = "O" And lbl1_2.Text = "O" And lbl1_3.Text = "" Then
lbl1_3.Text = "O"
found = True
ElseIf lbl1_1.Text = "O" And lbl1_2.Text = "" And lbl1_3.Text = "O" Then
lbl1_2.Text = "O"
found = True
ElseIf lbl1_1.Text = "" And lbl1_2.Text = "O" And lbl1_3.Text = "O" Then
lbl1_1.Text = "O"
found = True
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ElseIf lbl2_1.Text = "O" And lbl2_2.Text = "O" And lbl2_3.Text = "" Then
lbl2_3.Text = "O"
found = True
ElseIf lbl2_1.Text = "O" And lbl2_2.Text = "" And lbl2_3.Text = "O" Then
lbl2_2.Text = "O"
found = True
ElseIf lbl2_1.Text = "" And lbl2_2.Text = "O" And lbl2_3.Text = "O" Then
lbl2_1.Text = "O"
found = True
'''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''
ElseIf lbl3_1.Text = "O" And lbl3_2.Text = "O" And lbl3_3.Text = "" Then
lbl3_3.Text = "O"
found = True
ElseIf lbl3_1.Text = "O" And lbl3_2.Text = "" And lbl3_3.Text = "O" Then
lbl3_2.Text = "O"
found = True
ElseIf lbl3_1.Text = "" And lbl2_2.Text = "O" And lbl2_3.Text = "O" Then
lbl3_1.Text = "O"
found = True
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ElseIf lbl1_1.Text = "O" And lbl2_1.Text = "O" And lbl3_1.Text = "" Then
lbl3_1.Text = "O"
found = True
ElseIf lbl1_1.Text = "O" And lbl2_1.Text = "" And lbl3_1.Text = "O" Then
lbl2_1.Text = "O"
found = True
ElseIf lbl1_1.Text = "" And lbl2_1.Text = "O" And lbl3_1.Text = "O" Then
lbl1_1.Text = "O"
found = True
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ElseIf lbl1_2.Text = "O" And lbl2_2.Text = "O" And lbl3_2.Text = "" Then
lbl3_2.Text = "O"
found = True
ElseIf lbl1_2.Text = "O" And lbl2_2.Text = "O" And lbl3_2.Text = "" Then
lbl3_2.Text = "O"
found = True
ElseIf lbl1_2.Text = "" And lbl2_2.Text = "O" And lbl3_2.Text = "O" Then
lbl1_2.Text = "O"
found = True
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ElseIf lbl1_3.Text = "O" And lbl2_3.Text = "O" And lbl3_3.Text = "" Then
lbl3_3.Text = "O"
found = True
ElseIf lbl1_3.Text = "O" And lbl2_3.Text = "" And lbl3_3.Text = "O" Then
lbl2_3.Text = "O"
found = True
ElseIf lbl1_3.Text = "" And lbl2_3.Text = "O" And lbl3_3.Text = "O" Then
lbl1_3.Text = "O"
found = True
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ElseIf lbl1_1.Text = "O" And lbl2_2.Text = "O" And lbl3_3.Text = "" Then
lbl3_3.Text = "O"
found = True
ElseIf lbl1_1.Text = "O" And lbl2_2.Text = "" And lbl3_3.Text = "O" Then
lbl2_2.Text = ""
found = True
ElseIf lbl1_1.Text = "" And lbl2_2.Text = "O" And lbl3_3.Text = "O" Then
lbl1_1.Text = "O"
found = True
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ElseIf lbl1_3.Text = "O" And lbl2_2.Text = "O" And lbl3_1.Text = "" Then
lbl3_1.Text = "O"
found = True
ElseIf lbl1_3.Text = "O" And lbl2_2.Text = "" And lbl3_1.Text = "O" Then
lbl2_2.Text = "O"
found = True
ElseIf lbl1_3.Text = "" And lbl2_2.Text = "O" And lbl3_3.Text = "O" Then
lbl1_3.Text = "O"
found = True
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ElseIf lbl1_1.Text = "X" And lbl1_2.Text = "X" And lbl1_3.Text = "" Then
lbl1_3.Text = "O"
found = True
ElseIf lbl1_1.Text = "X" And lbl1_2.Text = "" And lbl1_3.Text = "X" Then
lbl1_2.Text = "O"
found = True
ElseIf lbl1_1.Text = "" And lbl1_2.Text = "X" And lbl1_3.Text = "X" Then
lbl1_1.Text = "O"
found = True
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ElseIf lbl2_1.Text = "X" And lbl2_2.Text = "X" And lbl2_3.Text = "" Then
lbl2_3.Text = "O"
found = True
ElseIf lbl2_1.Text = "X" And lbl2_2.Text = "" And lbl2_3.Text = "X" Then
lbl2_2.Text = "O"
found = True
ElseIf lbl2_1.Text = "" And lbl2_2.Text = "X" And lbl2_3.Text = "X" Then
lbl2_1.Text = "O"
found = True
'''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''
ElseIf lbl3_1.Text = "X" And lbl3_2.Text = "X" And lbl3_3.Text = "" Then
lbl3_3.Text = "O"
found = True
ElseIf lbl3_1.Text = "X" And lbl3_2.Text = "" And lbl3_3.Text = "X" Then
lbl3_2.Text = "O"
found = True
ElseIf lbl3_1.Text = "" And lbl2_2.Text = "X" And lbl2_3.Text = "X" Then
lbl3_1.Text = "O"
found = True
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ElseIf lbl1_1.Text = "X" And lbl2_1.Text = "X" And lbl3_1.Text = "" Then
lbl3_1.Text = "O"
found = True
ElseIf lbl1_1.Text = "X" And lbl2_1.Text = "" And lbl3_1.Text = "X" Then
lbl2_1.Text = "O"
found = True
ElseIf lbl1_1.Text = "" And lbl2_1.Text = "X" And lbl3_1.Text = "X" Then
lbl1_1.Text = "O"
found = True
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ElseIf lbl1_2.Text = "X" And lbl2_2.Text = "X" And lbl3_2.Text = "" Then
lbl3_2.Text = "O"
found = True
ElseIf lbl1_2.Text = "X" And lbl2_2.Text = "X" And lbl3_2.Text = "" Then
lbl3_2.Text = "O"
found = True
ElseIf lbl1_2.Text = "" And lbl2_2.Text = "X" And lbl3_2.Text = "X" Then
lbl1_2.Text = "O"
found = True
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ElseIf lbl1_3.Text = "X" And lbl2_3.Text = "X" And lbl3_3.Text = "" Then
lbl3_3.Text = "O"
found = True
ElseIf lbl1_3.Text = "X" And lbl2_3.Text = "" And lbl3_3.Text = "X" Then
lbl2_3.Text = "O"
found = True
ElseIf lbl1_3.Text = "" And lbl2_3.Text = "X" And lbl3_3.Text = "X" Then
lbl1_3.Text = "O"
found = True
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ElseIf lbl1_1.Text = "X" And lbl2_2.Text = "X" And lbl3_3.Text = "" Then
lbl3_3.Text = "O"
found = True
ElseIf lbl1_1.Text = "X" And lbl2_2.Text = "" And lbl3_3.Text = "X" Then
lbl2_2.Text = ""
found = True
ElseIf lbl1_1.Text = "" And lbl2_2.Text = "X" And lbl3_3.Text = "X" Then
lbl1_1.Text = "O"
found = True
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ElseIf lbl1_3.Text = "X" And lbl2_2.Text = "X" And lbl3_1.Text = "" Then
lbl3_1.Text = "O"
found = True
ElseIf lbl1_3.Text = "X" And lbl2_2.Text = "" And lbl3_1.Text = "X" Then
lbl2_2.Text = "O"
found = True
ElseIf lbl1_3.Text = "" And lbl2_2.Text = "X" And lbl3_3.Text = "X" Then
lbl1_3.Text = "O"
found = True
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ElseIf lbl3_1.Text = "X" And lbl1_3.Text = "" Then
lbl1_3.Text = "O"
found = True
ElseIf lbl1_3.Text = "X" And lbl3_3.Text = "" Then
lbl3_3.Text = "O"
found = True
Else
place = (Rnd() * 9 + 1)
If place = 1 And lbl1_1.Text = "" Then
lbl1_1.Text = "O"
found = True
ElseIf place = 2 And lbl1_2.Text = "" Then
lbl1_2.Text = "O"
found = True
ElseIf place = 3 And lbl1_3.Text = "" Then
lbl1_3.Text = "O"
found = True
ElseIf place = 4 And lbl2_1.Text = "" Then
lbl2_1.Text = "O"
found = True
ElseIf place = 5 And lbl2_2.Text = "" Then
lbl2_2.Text = "O"
found = True
ElseIf place = 6 And lbl2_3.Text = "" Then
lbl2_3.Text = "O"
found = True
ElseIf place = 7 And lbl3_1.Text = "" Then
lbl3_1.Text = "O"
found = True
ElseIf place = 8 And lbl3_2.Text = "" Then
lbl3_2.Text = "O"
found = True
ElseIf place = 9 And lbl3_3.Text = "" Then
lbl3_3.Text = "O"
found = True
End If
If lbl1_1.Text <> "" And lbl1_2.Text <> "" And lbl1_3.Text <> "" And lbl2_1.Text <> "" And lbl2_2.Text <> "" And lbl2_3.Text <> "" And lbl3_1.Text <> "" And lbl3_2.Text <> "" And lbl3_3.Text <> "" Then
gametimer.Stop()
playerlbl.Text = "its X turn"
MsgBox("No Winner")
restartboard()
found = True
End If
End If
End While
playerlbl.Text = "its X turn"
End If
End Sub
ושל הלחיצה על הlabel
הלוח שלי אגב מסודר לפי
1_1 1_2 1_3 וכו'..
קוד:
Sub clicked(ByRef lbl As Label)
If pause = False Then
If lbl.Text = "" Then
If playerlbl.Text = "its X turn" Then
lbl.Text = "X"
playerlbl.Text = "its O turn"
prgbar.Value = 0
Else
lbl.Text = "O"
playerlbl.Text = "its X turn"
prgbar.Value = 0
End If
If botX = True Then
bot()
End If
Else
MsgBox("Not empty")
End If
Else
MsgBox("You paused the game you need to active the game , Press F3 to active")
End If
End Sub