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,47 +354,49 @@ class Waiter(object):
def goByAStar(self, end):
positionList = aStar(self.pos, end)
print(positionList)
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]
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]
movey = positionList[i + 1][1] - positionList[i][1]
prevDirection = self.direction
if movex == -1 and movey == 0:
self.direction = 1 #"left"
elif movex == 1 and movey == 0:
self.direction = 3 #"right"
elif movey == 1 and movex == 0:
self.direction = 4 #"down"
else:
self.direction = 2 #"up"
prevDirection = self.direction
if movex == -1 and movey == 0:
self.direction = 1 #"left"
elif movex == 1 and movey == 0:
self.direction = 3 #"right"
elif movey == 1 and movex == 0:
self.direction = 4 #"down"
else:
self.direction = 2 #"up"
howToRotate = prevDirection - self.direction #działa!
howToRotate = prevDirection - self.direction #działa!
print(prevDirection)
print(self.direction)
print(howToRotate)
if howToRotate < 0:
self.rotate = "left"
self.rotationNumber = abs(howToRotate)
elif howToRotate > 0:
self.rotate = "right"
self.rotationNumber = abs(howToRotate)
elif howToRotate == 0:
if howToRotate < 0:
self.rotate = "left"
self.rotationNumber = abs(howToRotate)
elif howToRotate > 0:
self.rotate = "right"
self.rotationNumber = abs(howToRotate)
elif howToRotate == 0:
self.rotate = "forward"
self.rotationNumber = 0
#print(self.rotate)
for i in range(self.rotationNumber):
redrawWindow(window)
time.sleep(0.5)
self.rotate = "forward"
self.rotationNumber = 0
print(self.rotate)
for i in range(self.rotationNumber):
self.goForward(movex, movey)
redrawWindow(window)
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):
@ -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