Kontrola czy dane pole jest osiągalne - messagebox
This commit is contained in:
parent
86bd4e7973
commit
f0fa74f227
@ -3,6 +3,10 @@ import random
|
|||||||
import time
|
import time
|
||||||
import queue
|
import queue
|
||||||
import math
|
import math
|
||||||
|
from tkinter import messagebox
|
||||||
|
import tkinter as tk
|
||||||
|
root = tk.Tk()
|
||||||
|
root.withdraw() #ukrycie okna tworzonego przez tkinter
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
@ -350,47 +354,49 @@ class Waiter(object):
|
|||||||
def goByAStar(self, end):
|
def goByAStar(self, end):
|
||||||
positionList = aStar(self.pos, end)
|
positionList = aStar(self.pos, end)
|
||||||
print(positionList)
|
print(positionList)
|
||||||
lenght = len(positionList) - 1
|
if len(positionList) == 0:
|
||||||
for i in range(lenght):
|
messagebox.showerror("BŁĄD!", "Wybrano nieosiągalne pole!")
|
||||||
movex = positionList[i + 1][0] - positionList[i][0]
|
pygame.quit()
|
||||||
movey = positionList[i + 1][1] - positionList[i][1]
|
exit()
|
||||||
|
else:
|
||||||
|
lenght = len(positionList) - 1
|
||||||
|
for i in range(lenght):
|
||||||
|
movex = positionList[i + 1][0] - positionList[i][0]
|
||||||
|
movey = positionList[i + 1][1] - positionList[i][1]
|
||||||
|
|
||||||
prevDirection = self.direction
|
prevDirection = self.direction
|
||||||
if movex == -1 and movey == 0:
|
if movex == -1 and movey == 0:
|
||||||
self.direction = 1 #"left"
|
self.direction = 1 #"left"
|
||||||
elif movex == 1 and movey == 0:
|
elif movex == 1 and movey == 0:
|
||||||
self.direction = 3 #"right"
|
self.direction = 3 #"right"
|
||||||
elif movey == 1 and movex == 0:
|
elif movey == 1 and movex == 0:
|
||||||
self.direction = 4 #"down"
|
self.direction = 4 #"down"
|
||||||
else:
|
else:
|
||||||
self.direction = 2 #"up"
|
self.direction = 2 #"up"
|
||||||
|
|
||||||
howToRotate = prevDirection - self.direction #działa!
|
howToRotate = prevDirection - self.direction #działa!
|
||||||
|
|
||||||
print(prevDirection)
|
if howToRotate < 0:
|
||||||
print(self.direction)
|
self.rotate = "left"
|
||||||
print(howToRotate)
|
self.rotationNumber = abs(howToRotate)
|
||||||
if howToRotate < 0:
|
elif howToRotate > 0:
|
||||||
self.rotate = "left"
|
self.rotate = "right"
|
||||||
self.rotationNumber = abs(howToRotate)
|
self.rotationNumber = abs(howToRotate)
|
||||||
elif howToRotate > 0:
|
elif howToRotate == 0:
|
||||||
self.rotate = "right"
|
self.rotate = "forward"
|
||||||
self.rotationNumber = abs(howToRotate)
|
self.rotationNumber = 0
|
||||||
elif howToRotate == 0:
|
|
||||||
|
#print(self.rotate)
|
||||||
|
|
||||||
|
for i in range(self.rotationNumber):
|
||||||
|
redrawWindow(window)
|
||||||
|
time.sleep(0.5)
|
||||||
self.rotate = "forward"
|
self.rotate = "forward"
|
||||||
self.rotationNumber = 0
|
self.rotationNumber = 0
|
||||||
|
|
||||||
print(self.rotate)
|
self.goForward(movex, movey)
|
||||||
|
|
||||||
for i in range(self.rotationNumber):
|
|
||||||
redrawWindow(window)
|
redrawWindow(window)
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
self.rotate = "forward"
|
|
||||||
self.rotationNumber -= 0
|
|
||||||
|
|
||||||
self.goForward(movex, movey)
|
|
||||||
redrawWindow(window)
|
|
||||||
time.sleep(0.5)
|
|
||||||
|
|
||||||
|
|
||||||
def drawGrid(width, rows, surface):
|
def drawGrid(width, rows, surface):
|
||||||
@ -471,7 +477,7 @@ def main():
|
|||||||
clock.tick(60)
|
clock.tick(60)
|
||||||
redrawWindow(window)
|
redrawWindow(window)
|
||||||
#bot.moveRandomly()
|
#bot.moveRandomly()
|
||||||
goal = (1, 5)
|
goal = (1, 3)
|
||||||
bot.goByAStar(goal)
|
bot.goByAStar(goal)
|
||||||
time.sleep(60)
|
time.sleep(60)
|
||||||
flag = False
|
flag = False
|
||||||
|
Loading…
Reference in New Issue
Block a user