forked from s444417/ProjektAI
kitchenManager and Kitchen class added
This commit is contained in:
parent
7b4d017549
commit
90a9644a32
@ -2,10 +2,7 @@
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.7 (ProjektAI) (4)" jdkType="Python SDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TestRunnerService">
|
||||
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
|
||||
</component>
|
||||
</module>
|
@ -3,5 +3,5 @@
|
||||
<component name="JavaScriptSettings">
|
||||
<option name="languageLevel" value="ES6" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (ProjektAI) (4)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 (ProjektAI)" project-jdk-type="Python SDK" />
|
||||
</project>
|
BIN
kelner/images/kitchen.png
Normal file
BIN
kelner/images/kitchen.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 140 KiB |
@ -2,6 +2,7 @@ import pygame
|
||||
from kelner.src.components.GridBoard import GridBoard
|
||||
from kelner.src.components.Waiter import Waiter
|
||||
from kelner.src.components.Table import Table
|
||||
from kelner.src.components.Kitchen import Kitchen
|
||||
from kelner.src.managers.DrawableCollection import DrawableCollection
|
||||
from kelner.src.managers.MenuManager import MenuManager
|
||||
from kelner.src.managers.TableManager import TableManager
|
||||
@ -61,19 +62,24 @@ else:
|
||||
print("test4: fail")
|
||||
|
||||
|
||||
|
||||
# initialize waiter component
|
||||
waiter1 = Waiter(0, 0, 0, GridCountX - 1, 0, GridCountY - 1, CellSize, PaintOffset)
|
||||
waiter2 = Waiter(0, GridCountY - 1, 0, GridCountX - 1, 0, GridCountY - 1, CellSize, PaintOffset)
|
||||
waiter3 = Waiter(GridCountX - 1, 0, 0, GridCountX - 1, 0, GridCountY - 1, CellSize, PaintOffset)
|
||||
waiter4 = Waiter(GridCountX - 1, GridCountY - 1, 0, GridCountX - 1, 0, GridCountY - 1, CellSize, PaintOffset)
|
||||
# waiter2 = Waiter(0, GridCountY - 1, 0, GridCountX - 1, 0, GridCountY - 1, CellSize, PaintOffset)
|
||||
# waiter3 = Waiter(GridCountX - 1, 0, 0, GridCountX - 1, 0, GridCountY - 1, CellSize, PaintOffset)
|
||||
# waiter4 = Waiter(GridCountX - 1, GridCountY - 1, 0, GridCountX - 1, 0, GridCountY - 1, CellSize, PaintOffset)
|
||||
|
||||
|
||||
# adds waiter to drawable collection
|
||||
drawableManager.add(waiter1)
|
||||
drawableManager.add(waiter2)
|
||||
drawableManager.add(waiter3)
|
||||
drawableManager.add(waiter4)
|
||||
# drawableManager.add(waiter2)
|
||||
# drawableManager.add(waiter3)
|
||||
# drawableManager.add(waiter4)
|
||||
|
||||
|
||||
# TODO: create kitchen
|
||||
#kitchen = Kitchen(5, GridCountX-5, 5, GridCountY-5, CellSize, PaintOffset)
|
||||
#drawableManager.add(kitchen)
|
||||
|
||||
#My comment
|
||||
# initialize a number of tables given in range
|
||||
for i in range(0, 40):
|
||||
@ -89,14 +95,14 @@ tableTask.start()
|
||||
waiter1Task = WaiterManager(drawableManager, [waiter1])
|
||||
waiter1Task.start()
|
||||
|
||||
waiter2Task = WaiterManager(drawableManager, [waiter2])
|
||||
waiter2Task.start()
|
||||
|
||||
waiter3Task = WaiterManager(drawableManager, [waiter3])
|
||||
waiter3Task.start()
|
||||
|
||||
waiter4Task = WaiterManager(drawableManager, [waiter4])
|
||||
waiter4Task.start()
|
||||
# waiter2Task = WaiterManager(drawableManager, [waiter2])
|
||||
# waiter2Task.start()
|
||||
#
|
||||
# waiter3Task = WaiterManager(drawableManager, [waiter3])
|
||||
# waiter3Task.start()
|
||||
#
|
||||
# waiter4Task = WaiterManager(drawableManager, [waiter4])
|
||||
# waiter4Task.start()
|
||||
|
||||
# main loop
|
||||
running = True
|
||||
@ -106,9 +112,9 @@ while running:
|
||||
if event.type == pygame.QUIT:
|
||||
tableTask.stop()
|
||||
waiter1Task.stop()
|
||||
waiter2Task.stop()
|
||||
waiter3Task.stop()
|
||||
waiter4Task.stop()
|
||||
# waiter2Task.stop()
|
||||
# waiter3Task.stop()
|
||||
# waiter4Task.stop()
|
||||
running = False
|
||||
|
||||
# handles keyboard events
|
||||
|
@ -1,3 +1,6 @@
|
||||
from kelner.src.managers.ImageCache import ImageCache, Images
|
||||
|
||||
|
||||
class Drawable:
|
||||
|
||||
def __init__(self, x, y, minX, maxX, minY, maxY, cellSize, offset):
|
||||
@ -56,3 +59,12 @@ class Drawable:
|
||||
|
||||
def drawAux(self, screen):
|
||||
pass
|
||||
|
||||
def getImage(self, imageKind):
|
||||
if imageKind in [Images.Guest1, Images.Guest2, Images.Guest3, Images.Plate]:
|
||||
size = int(self.getCellSize() / 3)
|
||||
elif imageKind in [Images.Kitchen]:
|
||||
size = int(self.getCellSize())
|
||||
else:
|
||||
size = int(1.4 * self.getCellSize())
|
||||
return ImageCache.getInstance().getImage(imageKind, size, size)
|
||||
|
32
kelner/src/components/Kitchen.py
Normal file
32
kelner/src/components/Kitchen.py
Normal file
@ -0,0 +1,32 @@
|
||||
import random
|
||||
from enum import Enum
|
||||
from threading import Lock
|
||||
from kelner.src.components.Drawable import Drawable
|
||||
from kelner.src.managers.ImageCache import ImageCache, Images
|
||||
from kelner.src.algorithms.DecisionTree import Tree_Builder
|
||||
import os
|
||||
|
||||
|
||||
class Kitchen(Drawable):
|
||||
def __init__(self, minX, maxX, minY, maxY, cellSize, offset):
|
||||
# call base class constructor
|
||||
super().__init__(0, 0, minX, maxX, minY, maxY, cellSize, offset)
|
||||
self._preparing_orders = []
|
||||
self._ready_orders = []
|
||||
self._photos_path = os.path.join(os.getcwd(), 'foodImages')
|
||||
|
||||
def get_new_orders(self, orders):
|
||||
self._preparing_orders.append(orders)
|
||||
|
||||
def draw(self, screen):
|
||||
xBase = self.getX() * self.getCellSize() + self.getOffset()
|
||||
yBase = self.getY() * self.getCellSize() + self.getOffset()
|
||||
tableXYOffset = int(0.2 * self.getCellSize())
|
||||
image = self.getImage(Images.Kitchen)
|
||||
screen.blit(image, (xBase - tableXYOffset, yBase - tableXYOffset))
|
||||
|
||||
|
||||
def drawAux(self, screen):
|
||||
pass
|
||||
|
||||
|
@ -104,6 +104,9 @@ class Waiter(Drawable):
|
||||
# accepts orders from the table and stores them in queue
|
||||
def addOrder(self, table, order):
|
||||
self.__acceptedOrders += [(table, order)]
|
||||
|
||||
def getAcceptedOrders(self):
|
||||
return self.__acceptedOrders
|
||||
|
||||
def isPathEmpty(self):
|
||||
return self.__currentPath == []
|
||||
|
@ -21,6 +21,7 @@ class Images(Enum):
|
||||
Guest2 = 14
|
||||
Guest3 = 15
|
||||
ToolTip = 16
|
||||
Kitchen = 17
|
||||
|
||||
|
||||
class ImageCache:
|
||||
@ -56,7 +57,8 @@ class ImageCache:
|
||||
Images.Guest1: './images/wiking_blond.png',
|
||||
Images.Guest2: './images/wiking_rudy.png',
|
||||
Images.Guest3: './images/wiking_rudy2.png',
|
||||
Images.ToolTip: './images/tooltip.png'}
|
||||
Images.ToolTip: './images/tooltip.png',
|
||||
Images.Kitchen: './images/kitchen.png'}
|
||||
|
||||
def __getFont(self):
|
||||
if self.__font is None:
|
||||
|
23
kelner/src/managers/KitchenManager.py
Normal file
23
kelner/src/managers/KitchenManager.py
Normal file
@ -0,0 +1,23 @@
|
||||
import threading
|
||||
import time
|
||||
import sys
|
||||
|
||||
|
||||
# creates new thread
|
||||
class KitchenManager(threading.Thread):
|
||||
|
||||
def __init__(self, drawable_manager, images_storage):
|
||||
super().__init__()
|
||||
self._drawable_manager = drawable_manager
|
||||
self._runThread = True
|
||||
self._images_storage = images_storage
|
||||
|
||||
def prepare_dish(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
while self._runThread:
|
||||
pass
|
||||
|
||||
def stop(self):
|
||||
self._runThread = False
|
@ -20,7 +20,7 @@ class TableManager (threading.Thread):
|
||||
if tables:
|
||||
tableIndex = random.randint(0, len(tables) - 1)
|
||||
table = tables[tableIndex]
|
||||
time.sleep(3)
|
||||
time.sleep(5)
|
||||
table.setOrder(self.__menuManager.generateOrder())
|
||||
table.setStatus(Status.Ready)
|
||||
self.__drawableManager.forceRepaint()
|
||||
|
@ -82,16 +82,19 @@ class WaiterManager (threading.Thread):
|
||||
while self.__runThread:
|
||||
if self.__waiters:
|
||||
for waiter in self.__waiters:
|
||||
path = self.__getNearestTargetPath(waiter)
|
||||
waiter.setPath([] if path is None else path)
|
||||
if len(waiter.getAcceptedOrders()) < 5:
|
||||
path = self.__getNearestTargetPath(waiter)
|
||||
waiter.setPath([] if path is None else path)
|
||||
|
||||
if not waiter.isPathEmpty():
|
||||
step = waiter.popStepFromPath()
|
||||
self.__changeWaiterDirection(waiter, step[0], step[1])
|
||||
self.__moveWaiter(waiter, step[0], step[1])
|
||||
if not waiter.isPathEmpty():
|
||||
step = waiter.popStepFromPath()
|
||||
self.__changeWaiterDirection(waiter, step[0], step[1])
|
||||
self.__moveWaiter(waiter, step[0], step[1])
|
||||
|
||||
if waiter.isPathEmpty():
|
||||
self.__collectOrder(waiter)
|
||||
if waiter.isPathEmpty():
|
||||
self.__collectOrder(waiter)
|
||||
else:
|
||||
waiter.goToKitchen()
|
||||
|
||||
def stop(self):
|
||||
self.__runThread = False
|
||||
|
Loading…
Reference in New Issue
Block a user