kitchenManager and Kitchen class added

This commit is contained in:
= 2020-05-11 20:42:17 +02:00
parent 7b4d017549
commit 90a9644a32
11 changed files with 111 additions and 33 deletions

View File

@ -2,10 +2,7 @@
<module type="PYTHON_MODULE" version="4"> <module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" /> <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" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module> </module>

View File

@ -3,5 +3,5 @@
<component name="JavaScriptSettings"> <component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" /> <option name="languageLevel" value="ES6" />
</component> </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> </project>

BIN
kelner/images/kitchen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

View File

@ -2,6 +2,7 @@ import pygame
from kelner.src.components.GridBoard import GridBoard from kelner.src.components.GridBoard import GridBoard
from kelner.src.components.Waiter import Waiter from kelner.src.components.Waiter import Waiter
from kelner.src.components.Table import Table 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.DrawableCollection import DrawableCollection
from kelner.src.managers.MenuManager import MenuManager from kelner.src.managers.MenuManager import MenuManager
from kelner.src.managers.TableManager import TableManager from kelner.src.managers.TableManager import TableManager
@ -61,19 +62,24 @@ else:
print("test4: fail") print("test4: fail")
# initialize waiter component # initialize waiter component
waiter1 = Waiter(0, 0, 0, GridCountX - 1, 0, GridCountY - 1, CellSize, PaintOffset) 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) # 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) # 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) # waiter4 = Waiter(GridCountX - 1, GridCountY - 1, 0, GridCountX - 1, 0, GridCountY - 1, CellSize, PaintOffset)
# adds waiter to drawable collection # adds waiter to drawable collection
drawableManager.add(waiter1) drawableManager.add(waiter1)
drawableManager.add(waiter2) # drawableManager.add(waiter2)
drawableManager.add(waiter3) # drawableManager.add(waiter3)
drawableManager.add(waiter4) # drawableManager.add(waiter4)
# TODO: create kitchen
#kitchen = Kitchen(5, GridCountX-5, 5, GridCountY-5, CellSize, PaintOffset)
#drawableManager.add(kitchen)
#My comment #My comment
# initialize a number of tables given in range # initialize a number of tables given in range
for i in range(0, 40): for i in range(0, 40):
@ -89,14 +95,14 @@ tableTask.start()
waiter1Task = WaiterManager(drawableManager, [waiter1]) waiter1Task = WaiterManager(drawableManager, [waiter1])
waiter1Task.start() waiter1Task.start()
waiter2Task = WaiterManager(drawableManager, [waiter2]) # waiter2Task = WaiterManager(drawableManager, [waiter2])
waiter2Task.start() # waiter2Task.start()
#
waiter3Task = WaiterManager(drawableManager, [waiter3]) # waiter3Task = WaiterManager(drawableManager, [waiter3])
waiter3Task.start() # waiter3Task.start()
#
waiter4Task = WaiterManager(drawableManager, [waiter4]) # waiter4Task = WaiterManager(drawableManager, [waiter4])
waiter4Task.start() # waiter4Task.start()
# main loop # main loop
running = True running = True
@ -106,9 +112,9 @@ while running:
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
tableTask.stop() tableTask.stop()
waiter1Task.stop() waiter1Task.stop()
waiter2Task.stop() # waiter2Task.stop()
waiter3Task.stop() # waiter3Task.stop()
waiter4Task.stop() # waiter4Task.stop()
running = False running = False
# handles keyboard events # handles keyboard events

View File

@ -1,3 +1,6 @@
from kelner.src.managers.ImageCache import ImageCache, Images
class Drawable: class Drawable:
def __init__(self, x, y, minX, maxX, minY, maxY, cellSize, offset): def __init__(self, x, y, minX, maxX, minY, maxY, cellSize, offset):
@ -56,3 +59,12 @@ class Drawable:
def drawAux(self, screen): def drawAux(self, screen):
pass 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)

View 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

View File

@ -105,6 +105,9 @@ class Waiter(Drawable):
def addOrder(self, table, order): def addOrder(self, table, order):
self.__acceptedOrders += [(table, order)] self.__acceptedOrders += [(table, order)]
def getAcceptedOrders(self):
return self.__acceptedOrders
def isPathEmpty(self): def isPathEmpty(self):
return self.__currentPath == [] return self.__currentPath == []

View File

@ -21,6 +21,7 @@ class Images(Enum):
Guest2 = 14 Guest2 = 14
Guest3 = 15 Guest3 = 15
ToolTip = 16 ToolTip = 16
Kitchen = 17
class ImageCache: class ImageCache:
@ -56,7 +57,8 @@ class ImageCache:
Images.Guest1: './images/wiking_blond.png', Images.Guest1: './images/wiking_blond.png',
Images.Guest2: './images/wiking_rudy.png', Images.Guest2: './images/wiking_rudy.png',
Images.Guest3: './images/wiking_rudy2.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): def __getFont(self):
if self.__font is None: if self.__font is None:

View 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

View File

@ -20,7 +20,7 @@ class TableManager (threading.Thread):
if tables: if tables:
tableIndex = random.randint(0, len(tables) - 1) tableIndex = random.randint(0, len(tables) - 1)
table = tables[tableIndex] table = tables[tableIndex]
time.sleep(3) time.sleep(5)
table.setOrder(self.__menuManager.generateOrder()) table.setOrder(self.__menuManager.generateOrder())
table.setStatus(Status.Ready) table.setStatus(Status.Ready)
self.__drawableManager.forceRepaint() self.__drawableManager.forceRepaint()

View File

@ -82,6 +82,7 @@ class WaiterManager (threading.Thread):
while self.__runThread: while self.__runThread:
if self.__waiters: if self.__waiters:
for waiter in self.__waiters: for waiter in self.__waiters:
if len(waiter.getAcceptedOrders()) < 5:
path = self.__getNearestTargetPath(waiter) path = self.__getNearestTargetPath(waiter)
waiter.setPath([] if path is None else path) waiter.setPath([] if path is None else path)
@ -92,6 +93,8 @@ class WaiterManager (threading.Thread):
if waiter.isPathEmpty(): if waiter.isPathEmpty():
self.__collectOrder(waiter) self.__collectOrder(waiter)
else:
waiter.goToKitchen()
def stop(self): def stop(self):
self.__runThread = False self.__runThread = False