1
0
forked from s444417/ProjektAI
ProjektAI/kelner/main.py

81 lines
3.0 KiB
Python
Raw Normal View History

2020-03-22 02:01:57 +01:00
import pygame
2020-03-22 21:52:12 +01:00
from src.components.GridBoard import GridBoard
from src.managers.DrawableCollection import DrawableCollection
from src.managers.MenuManager import MenuManager
2020-03-22 21:52:12 +01:00
from src.components.Waiter import Waiter
from src.components.Table import Table
from src.managers.TaskManager import TaskManager
2020-03-22 02:01:57 +01:00
2020-03-22 21:52:12 +01:00
#create screen consts
2020-04-06 18:27:11 +02:00
CellSize = 100 #pixel size of 1 square cell in the grid
2020-03-22 21:52:12 +01:00
GridCountX = 15 #number of columns in grid
2020-04-06 18:27:11 +02:00
GridCountY = 9 #number of rows in grid
2020-03-22 21:52:12 +01:00
ScreenWidth = CellSize * GridCountX #screen width in pixels
ScreenHeight = CellSize * GridCountY #screen height in pixels
2020-04-06 18:27:11 +02:00
Offset = 50
2020-03-22 02:01:57 +01:00
2020-03-22 21:52:12 +01:00
#initialize background
2020-04-06 18:27:11 +02:00
gridBoard = GridBoard(ScreenWidth+200, ScreenHeight+200, CellSize)
2020-03-22 02:01:57 +01:00
#initialize drawable objects manager
drawableManager = DrawableCollection()
#initialize menu manager
menuManager = MenuManager()
2020-03-22 21:52:12 +01:00
#initialize waiter component
waiter = Waiter(0, 0, 0, GridCountX - 1, 0, GridCountY - 1, CellSize)
#adds waiter to drawable collection
drawableManager.add(waiter)
#initialize a number of tables given in range
for i in range(1, 20):
table = Table(0, GridCountX - 1, 0, GridCountY - 1, CellSize)
drawableManager.generatePosition(table)
drawableManager.add(table)
2020-03-22 02:01:57 +01:00
#main loop
#object that controlls repainting of changed objects
doRepaint = [True]
#new thread
task = TaskManager(drawableManager, menuManager, doRepaint)
task.start()
2020-03-22 02:01:57 +01:00
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
#handles keyboard events
2020-03-22 02:01:57 +01:00
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
#checks if new waiter's position to the left is not occupied by other object
if drawableManager.isPositionAvailable(waiter.getX() - 1, waiter.getY()):
waiter.moveLeft()
2020-03-22 02:01:57 +01:00
if event.key == pygame.K_RIGHT:
# checks if new waiter's position to the right is not occupied by other object
if drawableManager.isPositionAvailable(waiter.getX() + 1, waiter.getY()):
waiter.moveRight()
2020-03-22 02:01:57 +01:00
if event.key == pygame.K_UP:
# checks if new waiter's position up is not occupied by other object
if drawableManager.isPositionAvailable(waiter.getX(), waiter.getY() - 1):
waiter.moveUp()
2020-03-22 02:01:57 +01:00
if event.key == pygame.K_DOWN:
# checks if new waiter's position down is not occupied by other object
if drawableManager.isPositionAvailable(waiter.getX(), waiter.getY() + 1):
waiter.moveDown()
doRepaint[0] = True
2020-03-22 21:52:12 +01:00
# repaints all objects to the screen
# is set only on initial paint or after keyboard event
if doRepaint[0]:
gridBoard.reinitialize()
gridBoard.draw(drawableManager)
gridBoard.udpdate()
doRepaint[0] = False
drawableManager.collectOrders()