Sztuczna_Inteligencja/game.py
2019-04-16 13:28:11 +02:00

91 lines
2.8 KiB
Python

import pygame, sys
from waiter import Waiter
from table import Table
from path import Path
from orderTable import OrderTable
from pool import Pool
class Game(object):
def __init__(self):
pygame.init()
self.x = 11
self.y = 12
self.gridElementWidth = 50
self.gridElementHeight = 50
self.screen = pygame.display.set_mode((self.x * self.gridElementWidth, self.y * self.gridElementHeight))
self.fpsClock = pygame.time.Clock()
self.idTable = 0
self.idOrder = 0
self.idItem = -1
self.idOrderTable = 0
self.waiter = Waiter(5, 0, self) #Waiter jest atrybutem klasy Game
pygame.display.set_caption('Automatic Waiter')
self.background = pygame.image.load("./Images/tlo.jpg")
# The most important lists
self.grid = []
self.row = []
self.tableList = []
# Wygląd planszy i elementy
for j in range(self.y):
for i in range(self.x):
if ((i == 0) or (i == 10)) and ((j == 0) or (j == 8)):
self.row.append(Table(i, j, self))
elif (i == 6 and (j == 9 or j == 10 or j == 11)):
table = OrderTable(i, j, self)
self.row.append(table)
self.tableList.append(table)
elif ((i > 0 and i < 10) and (j > 1 and j < 7)) or ((i > 1 and i < 9) and (j == 1 or j == 7)):
self.row.append(Pool(i, j, self))
else:
if ((i < 5) or (i > 6)) and j > 8:
self.row.append(Pool(i, j, self))
else:
self.row.append(Path(i, j, self))
if i == 10:
self.grid.append(list(self.row))
self.row.clear()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit(0)
self.draw()
self.waiter.move(self)
pygame.display.flip()
#print(self.waiter.position)
self.fpsClock.tick(10)
def draw(self):
for row in self.grid:
for gridElement in row:
gridElement.draw()
self.waiter.draw()
def convert(self, object):
if object.type == "gridElement":
return 'G'
elif object.type == "table":
return 'T'
elif object.type == "waiter":
return 'W'
elif object.type == "orderTable":
return 'O'
elif object.type == "pool":
return 'P'
def showGrid(self, grid):
charakterList = []
row = []
for y in range(self.y):
row = list(map(self.convert, grid[y]))
charakterList.append(row)
print(row)
if __name__ == "__main__":
Game()