2020-03-22 02:01:57 +01:00
|
|
|
import pygame
|
2020-03-22 21:52:12 +01:00
|
|
|
from src.components.GridBoard import GridBoard
|
2020-04-03 23:54:29 +02:00
|
|
|
from src.managers.DrawableCollection import DrawableCollection
|
2020-03-22 21:52:12 +01:00
|
|
|
from src.components.Waiter import Waiter
|
2020-04-03 23:54:29 +02:00
|
|
|
from src.components.Table import Table
|
2020-03-22 02:01:57 +01:00
|
|
|
|
|
|
|
|
2020-03-22 21:52:12 +01:00
|
|
|
#create screen consts
|
|
|
|
CellSize = 50 #pixel size of 1 square cell in the grid
|
|
|
|
GridCountX = 15 #number of columns in grid
|
|
|
|
GridCountY = 11 #number of rows in grid
|
|
|
|
ScreenWidth = CellSize * GridCountX #screen width in pixels
|
|
|
|
ScreenHeight = CellSize * GridCountY #screen height in pixels
|
2020-03-22 02:01:57 +01:00
|
|
|
|
2020-03-22 21:52:12 +01:00
|
|
|
#initialize background
|
|
|
|
gridBoard = GridBoard(ScreenWidth, ScreenHeight, CellSize)
|
2020-03-22 02:01:57 +01:00
|
|
|
|
2020-04-03 23:54:29 +02:00
|
|
|
#initialize drawable objects manager
|
|
|
|
drawableManager = DrawableCollection()
|
|
|
|
|
2020-03-22 21:52:12 +01:00
|
|
|
#initialize waiter component
|
2020-04-03 23:54:29 +02:00
|
|
|
waiter = Waiter(0, 0, 0, GridCountX - 1, 0, GridCountY - 1, CellSize)
|
|
|
|
|
|
|
|
#initialize a number of tables given in range
|
|
|
|
for i in range(1, 15):
|
|
|
|
table = Table(0, GridCountX - 1, 0, GridCountY - 1, CellSize)
|
|
|
|
drawableManager.generatePosition(table)
|
|
|
|
drawableManager.add(table)
|
2020-03-22 02:01:57 +01:00
|
|
|
|
2020-04-03 23:54:29 +02:00
|
|
|
#main loop
|
2020-03-22 21:52:12 +01:00
|
|
|
doRepaint = True
|
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
|
|
|
|
|
2020-04-03 23:54:29 +02:00
|
|
|
#handles keyboard events
|
2020-03-22 02:01:57 +01:00
|
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
if event.key == pygame.K_LEFT:
|
2020-04-03 23:54:29 +02:00
|
|
|
#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:
|
2020-04-03 23:54:29 +02:00
|
|
|
# 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:
|
2020-04-03 23:54:29 +02:00
|
|
|
# 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:
|
2020-04-03 23:54:29 +02:00
|
|
|
# checks if new waiter's position down is not occupied by other object
|
|
|
|
if drawableManager.isPositionAvailable(waiter.getX(), waiter.getY() + 1):
|
|
|
|
waiter.moveDown()
|
2020-03-22 21:52:12 +01:00
|
|
|
doRepaint = True
|
|
|
|
|
2020-04-03 23:54:29 +02:00
|
|
|
# repaints all objects to the screen
|
|
|
|
#is set only on initial paint or after keyboard event
|
2020-03-22 21:52:12 +01:00
|
|
|
if doRepaint:
|
|
|
|
gridBoard.reinitialize()
|
2020-04-03 23:54:29 +02:00
|
|
|
gridBoard.draw(drawableManager)
|
2020-03-22 21:52:12 +01:00
|
|
|
gridBoard.draw(waiter)
|
|
|
|
gridBoard.udpdate()
|
|
|
|
doRepaint = False
|