66 lines
1.5 KiB
Python
66 lines
1.5 KiB
Python
|
#!/usr/bin/python3
|
||
|
|
||
|
import pygame
|
||
|
|
||
|
from config import *
|
||
|
from app.board import Board
|
||
|
from app.agent import Agent
|
||
|
|
||
|
|
||
|
class App:
|
||
|
def __init__(self):
|
||
|
self.__running = True
|
||
|
self.__screen = None
|
||
|
self.__clock = None
|
||
|
self.__board = Board()
|
||
|
self.__agent = Agent()
|
||
|
|
||
|
def initialize(self):
|
||
|
pygame.init()
|
||
|
pygame.display.set_caption(CAPTION)
|
||
|
self.__screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
||
|
|
||
|
self.__clock = pygame.time.Clock()
|
||
|
|
||
|
def event_handler(self, event: pygame.event.Event):
|
||
|
if event.type == pygame.QUIT:
|
||
|
self.__running = False
|
||
|
|
||
|
def loop_handler(self):
|
||
|
self.__board.draw(self.__screen)
|
||
|
self.__agent.draw(self.__screen)
|
||
|
|
||
|
def keys_pressed_handler(self):
|
||
|
keys = pygame.key.get_pressed()
|
||
|
|
||
|
if keys[pygame.K_UP]:
|
||
|
self.__agent.move_up()
|
||
|
if keys[pygame.K_DOWN]:
|
||
|
self.__agent.move_down()
|
||
|
if keys[pygame.K_LEFT]:
|
||
|
self.__agent.move_left()
|
||
|
if keys[pygame.K_RIGHT]:
|
||
|
self.__agent.move_right()
|
||
|
|
||
|
def update_screen(self):
|
||
|
pygame.display.flip()
|
||
|
|
||
|
def quit(self):
|
||
|
pygame.quit()
|
||
|
|
||
|
def run(self):
|
||
|
self.initialize()
|
||
|
|
||
|
while self.__running:
|
||
|
self.__clock.tick(FPS)
|
||
|
|
||
|
for event in pygame.event.get():
|
||
|
self.event_handler(event)
|
||
|
|
||
|
self.keys_pressed_handler()
|
||
|
|
||
|
self.loop_handler()
|
||
|
self.update_screen()
|
||
|
|
||
|
self.quit()
|