Sztuczna_Inteligencja/game.py

92 lines
2.9 KiB
Python
Raw Normal View History

2019-04-10 10:31:09 +02:00
import pygame, sys
from waiter import Waiter
from table import Table
2019-04-16 13:28:11 +02:00
from path import Path
2019-04-10 10:31:09 +02:00
from orderTable import OrderTable
2019-04-14 18:33:30 +02:00
from pool import Pool
2019-04-10 10:31:09 +02:00
2019-04-16 13:28:11 +02:00
2019-04-10 10:31:09 +02:00
class Game(object):
def __init__(self):
pygame.init()
2019-04-14 18:33:30 +02:00
self.x = 11
2019-04-10 10:31:09 +02:00
self.y = 12
2019-04-16 13:28:11 +02:00
self.gridElementWidth = 50
self.gridElementHeight = 50
self.screen = pygame.display.set_mode((self.x * self.gridElementWidth, self.y * self.gridElementHeight))
2019-04-10 10:31:09 +02:00
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 i nie ma go w gridzie
self.waiterMovesHistory = []
2019-04-10 10:31:09 +02:00
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
2019-04-16 13:28:11 +02:00
for j in range(self.y):
2019-04-10 10:31:09 +02:00
for i in range(self.x):
2019-04-16 13:28:11 +02:00
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)
2019-04-10 10:31:09 +02:00
self.row.append(table)
self.tableList.append(table)
2019-04-16 13:28:11 +02:00
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))
2019-04-10 10:31:09 +02:00
else:
2019-04-16 13:28:11 +02:00
if ((i < 5) or (i > 6)) and j > 8:
self.row.append(Pool(i, j, self))
2019-04-10 10:31:09 +02:00
else:
2019-04-16 13:28:11 +02:00
self.row.append(Path(i, j, self))
2019-04-14 18:33:30 +02:00
if i == 10:
2019-04-10 10:31:09 +02:00
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()
2019-04-16 13:28:11 +02:00
self.waiter.move(self)
2019-04-10 10:31:09 +02:00
pygame.display.flip()
2019-04-16 13:28:11 +02:00
#print(self.waiter.position)
2019-04-10 10:31:09 +02:00
self.fpsClock.tick(10)
def draw(self):
for row in self.grid:
for gridElement in row:
2019-04-16 13:28:11 +02:00
gridElement.draw()
self.waiter.draw()
2019-04-10 10:31:09 +02:00
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'
2019-04-14 18:33:30 +02:00
elif object.type == "pool":
return 'P'
2019-04-10 10:31:09 +02:00
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()