Kontrola czy dane pole jest osiągalne - messagebox

This commit is contained in:
Sara Kowalska 2020-04-27 11:43:58 +02:00
parent 86bd4e7973
commit f0fa74f227

View File

@ -3,6 +3,10 @@ import random
import time
import queue
import math
from tkinter import messagebox
import tkinter as tk
root = tk.Tk()
root.withdraw() #ukrycie okna tworzonego przez tkinter
pygame.init()
@ -350,6 +354,11 @@ class Waiter(object):
def goByAStar(self, end):
positionList = aStar(self.pos, end)
print(positionList)
if len(positionList) == 0:
messagebox.showerror("BŁĄD!", "Wybrano nieosiągalne pole!")
pygame.quit()
exit()
else:
lenght = len(positionList) - 1
for i in range(lenght):
movex = positionList[i + 1][0] - positionList[i][0]
@ -367,9 +376,6 @@ class Waiter(object):
howToRotate = prevDirection - self.direction #działa!
print(prevDirection)
print(self.direction)
print(howToRotate)
if howToRotate < 0:
self.rotate = "left"
self.rotationNumber = abs(howToRotate)
@ -380,13 +386,13 @@ class Waiter(object):
self.rotate = "forward"
self.rotationNumber = 0
print(self.rotate)
#print(self.rotate)
for i in range(self.rotationNumber):
redrawWindow(window)
time.sleep(0.5)
self.rotate = "forward"
self.rotationNumber -= 0
self.rotationNumber = 0
self.goForward(movex, movey)
redrawWindow(window)
@ -471,7 +477,7 @@ def main():
clock.tick(60)
redrawWindow(window)
#bot.moveRandomly()
goal = (1, 5)
goal = (1, 3)
bot.goByAStar(goal)
time.sleep(60)
flag = False