Sztuczna_Inteligencja_2020/main.py

62 lines
1.7 KiB
Python
Raw Normal View History

2020-04-06 22:10:21 +02:00
import sys
2020-04-27 21:56:17 +02:00
import secrets
2020-04-06 22:10:21 +02:00
from src.graphics import *
from src.waiter import *
if __name__ == "__main__":
# SETUP
pygame.init()
clock = pygame.time.Clock()
2020-04-27 21:56:17 +02:00
fps = 2
2020-04-06 22:10:21 +02:00
graphics = Graphics()
waiter = Waiter(graphics)
# init functions
graphics.drawBackground(waiter.matrix)
graphics.update(waiter.X, waiter.Y)
2020-04-27 21:56:17 +02:00
goal = None
path = [(0, 0)]
# print(waiter.findPath())
2020-04-06 22:10:21 +02:00
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
break
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pygame.quit()
sys.exit()
break
2020-04-27 21:56:17 +02:00
if event.key == pygame.K_r:
temp = False
while not temp:
x = secrets.randbelow(graphics.width)
y = secrets.randbelow(graphics.height)
if waiter.matrix.matrix[x][y].walk_through == 1:
temp = True
goal = (x, y)
path = waiter.findPath(goal)
2020-04-28 18:56:50 +02:00
print('goal: {}'.format(goal))
2020-04-27 21:56:17 +02:00
if path != []:
2020-04-28 18:56:50 +02:00
print(path)
nextStep = path.pop(0)
print(nextStep)
waiter.travel(nextStep, graphics)
print('{} {} current position'.format(waiter.X, waiter.Y))
'''
graphics.clear(waiter.X, waiter.Y)
waiter.update(event, graphics)
graphics.update(waiter.X, waiter.Y)
'''
2020-04-06 22:10:21 +02:00
pygame.display.flip()
clock.tick(fps)