import pygame from src.components.GridBoard import GridBoard from src.managers.DrawableCollection import DrawableCollection from src.components.Waiter import Waiter from src.components.Table import Table #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 #initialize background gridBoard = GridBoard(ScreenWidth, ScreenHeight, CellSize) #initialize drawable objects manager drawableManager = DrawableCollection() #initialize waiter component 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) #main loop doRepaint = True running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False #handles keyboard events 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() 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() 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() 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 = True # repaints all objects to the screen #is set only on initial paint or after keyboard event if doRepaint: gridBoard.reinitialize() gridBoard.draw(drawableManager) gridBoard.draw(waiter) gridBoard.udpdate() doRepaint = False