129 lines
4.2 KiB
Python
129 lines
4.2 KiB
Python
import pygame, sys
|
|
from waiter import Waiter
|
|
from table import Table
|
|
from gridElement import GridElement
|
|
from pygame.math import Vector2
|
|
from orderTable import OrderTable
|
|
from pool import Pool
|
|
import copy
|
|
|
|
class Game(object):
|
|
def __init__(self):
|
|
pygame.init()
|
|
self.x = 10
|
|
self.y = 10
|
|
self.screen = pygame.display.set_mode((self.x * 50, self.y * 50))
|
|
self.fpsClock = pygame.time.Clock()
|
|
self.idTable = 0
|
|
self.idOrder = 0
|
|
self.idItem = -1
|
|
self.idOrderTable = 0
|
|
self.waiterNumberInGrid = Vector2()
|
|
pygame.display.set_caption('Automatic Waiter')
|
|
self.background = pygame.image.load("./Images/tlo.jpg")
|
|
|
|
# The most important lists
|
|
self.grid = []
|
|
self.row = []
|
|
self.tableList = []
|
|
|
|
for b in range(self.y):
|
|
for i in range(self.x):
|
|
if ((i == 0) or (i == 9)) and ((b == 0) or (b == 6)):
|
|
self.row.append(Table(i * 50, b * 50, self))
|
|
elif (b == self.y-1 or b == self.y-2 or b == self.y-3) and (i == 5):
|
|
table = OrderTable(i * 50, b * 50, self)
|
|
self.row.append(table)
|
|
self.tableList.append(table)
|
|
elif i == 4 and b == 9:
|
|
self.waiter = Waiter(self, i * 50, b * 50)
|
|
self.row.append(self.waiter)
|
|
self.waiterNumberInGrid.x = i
|
|
self.waiterNumberInGrid.y = b
|
|
elif (((((b > 0 and b < 6) and (i > 0 and i < 9)) and not((i==1 or i == 8) and (b==1 or b==5))) \
|
|
or (b>6 and (i<4 or i > 5) ))) and not i == 4:
|
|
self.row.append(Pool(i * 50, b * 50, self))
|
|
else:
|
|
self.row.append(GridElement(i * 50, b * 50, self))
|
|
if i == self.x-1:
|
|
self.grid.append(list(self.row))
|
|
self.row.clear()
|
|
|
|
|
|
#self.dfs(self.waiter, 1, [])
|
|
|
|
#self.dfs(self.waiter, 3, [])
|
|
|
|
#self.bfs(self.waiter, 1, [])
|
|
self.bfs(self.waiter, 3, [])
|
|
|
|
#path = self.waiter.bfsFind([self.waiter.positionX, self.waiter.positionY], [], 1)
|
|
|
|
while True:
|
|
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
sys.exit(0)
|
|
|
|
self.draw()
|
|
self.waiter.move(self)
|
|
#print(self.waiter.checkPoss(self.grid, self.waiter.lastStep))
|
|
|
|
#print(self.waiterNumberInGrid)
|
|
self.fpsClock.tick(10)
|
|
|
|
def draw(self):
|
|
tempTable = []
|
|
for row in self.grid:
|
|
for gridElement in row:
|
|
if gridElement.type == "gridElement":
|
|
gridElement.draw()
|
|
else:
|
|
tempTable.append(gridElement)
|
|
for otherElement in tempTable:
|
|
otherElement.draw()
|
|
pygame.display.flip()
|
|
|
|
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)
|
|
|
|
def dfs(self, waiter, soughtID, operation=[]):
|
|
visited = []
|
|
waiter.dfsFind([waiter.positionX, waiter.positionY], operation, visited, soughtID)
|
|
paths = waiter.dfsPaths
|
|
paths.sort(key=len)
|
|
print("Wszystkie sciezki dfs: ", paths)
|
|
bestPath = paths[0]
|
|
waiter.dfsPaths = []
|
|
waiter.followThePath(bestPath)
|
|
|
|
def bfs(self, waiter, soughtID, operation=[]):
|
|
waiter.bfsFind([waiter.positionX, waiter.positionY], operation, [], soughtID)
|
|
paths = waiter.bfsPaths
|
|
paths.sort(key=len)
|
|
print("Wszystkie sciezki bfs: ", paths)
|
|
bestPath = paths[0]
|
|
waiter.bfsPaths = []
|
|
waiter.followThePath(bestPath)
|
|
|
|
if __name__ == "__main__":
|
|
v1 = Game()
|
|
|