Sztuczna_Inteligencja_2020/main.py
2020-05-13 09:22:12 +02:00

57 lines
1.5 KiB
Python

import sys
import secrets
from src.graphics import *
from src.rabbit import Rabbit
from src.waiter import *
if __name__ == "__main__":
# SETUP
pygame.init()
clock = pygame.time.Clock()
graphics = Graphics()
waiter = Waiter(graphics)
rabbit = Rabbit()
# init functions
graphics.drawBackground(waiter.matrix)
graphics.update(waiter)
goal = None
path = ''
while True:
for event in pygame.event.get():
# rabbit.check(waiter.matrix, waiter.X, waiter.Y)
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
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)
path = waiter.translatePath(path)
if path != '':
nextStep = path[0]
path = path[1:]
waiter.travel(nextStep, graphics)
pygame.display.flip()
clock.tick(graphics.fps)