Compare commits

..

No commits in common. "plansza-podstawy" and "master" have entirely different histories.

23 changed files with 244 additions and 685 deletions

View File

@ -3,8 +3,7 @@
<component name="ChangeListManager">
<list default="true" id="152ea650-8e02-4ed6-aa8c-04d44b275be4" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Images/stolikJedznie.png" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/savedPaths.txt" beforeDir="false" afterPath="$PROJECT_DIR$/savedPaths.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/game.py" beforeDir="false" afterPath="$PROJECT_DIR$/game.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/waiter.py" beforeDir="false" afterPath="$PROJECT_DIR$/waiter.py" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -18,7 +17,7 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/order.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="132">
<state>
<caret line="6" selection-start-line="6" selection-end-line="6" />
</state>
</provider>
@ -27,8 +26,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/game.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="792">
<caret line="69" column="62" selection-start-line="69" selection-start-column="62" selection-end-line="69" selection-end-column="62" />
<state relative-caret-position="1475">
<caret line="59" column="26" selection-start-line="59" selection-start-column="19" selection-end-line="59" selection-end-column="26" />
<folding>
<element signature="e#0#18#0" expanded="true" />
</folding>
@ -36,16 +35,11 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/Images/tableSmall.png">
<provider selected="true" editor-type-id="images" />
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/gridElement.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="154">
<caret line="7" column="17" selection-start-line="7" selection-start-column="17" selection-end-line="7" selection-end-column="17" />
<state>
<caret line="14" column="59" selection-start-line="14" selection-start-column="59" selection-end-line="14" selection-end-column="59" />
</state>
</provider>
</entry>
@ -53,8 +47,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/table.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="72">
<caret line="10" column="6" selection-start-line="10" selection-start-column="6" selection-end-line="10" selection-end-column="6" />
<state>
<caret line="14" column="15" selection-start-line="14" selection-start-column="15" selection-end-line="14" selection-end-column="15" />
</state>
</provider>
</entry>
@ -62,8 +56,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/pool.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="176">
<caret line="8" column="65" selection-start-line="8" selection-start-column="21" selection-end-line="8" selection-end-column="65" />
<state>
<caret line="9" column="26" selection-start-line="9" selection-start-column="26" selection-end-line="9" selection-end-column="26" />
<folding>
<element signature="e#0#13#0" expanded="true" />
</folding>
@ -74,8 +68,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/orderTable.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="198">
<caret line="9" column="45" lean-forward="true" selection-start-line="9" selection-start-column="45" selection-end-line="9" selection-end-column="45" />
<state>
<caret line="17" column="58" selection-start-line="17" selection-start-column="58" selection-end-line="17" selection-end-column="58" />
</state>
</provider>
</entry>
@ -83,24 +77,15 @@
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/waiter.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="437">
<caret line="447" column="26" lean-forward="true" selection-start-line="447" selection-start-column="26" selection-end-line="447" selection-end-column="26" />
<state relative-caret-position="402">
<caret line="249" column="18" lean-forward="true" selection-start-line="249" selection-start-column="18" selection-end-line="249" selection-end-column="18" />
<folding>
<element signature="e#0#14#0" expanded="true" />
<element signature="e#0#13#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/wasteTable.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret column="13" lean-forward="true" selection-start-column="13" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
@ -110,14 +95,6 @@
</list>
</option>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>self.last</find>
<find>tmp</find>
<find>visited</find>
<find>drow</find>
</findStrings>
</component>
<component name="Git.Settings">
<option name="PREVIOUS_COMMIT_AUTHORS">
<list>
@ -125,14 +102,6 @@
</list>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="plansza-podstawy" />
</map>
</option>
</component>
<component name="HierarchyBrowserManager">
<option name="SORT_ALPHABETICALLY" value="true" />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
@ -142,19 +111,19 @@
<option value="$PROJECT_DIR$/gridElement.py" />
<option value="$PROJECT_DIR$/run.py" />
<option value="$PROJECT_DIR$/order.py" />
<option value="$PROJECT_DIR$/pool.py" />
<option value="$PROJECT_DIR$/table.py" />
<option value="$PROJECT_DIR$/orderTable.py" />
<option value="$PROJECT_DIR$/wasteTable.py" />
<option value="$PROJECT_DIR$/pool.py" />
<option value="$PROJECT_DIR$/game.py" />
<option value="$PROJECT_DIR$/waiter.py" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="-7" />
<option name="width" value="1660" />
<option name="height" value="1047" />
<option name="x" value="716" />
<option name="y" value="77" />
<option name="width" value="970" />
<option name="height" value="1050" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
@ -185,7 +154,7 @@
</component>
<component name="PropertiesComponent">
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="settings.editor.selected.configurable" value="xml.catalog" />
<property name="settings.editor.selected.configurable" value="editor.preferences.fonts.default" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
@ -288,20 +257,20 @@
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
<editor active="true" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.13382508" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.18124342" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32936078" />
<window_info active="true" anchor="bottom" id="Run" order="2" sideWeight="0.49894625" visible="true" weight="0.2979415" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.2708559" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info active="true" anchor="bottom" id="Run" order="2" sideWeight="0.49894625" visible="true" weight="0.29577464" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.3997833" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" weight="0.32936078" />
<window_info anchor="bottom" id="Version Control" order="7" sideWeight="0.49947312" weight="0.32936078" />
<window_info anchor="bottom" id="Terminal" order="8" weight="0.32936078" />
<window_info anchor="bottom" id="Event Log" order="9" sideWeight="0.50105375" side_tool="true" weight="0.32936078" />
<window_info anchor="bottom" id="Python Console" order="10" weight="0.32936078" />
<window_info anchor="bottom" id="Python Console" order="10" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
@ -349,31 +318,6 @@
<MESSAGE value="Lada i skromne kolizje" />
<option name="LAST_COMMIT_MESSAGE" value="Lada i skromne kolizje" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<default-breakpoints>
<breakpoint type="python-exception">
<properties notifyOnTerminate="true" exception="BaseException">
<option name="notifyOnTerminate" value="true" />
</properties>
</breakpoint>
</default-breakpoints>
</breakpoint-manager>
<watches-manager>
<configuration name="PythonConfigurationType">
<watch expression="grid" language="Python" />
</configuration>
</watches-manager>
</component>
<component name="debuggerHistoryManager">
<expressions id="watch">
<expression>
<expression-string>grid</expression-string>
<language-id>Python</language-id>
<evaluation-mode>EXPRESSION</evaluation-mode>
</expression>
</expressions>
</component>
<component name="editorHistoryManager">
<entry file="file://$USER_HOME$/Desktop/pygame-elsa/sprites/olaf.py">
<provider selected="true" editor-type-id="text-editor">
@ -385,6 +329,13 @@
<entry file="file://$PROJECT_DIR$/Images/waiter.jpg">
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file://$APPLICATION_HOME_DIR$/helpers/pydev/pydevd.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="168">
<caret line="1134" selection-start-line="1134" selection-end-line="1134" />
</state>
</provider>
</entry>
<entry file="file://$APPLICATION_HOME_DIR$/helpers/pydev/_pydev_imps/_pydev_execfile.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289">
@ -414,6 +365,9 @@
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file://$PROJECT_DIR$/run.py" />
<entry file="file://$PROJECT_DIR$/Images/tableSmall.png">
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file://$PROJECT_DIR$/Images/water.jpg">
<provider selected="true" editor-type-id="images" />
</entry>
@ -430,84 +384,60 @@
<entry file="file://$PROJECT_DIR$/Images/tlo.jpg">
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file://$USER_HOME$/.PyCharmCE2018.3/system/python_stubs/-258859485/builtins.py">
<entry file="file://$PROJECT_DIR$/order.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="299">
<caret line="3704" column="8" selection-start-line="3704" selection-start-column="8" selection-end-line="3704" selection-end-column="8" />
<state>
<caret line="6" selection-start-line="6" selection-end-line="6" />
</state>
</provider>
</entry>
<entry file="file://$APPLICATION_HOME_DIR$/helpers/pydev/pydevd.py">
<entry file="file://$PROJECT_DIR$/gridElement.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="448">
<caret line="1740" selection-start-line="1740" selection-end-line="1740" />
<state>
<caret line="14" column="59" selection-start-line="14" selection-start-column="59" selection-end-line="14" selection-end-column="59" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/table.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret line="14" column="15" selection-start-line="14" selection-start-column="15" selection-end-line="14" selection-end-column="15" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/pool.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="176">
<caret line="8" column="65" selection-start-line="8" selection-start-column="21" selection-end-line="8" selection-end-column="65" />
<state>
<caret line="9" column="26" selection-start-line="9" selection-start-column="26" selection-end-line="9" selection-end-column="26" />
<folding>
<element signature="e#0#13#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/Images/tableSmall.png">
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file://$PROJECT_DIR$/orderTable.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="198">
<caret line="9" column="45" lean-forward="true" selection-start-line="9" selection-start-column="45" selection-end-line="9" selection-end-column="45" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/wasteTable.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret column="13" lean-forward="true" selection-start-column="13" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/gridElement.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="154">
<caret line="7" column="17" selection-start-line="7" selection-start-column="17" selection-end-line="7" selection-end-column="17" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/table.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="72">
<caret line="10" column="6" selection-start-line="10" selection-start-column="6" selection-end-line="10" selection-end-column="6" />
<caret line="17" column="58" selection-start-line="17" selection-start-column="58" selection-end-line="17" selection-end-column="58" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/game.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="792">
<caret line="69" column="62" selection-start-line="69" selection-start-column="62" selection-end-line="69" selection-end-column="62" />
<state relative-caret-position="1475">
<caret line="59" column="26" selection-start-line="59" selection-start-column="19" selection-end-line="59" selection-end-column="26" />
<folding>
<element signature="e#0#18#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/order.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="132">
<caret line="6" selection-start-line="6" selection-end-line="6" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/waiter.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="437">
<caret line="447" column="26" lean-forward="true" selection-start-line="447" selection-start-column="26" selection-end-line="447" selection-end-column="26" />
<state relative-caret-position="402">
<caret line="249" column="18" lean-forward="true" selection-start-line="249" selection-start-column="18" selection-end-line="249" selection-end-column="18" />
<folding>
<element signature="e#0#14#0" expanded="true" />
<element signature="e#0#13#0" expanded="true" />
</folding>
</state>
</provider>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

86
game.py
View File

@ -1,13 +1,10 @@
import pygame, sys, random
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
from wasteTable import WasteTable
from operator import attrgetter
import copy
class Game(object):
def __init__(self):
@ -28,57 +25,29 @@ class Game(object):
self.grid = []
self.row = []
self.tableList = []
self.orderTableList = []
# TWORZENIE ELEMENTÓW PLANSZY
for b in range(self.y):
for i in range(self.x):
if ((i == 0) or (i == 9)) and ((b == 0) or (b == 6)):
tmp = random.randint(0, 3)
table = Table(i * 50, b * 50, self)
if tmp == 1:
table.isOrdering = True
elif tmp == 2:
table.isWaiting = True
elif tmp == 3:
table.isClean = False
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 (b == self.y-1 or b == self.y-2 or b == self.y-3) and (i == 5):
orderTable = OrderTable(i * 50, b * 50, self)
self.row.append(orderTable)
self.orderTableList.append(orderTable)
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 and not (b == 3) and not (i==3 and b==9):
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) ):
self.row.append(Pool(i * 50, b * 50, self))
elif i == 3 and b == 9:
self.row.append(WasteTable(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()
#Wydawka jedzenia
for table in self.tableList:
if table.isWaiting:
self.orderTableList[0].hasDish = True
self.orderTableList.sort(key=attrgetter("hasDish"))
#self.dfs(self.waiter, 1, [])
#self.dfs(self.waiter, 3, [])
self.bfs(self.waiter, 1, [])
self.bfs(self.waiter, 4, [])
#path = self.waiter.bfsFind([self.waiter.positionX, self.waiter.positionY], [], 1)
# GŁÓWNA PĘTLA GRY
self.waiter.dfsFind(self, self.waiter.lastStep, 1)
while True:
for event in pygame.event.get():
@ -87,12 +56,11 @@ class Game(object):
self.draw()
self.waiter.move(self)
#print(self.waiter.checkPoss(self.grid, self.waiter.lastStep))
print(self.waiter.checkPoss(self, self.waiter.lastStep))
pygame.display.flip()
#print(self.waiterNumberInGrid)
self.fpsClock.tick(10)
# WYRYSOWANIE KAZDEGO ELEMENTU Z GRIDU NA EKRAN
def draw(self):
tempTable = []
for row in self.grid:
@ -103,7 +71,6 @@ class Game(object):
tempTable.append(gridElement)
for otherElement in tempTable:
otherElement.draw()
pygame.display.flip()
def convert(self, object):
if object.type == "gridElement":
@ -116,9 +83,6 @@ class Game(object):
return 'O'
elif object.type == "pool":
return 'P'
elif object.type == "wasteTable":
return 'Z'
def showGrid(self, grid):
charakterList = []
@ -128,33 +92,7 @@ class Game(object):
charakterList.append(row)
print(row)
# ZNAJDUJE NAJKRÓTSZĄ ŚCIEŻKĘ DFS I PRZECHODZI WEDŁUG LISTY KROKÓW
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)
if paths:
bestPath = paths[0]
waiter.dfsPaths = []
waiter.followThePath(bestPath)
# ZNAJDUJE NAJKRÓTSZĄ ŚCIEŻKĘ BFS I PRZECHODZI WEDŁUG LISTY KROKÓW
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)
if paths:
bestPath = paths[0]
savedPaths = open("savedPaths.txt", "a+")
print(str(bestPath))
savedPaths.write(str(bestPath) + "\n")
waiter.bfsPaths = []
waiter.bfsQueue = []
waiter.followThePath(bestPath)
savedPaths.close()
if __name__ == "__main__":
v1 = Game()
Game()

View File

@ -12,11 +12,7 @@ class OrderTable(object):
self.y = y
self.image = pygame.image.load("./Images/drewno.jpg")
self.type = "orderTable"
self.hasDish = False
def draw(self):
self.rect = pygame.Rect(self.x, self.y, 50, 50)
if self.hasDish:
self.game.screen.blit(pygame.image.load("./Images/ladaJedzenie.png"),(self.x, self.y))
else:
self.game.screen.blit(self.image, (self.x, self.y))
self.game.screen.blit(self.image,(self.x, self.y))

View File

@ -1,77 +0,0 @@
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left', 'Up', 'Up']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']

View File

@ -11,25 +11,12 @@ class Table(object):
game.idTable += 1
game.idItem += 1
self.number = game.idItem
self.isWaiting = False
self.isClean = True
self.isOrdering = False
self.hasDish = False
self.isBusy = False
self.id = game.idTable
self.image = pygame.image.load("./Images/stolik.png")
#self.image = pygame.transform.scale(self.image, (50, 50))
self.image = pygame.image.load("./Images/tableSmall.png")
self.type = "table"
def draw(self):
self.table = pygame.Rect(self.x, self.y, 50, 50)
pygame.draw.rect(self.game.screen, (100, 0, 100), self.table)
if self.isOrdering:
self.game.screen.blit(pygame.image.load("./Images/stolikSkladaZamowienie.png"), (self.x, self.y))
elif self.isWaiting:
self.game.screen.blit(pygame.image.load("./Images/stolikOczekuje.png"), (self.x, self.y))
elif not self.isClean:
self.game.screen.blit(pygame.image.load("./Images/stolikBrudny.png"), (self.x, self.y))
elif self.hasDish:
self.game.screen.blit(pygame.image.load("./Images/stolikJedzenie.png"), (self.x, self.y))
else:
self.game.screen.blit((self.image), (self.x, self.y))
#self.game.screen.blit(self.image, (self.x, self.y))

539
waiter.py
View File

@ -1,15 +1,11 @@
import asyncio
from multiprocessing import Queue
import pygame
import time
from pygame.math import Vector2
class Waiter(object):
def __init__(self, game, x, y):
self.game = game
self.grid = game.grid
game.idItem += 1
self.size= self.game.screen.get_size()
self.x = x
@ -20,429 +16,236 @@ class Waiter(object):
self.image.set_colorkey((255, 255, 255))
self.type = "waiter"
self.lastStep = []
self.whatKeep = 0
self.dfsStack = []
self.dfsPaths = []
self.bfsQueue = []
self.bfsPaths = []
# NIEUZYWANA FUNKCJA ZNAJDOWANIA KELNERA NA PLANSZY; ZWRACA POZYCJĘ KELNERA
def findWaiter(self, grid):
for y in range(10):
for x in range(10):
if grid[y][x].type =="waiter":
#print(x,y)
return [x, y]
def moveLeft(self):
def moveLeft(self, game):
if self.positionX != 0:
collisionObject = self.game.grid[self.positionY][self.positionX - 1]
collisionObject = game.grid[self.positionY][self.positionX - 1]
if collisionObject.type == "gridElement":
self.game.grid[self.positionY][self.positionX - 1].x += 50
self.game.grid[self.positionY][self.positionX].x -= 50
self.game.grid[self.positionY][self.positionX - 1], \
self.game.grid[self.positionY][self.positionX] = \
self.game.grid[self.positionY][self.positionX], \
self.game.grid[self.positionY][self.positionX - 1]
game.grid[self.positionY][self.positionX - 1].x += 50
game.grid[self.positionY][self.positionX].x -= 50
game.grid[self.positionY][self.positionX - 1], \
game.grid[self.positionY][self.positionX] = \
game.grid[self.positionY][self.positionX], \
game.grid[self.positionY][self.positionX - 1]
self.positionX -= 1
#print(self.positionX)
self.lastStep.append("Left")
else:
self.work(collisionObject)
def moveRight(self):
if self.positionX != self.game.x-1:
collisionObject = self.game.grid[self.positionY][self.positionX + 1]
pass
def moveRight(self, game):
if self.positionX != game.x-1:
collisionObject = game.grid[self.positionY][self.positionX + 1]
if collisionObject.type == "gridElement":
self.game.grid[self.positionY][self.positionX + 1].x -= 50
self.game.grid[self.positionY][self.positionX].x += 50
self.game.grid[self.positionY][self.positionX + 1], \
self.game.grid[self.positionY][self.positionX] = \
self.game.grid[self.positionY][self.positionX], \
self.game.grid[self.positionY][self.positionX + 1]
game.grid[self.positionY][self.positionX + 1].x -= 50
game.grid[self.positionY][self.positionX].x += 50
game.grid[self.positionY][self.positionX + 1], \
game.grid[self.positionY][self.positionX] = \
game.grid[self.positionY][self.positionX], \
game.grid[self.positionY][self.positionX + 1]
self.positionX += 1
#print(self.positionX)
self.lastStep.append("Right")
else:
self.work(collisionObject)
pass
def moveUp(self):
def moveUp(self, game):
if self.positionY != 0:
collisionObject = self.game.grid[self.positionY - 1][self.positionX]
collisionObject = game.grid[self.positionY - 1][self.positionX]
if collisionObject.type == "gridElement":
self.game.grid[self.positionY - 1][self.positionX].y += 50
self.game.grid[self.positionY][self.positionX].y -= 50
self.game.grid[self.positionY - 1][self.positionX], \
self.game.grid[self.positionY][self.positionX] = \
self.game.grid[self.positionY][self.positionX], \
self.game.grid[self.positionY - 1][self.positionX]
game.grid[self.positionY - 1][self.positionX].y += 50
game.grid[self.positionY][self.positionX].y -= 50
game.grid[self.positionY - 1][self.positionX], \
game.grid[self.positionY][self.positionX] = \
game.grid[self.positionY][self.positionX], \
game.grid[self.positionY - 1][self.positionX]
self.positionY -= 1
self.lastStep.append("Up")
else:
self.work(collisionObject)
pass
def moveDown(self):
if self.positionY != self.game.y-1:
collisionObject = self.game.grid[self.positionY + 1][self.positionX]
def moveDown(self, game):
if self.positionY != game.y-1:
collisionObject = game.grid[self.positionY + 1][self.positionX]
if collisionObject.type == "gridElement":
self.game.grid[self.positionY + 1][self.positionX].y -= 50
self.game.grid[self.positionY][self.positionX].y += 50
self.game.grid[self.positionY + 1][self.positionX], \
self.game.grid[self.positionY][self.positionX] = \
self.game.grid[self.positionY][self.positionX], \
self.game.grid[self.positionY + 1][self.positionX]
game.grid[self.positionY + 1][self.positionX].y -= 50
game.grid[self.positionY][self.positionX].y += 50
game.grid[self.positionY + 1][self.positionX], \
game.grid[self.positionY][self.positionX] = \
game.grid[self.positionY][self.positionX], \
game.grid[self.positionY + 1][self.positionX]
self.positionY += 1
self.lastStep.append("Down")
else:
self.work(collisionObject)
pass
# SPRAWDZA NACIŚNIĘTE KLAWISZE
def move(self, game):
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
self.moveLeft()
self.moveLeft(game)
if keys[pygame.K_RIGHT]:
self.moveRight()
self.moveRight(game)
if keys[pygame.K_UP]:
self.moveUp()
self.moveUp(game)
if keys[pygame.K_DOWN]:
self.moveDown()
self.moveDown(game)
if keys[pygame.K_s]:
game.showGrid(game.grid)
def draw(self):
self.rect1 = pygame.Rect(self.x, self.y, 50, 50)
pygame.draw.rect(self.game.screen, (0, 150, 255), self.rect1)
if self.whatKeep == 0:
self.game.screen.blit(self.image, (self.x, self.y))
elif self.whatKeep == 1:
self.game.screen.blit(pygame.image.load("./Images/waiterJedzenie.png"), (self.x, self.y))
elif self.whatKeep == 2:
self.game.screen.blit(pygame.image.load("./Images/waiterBrudneTalerze.png"), (self.x, self.y))
#print(self.lastStep)
self.game.screen.blit(self.image, (self.x, self.y))
# SPRAWDZA CZY ELELEMNT, KTORY POBIERAMY NIE JEST SPOZA PLANSZY
def isMoveInRange(self, move, position):
positionX = position[0]
positionY = position[1]
def isMoveInRange(self, move):
if move == "Left":
if positionX == 0:
if self.positionX == 0:
return False
if move == "Right":
if positionX == 9:
if self.positionX == 9:
return False
if move == "Up":
if positionY == 0:
if self.positionY == 0:
return False
if move == "Down":
if positionY == 9:
if self.positionY == 9:
return False
return True
# SPRAWDZA MOZLIWOSCI RUCHU ZGODNIE Z OSTATNIM RUCHEM
def checkPoss(self, position, lastOperation):
stackMove = []
def checkPoss(self, game, lastOperation):
self.grid = game.grid
self.lastOperation = lastOperation
self.stackMove = []
positionX = position[0]
positionY = position[1]
if len(lastOperation) == 0:
if self.isMoveInRange("Up", position):
collisionObjectUp = self.grid[positionY - 1][positionX]
if collisionObjectUp.type == "gridElement" or collisionObjectUp.type == "waiter":
stackMove.append("Up")
if self.isMoveInRange("Down", position):
collisionObjectDown = self.grid[positionY + 1][positionX]
if collisionObjectDown.type == "gridElement":
stackMove.append("Down")
if self.isMoveInRange("Left", position):
collisionObjectLeft = self.grid[positionY][positionX - 1]
if collisionObjectLeft.type == "gridElement" or collisionObjectLeft.type == "waiter":
stackMove.append("Left")
if self.isMoveInRange("Right", position):
collisionObjectRight = self.grid[positionY][positionX + 1]
if collisionObjectRight.type == "gridElement" or collisionObjectRight.type == "waiter":
stackMove.append("Right")
return stackMove
if len(self.lastOperation) == 0:
if self.isMoveInRange("Up"):
self.collisionObjectUp = self.grid[self.positionY - 1][self.positionX]
if self.collisionObjectUp.type == "gridElement":
self.stackMove.append("Up")
if self.isMoveInRange("Down"):
self.collisionObjectDown = self.grid[self.positionY + 1][self.positionX]
if self.collisionObjectDown.type == "gridElement":
self.stackMove.append("Down")
if self.isMoveInRange("Left"):
self.collisionObjectLeft = self.grid[self.positionY][self.positionX - 1]
if self.collisionObjectLeft.type == "gridElement":
self.stackMove.append("Left")
if self.isMoveInRange("Right"):
self.collisionObjectRight = self.grid[self.positionY][self.positionX + 1]
if self.collisionObjectRight.type == "gridElement":
self.stackMove.append("Right")
return self.stackMove
else:
last = lastOperation[-1]
if last == "Left":
if self.isMoveInRange("Up", position):
collisionObjectUp = self.grid[positionY - 1][positionX]
if collisionObjectUp.type == "gridElement":
stackMove.append("Up")
if self.isMoveInRange("Down", position):
collisionObjectDown = self.grid[positionY + 1][positionX]
if collisionObjectDown.type == "gridElement":
stackMove.append("Down")
if self.isMoveInRange("Left", position):
collisionObjectLeft = self.grid[positionY][positionX - 1]
if collisionObjectLeft.type == "gridElement":
stackMove.append("Left")
self.last = self.lastOperation[-1]
if self.last == "Left":
if self.isMoveInRange("Up"):
self.collisionObjectUp = self.grid[self.positionY - 1][self.positionX]
if self.collisionObjectUp.type == "gridElement":
self.stackMove.append("Up")
if self.isMoveInRange("Down"):
self.collisionObjectDown = self.grid[self.positionY + 1][self.positionX]
if self.collisionObjectDown.type == "gridElement":
self.stackMove.append("Down")
if self.isMoveInRange("Left"):
self.collisionObjectLeft = self.grid[self.positionY][self.positionX - 1]
if self.collisionObjectLeft.type == "gridElement":
self.stackMove.append("Left")
return stackMove
return self.stackMove
if last == "Right":
if self.isMoveInRange("Up", position):
collisionObjectUp = self.grid[positionY - 1][positionX]
if collisionObjectUp.type == "gridElement":
stackMove.append("Up")
if self.isMoveInRange("Down", position):
collisionObjectDown = self.grid[positionY + 1][positionX]
if collisionObjectDown.type == "gridElement":
stackMove.append("Down")
if self.last == "Right":
if self.isMoveInRange("Up"):
self.collisionObjectUp = self.grid[self.positionY - 1][self.positionX]
if self.collisionObjectUp.type == "gridElement":
self.stackMove.append("Up")
if self.isMoveInRange("Down"):
self.collisionObjectDown = self.grid[self.positionY + 1][self.positionX]
if self.collisionObjectDown.type == "gridElement":
self.stackMove.append("Down")
if self.isMoveInRange("Right", position):
collisionObjectRight = self.grid[positionY][positionX + 1]
if collisionObjectRight.type == "gridElement":
stackMove.append("Right")
return stackMove
if self.isMoveInRange("Right"):
self.collisionObjectRight = self.grid[self.positionY][self.positionX + 1]
if self.collisionObjectRight.type == "gridElement":
self.stackMove.append("Right")
return self.stackMove
if last == "Up":
if self.isMoveInRange("Up", position):
collisionObjectUp = self.grid[positionY - 1][positionX]
if collisionObjectUp.type == "gridElement":
stackMove.append("Up")
if self.last == "Up":
if self.isMoveInRange("Up"):
self.collisionObjectUp = self.grid[self.positionY - 1][self.positionX]
if self.collisionObjectUp.type == "gridElement":
self.stackMove.append("Up")
if self.isMoveInRange("Left", position):
collisionObjectLeft = self.grid[positionY][positionX - 1]
if collisionObjectLeft.type == "gridElement":
stackMove.append("Left")
if self.isMoveInRange("Right", position):
collisionObjectRight = self.grid[positionY][positionX + 1]
if collisionObjectRight.type == "gridElement":
stackMove.append("Right")
return stackMove
if self.isMoveInRange("Left"):
self.collisionObjectLeft = self.grid[self.positionY][self.positionX - 1]
if self.collisionObjectLeft.type == "gridElement":
self.stackMove.append("Left")
if self.isMoveInRange("Right"):
self.collisionObjectRight = self.grid[self.positionY][self.positionX + 1]
if self.collisionObjectRight.type == "gridElement":
self.stackMove.append("Right")
return self.stackMove
if last == "Down":
if self.last == "Down":
if self.isMoveInRange("Down", position):
collisionObjectDown = self.grid[positionY + 1][positionX]
if collisionObjectDown.type == "gridElement":
stackMove.append("Down")
if self.isMoveInRange("Left", position):
collisionObjectLeft = self.grid[positionY][positionX - 1]
if collisionObjectLeft.type == "gridElement":
stackMove.append("Left")
if self.isMoveInRange("Right", position):
collisionObjectRight = self.grid[positionY][positionX + 1]
if collisionObjectRight.type == "gridElement":
stackMove.append("Right")
return stackMove
# DFS
def dfsFind(self, position, currentOperation, visited, idTable):
#print("Sprawdzam czy stolik")
if self.isMoveInRange("Down"):
self.collisionObjectDown = self.grid[self.positionY + 1][self.positionX]
if self.collisionObjectDown.type == "gridElement":
self.stackMove.append("Down")
if self.isMoveInRange("Left"):
self.collisionObjectLeft = self.grid[self.positionY][self.positionX - 1]
if self.collisionObjectLeft.type == "gridElement":
self.stackMove.append("Left")
if self.isMoveInRange("Right"):
self.collisionObjectRight = self.grid[self.positionY][self.positionX + 1]
if self.collisionObjectRight.type == "gridElement":
self.stackMove.append("Right")
return self.stackMove
positionX = position[0]
positionY = position[1]
#print("Pozycja kelnera: ", position)
if self.isMoveInRange("Up", position):
if self.grid[positionY - 1][positionX].type == "table":
if self.grid[positionY - 1][positionX].id == idTable:
self.dfsPaths.append(currentOperation)
print("Dodalem sciezke: ", currentOperation)
return 0
if self.isMoveInRange("Down", position):
if self.grid[positionY + 1][positionX].type == "table":
if self.grid[positionY + 1][positionX].id == idTable:
self.dfsPaths.append(currentOperation)
print("Dodalem sciezke: ", currentOperation)
return 0
if self.isMoveInRange("Left", position):
if self.grid[positionY][positionX - 1].type == "table":
if self.grid[positionY][positionX - 1].id == idTable:
self.dfsPaths.append(currentOperation)
print("Dodalem sciezke: ", currentOperation)
return 0
if self.isMoveInRange("Right", position):
if self.grid[positionY][positionX + 1].type == "table":
if self.grid[positionY][positionX + 1].id == idTable:
self.dfsPaths.append(currentOperation)
print("Dodalem sciezke: ", currentOperation)
return 0
# print("Sprawdzilem nie jest to stolik")
def dfsFind(self, game, currentOperation, idTable):
self.game = game
self.grid = game.grid
self.currentOperation = currentOperation
print("Sprawdzam czy stolik")
if self.isMoveInRange("Up"):
if self.grid[self.positionY - 1][self.positionX].type == "table":
if self.grid[self.positionY - 1][self.positionX].id == idTable:
return self.currentOperation
if self.isMoveInRange("Down"):
if self.grid[self.positionY + 1][self.positionX].type == "table":
if self.grid[self.positionY + 1][self.positionX].id == idTable:
return self.currentOperation
if self.isMoveInRange("Left"):
if self.grid[self.positionY][self.positionX - 1].type == "table":
if self.grid[self.positionY][self.positionX - 1].id == idTable:
return self.currentOperation
if self.isMoveInRange("Right"):
if self.grid[self.positionY][self.positionX + 1].type == "table":
if self.grid[self.positionY][self.positionX + 1].id == idTable:
return self.currentOperation
print("Sprawdzilem nie stolik")
steps = []
steps.append(self.checkPoss(position, currentOperation))
allstep = steps[-1]
# print("Naszymi mozliwosciami sa ", allstep)
if not allstep:
return 0
else:
for step in allstep:
newCurrentOperation = currentOperation[:]
newCurrentOperation.append(step)
newPosition = position[:]
newVisited = visited[:]
#print("newVisited", newVisited)
if step == "Left":
if [newPosition[0] - 1, newPosition[1]] in visited:
# print("Tam gdzie chce isc bylem juz: ", step)
continue
newPosition[0] -= 1
if len(self.checkPoss(newPosition, newCurrentOperation)) == 1:
newVisited.append(newPosition)
elif step == "Right":
if [newPosition[0] + 1, newPosition[1]] in visited:
# print("Tam gdzie chce isc bylem juz: ", step)
continue
newPosition[0] += 1
if len(self.checkPoss(newPosition, newCurrentOperation)) == 1:
newVisited.append(newPosition)
elif step == "Up":
if [newPosition[0], newPosition[1] - 1] in visited:
# print("Tam gdzie chce isc bylem juz: ", step)
continue
newPosition[1] -= 1
if len(self.checkPoss(newPosition, newCurrentOperation)) == 1:
newVisited.append(newPosition)
else:
if [newPosition[0], newPosition[1] + 1] in visited:
# print("Tam gdzie chce isc bylem juz: ", step)
continue
newPosition[1] += 1
if len(self.checkPoss(newPosition, newCurrentOperation)) == 1:
newVisited.append(newPosition)
self.dfsStack.append([newPosition, newCurrentOperation, newVisited, idTable])
while self.dfsStack:
move = self.dfsStack.pop()
self.dfsFind(move[0], move[1], move[2], move[3])
# BFS
def bfsFind(self, position, currentOperation, visited, idTable):
#print("Sprawdzam czy stolik")
positionX = position[0]
positionY = position[1]
# print("Pozycja kelnera: ", position)
if self.isMoveInRange("Up", position):
if self.grid[positionY - 1][positionX].type == "table":
if self.grid[positionY - 1][positionX].id == idTable:
currentOperation.append("Up")
self.bfsPaths.append(currentOperation)
print("Dodalem sciezke: ", currentOperation)
return 0
if self.isMoveInRange("Down", position):
if self.grid[positionY + 1][positionX].type == "table":
if self.grid[positionY + 1][positionX].id == idTable:
currentOperation.append("Down")
self.bfsPaths.append(currentOperation)
print("Dodalem sciezke: ", currentOperation)
return 0
if self.isMoveInRange("Left", position):
if self.grid[positionY][positionX - 1].type == "table":
if self.grid[positionY][positionX - 1].id == idTable:
currentOperation.append("Left")
self.bfsPaths.append(currentOperation)
print("Dodalem sciezke: ", currentOperation)
return 0
if self.isMoveInRange("Right", position):
if self.grid[positionY][positionX + 1].type == "table":
if self.grid[positionY][positionX + 1].id == idTable:
currentOperation.append("Right")
self.bfsPaths.append(currentOperation)
print("Dodalem sciezke: ", currentOperation)
return 0
# print("Sprawdzilem nie jest to stolik")
steps = []
steps.append(self.checkPoss(position, currentOperation))
allstep = steps[-1]
# print("Naszymi mozliwosciami sa ", allstep)
if not allstep:
return 0
else:
for step in allstep:
newCurrentOperation = currentOperation[:]
newCurrentOperation.append(step)
newPosition = position[:]
newVisited = visited[:]
# print("newVisited", newVisited)
if step == "Left":
if [newPosition[0] - 1, newPosition[1]] in visited:
# print("Tam gdzie chce isc bylem juz: ", step)
continue
newPosition[0] -= 1
if len(self.checkPoss(newPosition, newCurrentOperation)) == 1:
newVisited.append(newPosition)
elif step == "Right":
if [newPosition[0] + 1, newPosition[1]] in visited:
# print("Tam gdzie chce isc bylem juz: ", step)
continue
newPosition[0] += 1
if len(self.checkPoss(newPosition, newCurrentOperation)) == 1:
newVisited.append(newPosition)
elif step == "Up":
if [newPosition[0], newPosition[1] - 1] in visited:
# print("Tam gdzie chce isc bylem juz: ", step)
continue
newPosition[1] -= 1
if len(self.checkPoss(newPosition, newCurrentOperation)) == 1:
newVisited.append(newPosition)
else:
if [newPosition[0], newPosition[1] + 1] in visited:
# print("Tam gdzie chce isc bylem juz: ", step)
continue
newPosition[1] += 1
if len(self.checkPoss(newPosition, newCurrentOperation)) == 1:
newVisited.append(newPosition)
self.bfsQueue.append([newPosition, newCurrentOperation, newVisited, idTable])
while not(self.bfsPaths) and self.bfsQueue:
move = self.bfsQueue.pop(0)
self.bfsFind(move[0], move[1],move[2], move[3])
# PORUSZA KELNERA WEDŁUG LISTY KROKOW
def followThePath(self, path):
for direction in path:
if direction == "Left":
self.moveLeft()
if direction == "Right":
self.moveRight()
if direction == "Up":
self.moveUp()
if direction == "Down":
self.moveDown()
self.game.draw()
time.sleep(.50)
def takeDish(self, orderTable):
orderTable.hasDish = False
self.whatKeep = 1
def putDish(self, table):
self.whatKeep = 0
table.hasDish = True
table.isWaiting = False
def takePlate(self, table):
table.hasDish = False
table.isClean = True
self.whatKeep = 2
def putPlate(self):
self.whatKeep = 0
def takeOrder(self, table):
table.isOrdering = False
def work(self, object: object) -> object:
if object.type == "wasteTable" and self.whatKeep == 2:
self.putPlate()
elif object.type == "orderTable" and object.hasDish and self.whatKeep == 0:
self.takeDish(object)
elif object.type == "table":
if not object.isClean and (self.whatKeep == 0 or self.whatKeep == 2):
self.takePlate(object)
elif object.isOrdering and self.whatKeep == 0:
self.takeOrder(object)
elif object.isWaiting and self.whatKeep == 1:
self.putDish(object)
steps.append(self.checkPoss(self.game, self.currentOperation))
step = steps[-1]
print(step[-1])
if step[-1] == "Left":
self.moveLeft(self.game)
self.currentOperation.append("Left")
if step[-1] == "Right":
self.moveRight(self.game)
self.currentOperation.append("Right")
if step[-1] == "Up":
self.moveUp(self.game)
self.currentOperation.append("Up")
if step[-1] == "Down":
self.moveDown(self.game)
self.currentOperation.append("Down")
game.draw()
time.sleep(.500)
pygame.display.flip()
self.dfsFind(self.game, self.currentOperation, idTable)

View File

@ -1,18 +0,0 @@
import pygame
class WasteTable(object):
def __init__(self, x, y, game):
self.game = game
game.idItem += 1
self.idItem = game.idItem
self.x = x
self.y = y
self.image = pygame.image.load("./Images/zmywak.png")
self.type = "wasteTable"
def draw(self):
self.rect = pygame.Rect(self.x, self.y, 50, 50)
self.game.screen.blit(pygame.image.load("./Images/zmywak.png"), (self.x, self.y))