Stoły mają 4 stany. Status gotowy do złożenia zamówienia ustawiany jest w nowym wątku w klasie TaskManager co 3 sekundy dla jednego stolika, kelner moze odbierać zamówienia od stolików gotowych do ich złożenia #4

Closed
s444417 wants to merge 1 commits from master into miki_branch
10 changed files with 180 additions and 60 deletions
Showing only changes of commit cd4d74b019 - Show all commits

View File

@ -2,7 +2,15 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="4be2149b-d9bc-4e21-8365-293320ae7f92" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/components/Drawable.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/components/Table.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/managers/DrawableCollection.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/images/20x20grid.png" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/images/bigWaiter.jpg" beforeDir="false" afterPath="$PROJECT_DIR$/images/bigWaiter.jpg" afterDir="false" />
<change beforePath="$PROJECT_DIR$/images/waiter.png" beforeDir="false" afterPath="$PROJECT_DIR$/images/waiter.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/GridBoard.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/GridBoard.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/Waiter.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/Waiter.py" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -91,6 +99,13 @@
<workItem from="1584889217128" duration="21436000" />
<workItem from="1584912093524" duration="666000" />
<workItem from="1584986159947" duration="1123000" />
<workItem from="1585006246801" duration="264000" />
<workItem from="1585247780368" duration="715000" />
<workItem from="1585257395176" duration="8541000" />
<workItem from="1585864729460" duration="241000" />
<workItem from="1585939347531" duration="8682000" />
<workItem from="1585948578229" duration="795000" />
<workItem from="1585950329643" duration="151000" />
</task>
<task id="LOCAL-00001" summary="klasa kelner">
<created>1584889744892</created>
@ -113,7 +128,14 @@
<option name="project" value="LOCAL" />
<updated>1584910685304</updated>
</task>
<option name="localTasksCounter" value="4" />
<task id="LOCAL-00004" summary="klasa kelner">
<created>1585257603366</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1585257603366</updated>
</task>
<option name="localTasksCounter" value="5" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -137,6 +159,6 @@
<option name="LAST_COMMIT_MESSAGE" value="klasa kelner" />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/kelner$main.coverage" NAME="main Coverage Results" MODIFIED="1584986397013" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/kelner$main.coverage" NAME="main Coverage Results" MODIFIED="1585950468781" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -1,6 +1,8 @@
import pygame
from src.components.GridBoard import GridBoard
from src.managers.DrawableCollection import DrawableCollection
from src.components.Waiter import Waiter
from src.components.Table import Table
#create screen consts
@ -13,10 +15,19 @@ ScreenHeight = CellSize * GridCountY #screen height in pixels
#initialize background
gridBoard = GridBoard(ScreenWidth, ScreenHeight, CellSize)
#initialize waiter component
waiter = Waiter(1, 1, 0, GridCountX - 1, 0, GridCountY - 1, CellSize)
#initialize drawable objects manager
drawableManager = DrawableCollection()
#loop
#initialize waiter component
waiter = Waiter(0, 0, 0, GridCountX - 1, 0, GridCountY - 1, CellSize)
#initialize a number of tables given in range
for i in range(1, 15):
table = Table(0, GridCountX - 1, 0, GridCountY - 1, CellSize)
drawableManager.generatePosition(table)
drawableManager.add(table)
#main loop
doRepaint = True
running = True
while running:
@ -25,19 +36,31 @@ while running:
if event.type == pygame.QUIT:
running = False
#handles keyboard events
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
waiter.moveLeft()
#checks if new waiter's position to the left is not occupied by other object
if drawableManager.isPositionAvailable(waiter.getX() - 1, waiter.getY()):
waiter.moveLeft()
if event.key == pygame.K_RIGHT:
waiter.moveRight()
# checks if new waiter's position to the right is not occupied by other object
if drawableManager.isPositionAvailable(waiter.getX() + 1, waiter.getY()):
waiter.moveRight()
if event.key == pygame.K_UP:
waiter.moveUp()
# checks if new waiter's position up is not occupied by other object
if drawableManager.isPositionAvailable(waiter.getX(), waiter.getY() - 1):
waiter.moveUp()
if event.key == pygame.K_DOWN:
waiter.moveDown()
# checks if new waiter's position down is not occupied by other object
if drawableManager.isPositionAvailable(waiter.getX(), waiter.getY() + 1):
waiter.moveDown()
doRepaint = True
# repaints all objects to the screen
#is set only on initial paint or after keyboard event
if doRepaint:
gridBoard.reinitialize()
gridBoard.draw(drawableManager)
gridBoard.draw(waiter)
gridBoard.udpdate()
doRepaint = False

View File

@ -0,0 +1,52 @@
class Drawable:
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
def __init__(self, x, y, minX, maxX, minY, maxY, ratio):
self.__minX = minX
self.__maxX = maxX
self.__minY = minY
self.__maxY = maxY
self.setX(x)
self.setY(y)
self.__ratio = ratio #cell size
def setX(self, x):
if (x < self.__minX or self.__maxX < x):
return False
else:
self.__x = x
return True
def setY(self, y):
if (y < self.__minY or self.__maxY < y):
return False
else:
self.__y = y
return True
def getX(self):
return self.__x
def getY(self):
return self.__y
def getMinX(self):
return self.__minX
def getMaxX(self):
return self.__maxX
def getMinY(self):
return self.__minY
def getMaxY(self):
return self.__maxY
def getRatio(self):
return self.__ratio
def draw(self, screen):
pass

View File

@ -8,8 +8,9 @@ class GridBoard:
self.__width = width
self.__height = height
self.__cellSize = cellSize
self.__screen = pygame.display.set_mode((width, height)) #initialize screen
self.__screen = pygame.display.set_mode((width, height)) # initialize screen
#fills the screen with white and draws grid
def reinitialize(self):
self.__screen.fill((255, 255, 255))
for x in range(0, self.__width, self.__cellSize):
@ -17,8 +18,10 @@ class GridBoard:
for y in range(0, self.__height, self.__cellSize):
pygame.draw.line(self.__screen, (0,0,0), (0,y), ((self.__width - 1),y))
#draws object on screen
def draw(self, component):
component.draw(self.__screen)
#updates screen
def udpdate(self):
pygame.display.update()

View File

@ -0,0 +1,14 @@
import pygame
import random
from .Drawable import Drawable
class Table(Drawable):
def __init__(self, minX, maxX, minY, maxY, ratio):
#call base class constructor
Drawable.__init__(self, 0, 0, minX, maxX, minY, maxY, ratio)
def draw(self, screen):
pygame.draw.circle(screen, self.GREEN, ((self.getX() * self.getRatio()) + (self.getRatio() // 2),
(self.getY() * self.getRatio()) + (self.getRatio() // 2)),
(self.getRatio() // 3))

View File

@ -1,74 +1,37 @@
import pygame
from .Drawable import Drawable
class Waiter:
class Waiter(Drawable):
def __init__(self, x, y, minX, maxX, minY, maxY, ratio):
self.__minX = minX
self.__maxX = maxX
self.__minY = minY
self.__maxY = maxY
self.setX(x)
self.setY(y)
self.__ratio = ratio #cell size
#call base class constructor
Drawable.__init__(self, x, y, minX, maxX, minY, maxY, ratio)
self.__image = self.__loadImg('./images/waiter.png')
def setX(self, x):
if (x < self.__minX or self.__maxX < x):
return False
else:
self.__x = x
return True
def setY(self, y):
if (y < self.__minY or self.__maxY < y):
return False
else:
self.__y = y
return True
def getX(self):
return self.__x
def getY(self):
return self.__y
def getXmin(self):
return self.__minX
def getXmax(self):
return self.__maxX
def getYmin(self):
return self.__minY
def getYmax(self):
return self.__maxY
def moveUp(self):
if self.__y > self.__minY:
self.__y -= 1
if self.getY() > self.getMinY():
self.setY(self.getY() - 1)
return True
else:
return False
def moveDown(self):
if self.__y < self.__maxY:
self.__y += 1
if self.getY() < self.getMaxY():
self.setY(self.getY() + 1)
return True
else:
return False
def moveLeft(self):
if self.__x > self.__minX:
self.__x -= 1
if self.getX() > self.getMinX():
self.setX(self.getX() - 1)
return True
else:
return False
def moveRight(self):
if self.__x < self.__maxX:
self.__x += 1
if self.getX() < self.getMaxX():
self.setX(self.getX() + 1)
return True
else:
return False
@ -77,4 +40,4 @@ class Waiter:
return pygame.image.load(filePath)
def draw(self, screen):
screen.blit(self.__image, (self.__x * self.__ratio, self.__y * self.__ratio))
screen.blit(self.__image, (self.getX() * self.getRatio(), self.getY() * self.getRatio()))

View File

@ -0,0 +1,43 @@
import random
#drawable objects manager
class DrawableCollection:
#const, minimal distance between objects
__MinDistance = 1
def __init__(self):
#collection that holds all drawable objects
self.__drawables = []
#adds drawable objects to the collection
def add(self, drawable):
self.__drawables.append(drawable)
#generates and sets random x, y and cheks if it's not occupied by other object
def generatePosition(self, drawable):
isPositionUnique = False
while not isPositionUnique:
x = random.randint(drawable.getMinX() + 1, drawable.getMaxX() - 1)
y = random.randint(drawable.getMinY() + 1, drawable.getMaxY() - 1)
isPositionUnique = True
for item in self.__drawables:
if abs(item.getX() - x) <= self.__MinDistance and abs(item.getY() - y) <= self.__MinDistance:
isPositionUnique = False
break
if isPositionUnique:
drawable.setX(x)
drawable.setY(y)
#draws all objects stored in collection
def draw(self, screen):
for item in self.__drawables:
item.draw(screen)
#checks if position (x,y) is not occupied by other object
def isPositionAvailable(self, x, y):
isPositionAvailable = True
for item in self.__drawables:
if item.getX() == x and item.getY() == y:
isPositionAvailable = False
break
return isPositionAvailable