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"> <component name="ChangeListManager">
<list default="true" id="152ea650-8e02-4ed6-aa8c-04d44b275be4" name="Default Changelist" comment=""> <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$/.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$/game.py" beforeDir="false" afterPath="$PROJECT_DIR$/game.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/savedPaths.txt" beforeDir="false" afterPath="$PROJECT_DIR$/savedPaths.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/waiter.py" beforeDir="false" afterPath="$PROJECT_DIR$/waiter.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/waiter.py" beforeDir="false" afterPath="$PROJECT_DIR$/waiter.py" afterDir="false" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -18,7 +17,7 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/order.py"> <entry file="file://$PROJECT_DIR$/order.py">
<provider selected="true" editor-type-id="text-editor"> <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" /> <caret line="6" selection-start-line="6" selection-end-line="6" />
</state> </state>
</provider> </provider>
@ -27,8 +26,8 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/game.py"> <entry file="file://$PROJECT_DIR$/game.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="792"> <state relative-caret-position="1475">
<caret line="69" column="62" selection-start-line="69" selection-start-column="62" selection-end-line="69" selection-end-column="62" /> <caret line="59" column="26" selection-start-line="59" selection-start-column="19" selection-end-line="59" selection-end-column="26" />
<folding> <folding>
<element signature="e#0#18#0" expanded="true" /> <element signature="e#0#18#0" expanded="true" />
</folding> </folding>
@ -36,16 +35,11 @@
</provider> </provider>
</entry> </entry>
</file> </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"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/gridElement.py"> <entry file="file://$PROJECT_DIR$/gridElement.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="154"> <state>
<caret line="7" column="17" selection-start-line="7" selection-start-column="17" selection-end-line="7" selection-end-column="17" /> <caret line="14" column="59" selection-start-line="14" selection-start-column="59" selection-end-line="14" selection-end-column="59" />
</state> </state>
</provider> </provider>
</entry> </entry>
@ -53,8 +47,8 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/table.py"> <entry file="file://$PROJECT_DIR$/table.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="72"> <state>
<caret line="10" column="6" selection-start-line="10" selection-start-column="6" selection-end-line="10" selection-end-column="6" /> <caret line="14" column="15" selection-start-line="14" selection-start-column="15" selection-end-line="14" selection-end-column="15" />
</state> </state>
</provider> </provider>
</entry> </entry>
@ -62,8 +56,8 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/pool.py"> <entry file="file://$PROJECT_DIR$/pool.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="176"> <state>
<caret line="8" column="65" selection-start-line="8" selection-start-column="21" selection-end-line="8" selection-end-column="65" /> <caret line="9" column="26" selection-start-line="9" selection-start-column="26" selection-end-line="9" selection-end-column="26" />
<folding> <folding>
<element signature="e#0#13#0" expanded="true" /> <element signature="e#0#13#0" expanded="true" />
</folding> </folding>
@ -74,8 +68,8 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/orderTable.py"> <entry file="file://$PROJECT_DIR$/orderTable.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="198"> <state>
<caret line="9" column="45" lean-forward="true" selection-start-line="9" selection-start-column="45" selection-end-line="9" selection-end-column="45" /> <caret line="17" column="58" selection-start-line="17" selection-start-column="58" selection-end-line="17" selection-end-column="58" />
</state> </state>
</provider> </provider>
</entry> </entry>
@ -83,24 +77,15 @@
<file pinned="false" current-in-tab="true"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/waiter.py"> <entry file="file://$PROJECT_DIR$/waiter.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="437"> <state relative-caret-position="402">
<caret line="447" column="26" lean-forward="true" selection-start-line="447" selection-start-column="26" selection-end-line="447" selection-end-column="26" /> <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> <folding>
<element signature="e#0#14#0" expanded="true" /> <element signature="e#0#13#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
</file> </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> </leaf>
</component> </component>
<component name="FileTemplateManagerImpl"> <component name="FileTemplateManagerImpl">
@ -110,14 +95,6 @@
</list> </list>
</option> </option>
</component> </component>
<component name="FindInProjectRecents">
<findStrings>
<find>self.last</find>
<find>tmp</find>
<find>visited</find>
<find>drow</find>
</findStrings>
</component>
<component name="Git.Settings"> <component name="Git.Settings">
<option name="PREVIOUS_COMMIT_AUTHORS"> <option name="PREVIOUS_COMMIT_AUTHORS">
<list> <list>
@ -125,14 +102,6 @@
</list> </list>
</option> </option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <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>
<component name="IdeDocumentHistory"> <component name="IdeDocumentHistory">
<option name="CHANGED_PATHS"> <option name="CHANGED_PATHS">
@ -142,19 +111,19 @@
<option value="$PROJECT_DIR$/gridElement.py" /> <option value="$PROJECT_DIR$/gridElement.py" />
<option value="$PROJECT_DIR$/run.py" /> <option value="$PROJECT_DIR$/run.py" />
<option value="$PROJECT_DIR$/order.py" /> <option value="$PROJECT_DIR$/order.py" />
<option value="$PROJECT_DIR$/pool.py" />
<option value="$PROJECT_DIR$/table.py" /> <option value="$PROJECT_DIR$/table.py" />
<option value="$PROJECT_DIR$/orderTable.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$/game.py" />
<option value="$PROJECT_DIR$/waiter.py" /> <option value="$PROJECT_DIR$/waiter.py" />
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectFrameBounds" extendedState="6"> <component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="-7" /> <option name="x" value="716" />
<option name="width" value="1660" /> <option name="y" value="77" />
<option name="height" value="1047" /> <option name="width" value="970" />
<option name="height" value="1050" />
</component> </component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true"> <component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" /> <ConfirmationsSetting value="2" id="Add" />
@ -185,7 +154,7 @@
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
<property name="last_opened_file_path" value="$PROJECT_DIR$" /> <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>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS"> <key name="MoveFile.RECENT_KEYS">
@ -288,20 +257,20 @@
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" /> <frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
<editor active="true" /> <editor active="true" />
<layout> <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="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" /> <window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" /> <window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32936078" /> <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.2979415" /> <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.2708559" /> <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="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> <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="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="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="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="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="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" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" 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" /> <MESSAGE value="Lada i skromne kolizje" />
<option name="LAST_COMMIT_MESSAGE" value="Lada i skromne kolizje" /> <option name="LAST_COMMIT_MESSAGE" value="Lada i skromne kolizje" />
</component> </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"> <component name="editorHistoryManager">
<entry file="file://$USER_HOME$/Desktop/pygame-elsa/sprites/olaf.py"> <entry file="file://$USER_HOME$/Desktop/pygame-elsa/sprites/olaf.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
@ -385,6 +329,13 @@
<entry file="file://$PROJECT_DIR$/Images/waiter.jpg"> <entry file="file://$PROJECT_DIR$/Images/waiter.jpg">
<provider selected="true" editor-type-id="images" /> <provider selected="true" editor-type-id="images" />
</entry> </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"> <entry file="file://$APPLICATION_HOME_DIR$/helpers/pydev/_pydev_imps/_pydev_execfile.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289"> <state relative-caret-position="289">
@ -414,6 +365,9 @@
<provider selected="true" editor-type-id="images" /> <provider selected="true" editor-type-id="images" />
</entry> </entry>
<entry file="file://$PROJECT_DIR$/run.py" /> <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"> <entry file="file://$PROJECT_DIR$/Images/water.jpg">
<provider selected="true" editor-type-id="images" /> <provider selected="true" editor-type-id="images" />
</entry> </entry>
@ -430,84 +384,60 @@
<entry file="file://$PROJECT_DIR$/Images/tlo.jpg"> <entry file="file://$PROJECT_DIR$/Images/tlo.jpg">
<provider selected="true" editor-type-id="images" /> <provider selected="true" editor-type-id="images" />
</entry> </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"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="299"> <state>
<caret line="3704" column="8" selection-start-line="3704" selection-start-column="8" selection-end-line="3704" selection-end-column="8" /> <caret line="6" selection-start-line="6" selection-end-line="6" />
</state> </state>
</provider> </provider>
</entry> </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"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="448"> <state>
<caret line="1740" selection-start-line="1740" selection-end-line="1740" /> <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> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/pool.py"> <entry file="file://$PROJECT_DIR$/pool.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="176"> <state>
<caret line="8" column="65" selection-start-line="8" selection-start-column="21" selection-end-line="8" selection-end-column="65" /> <caret line="9" column="26" selection-start-line="9" selection-start-column="26" selection-end-line="9" selection-end-column="26" />
<folding> <folding>
<element signature="e#0#13#0" expanded="true" /> <element signature="e#0#13#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/Images/tableSmall.png">
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file://$PROJECT_DIR$/orderTable.py"> <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"> <provider selected="true" editor-type-id="text-editor">
<state> <state>
<caret column="13" lean-forward="true" selection-start-column="13" selection-end-column="13" /> <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$/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" />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/game.py"> <entry file="file://$PROJECT_DIR$/game.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="792"> <state relative-caret-position="1475">
<caret line="69" column="62" selection-start-line="69" selection-start-column="62" selection-end-line="69" selection-end-column="62" /> <caret line="59" column="26" selection-start-line="59" selection-start-column="19" selection-end-line="59" selection-end-column="26" />
<folding> <folding>
<element signature="e#0#18#0" expanded="true" /> <element signature="e#0#18#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </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"> <entry file="file://$PROJECT_DIR$/waiter.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="437"> <state relative-caret-position="402">
<caret line="447" column="26" lean-forward="true" selection-start-line="447" selection-start-column="26" selection-end-line="447" selection-end-column="26" /> <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> <folding>
<element signature="e#0#14#0" expanded="true" /> <element signature="e#0#13#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </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 waiter import Waiter
from table import Table from table import Table
from gridElement import GridElement from gridElement import GridElement
from pygame.math import Vector2 from pygame.math import Vector2
from orderTable import OrderTable from orderTable import OrderTable
from pool import Pool from pool import Pool
from wasteTable import WasteTable
from operator import attrgetter
import copy
class Game(object): class Game(object):
def __init__(self): def __init__(self):
@ -28,57 +25,29 @@ class Game(object):
self.grid = [] self.grid = []
self.row = [] self.row = []
self.tableList = [] self.tableList = []
self.orderTableList = []
# TWORZENIE ELEMENTÓW PLANSZY
for b in range(self.y): for b in range(self.y):
for i in range(self.x): for i in range(self.x):
if ((i == 0) or (i == 9)) and ((b == 0) or (b == 6)): if ((i == 0) or (i == 9)) and ((b == 0) or (b == 6)):
tmp = random.randint(0, 3) self.row.append(Table(i * 50, b * 50, self))
table = Table(i * 50, b * 50, self) elif (b == self.y-1 or b == self.y-2 or b == self.y-3) and (i == 5):
if tmp == 1: table = OrderTable(i * 50, b * 50, self)
table.isOrdering = True
elif tmp == 2:
table.isWaiting = True
elif tmp == 3:
table.isClean = False
self.row.append(table) self.row.append(table)
self.tableList.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: elif i == 4 and b == 9:
self.waiter = Waiter(self, i * 50, b * 50) self.waiter = Waiter(self, i * 50, b * 50)
self.row.append(self.waiter) self.row.append(self.waiter)
self.waiterNumberInGrid.x = i self.waiterNumberInGrid.x = i
self.waiterNumberInGrid.y = b 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))) \ 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): or (b>6 and (i<4 or i > 5) ):
self.row.append(Pool(i * 50, b * 50, self)) 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: else:
self.row.append(GridElement(i * 50, b * 50, self)) self.row.append(GridElement(i * 50, b * 50, self))
if i == self.x-1: if i == self.x-1:
self.grid.append(list(self.row)) self.grid.append(list(self.row))
self.row.clear() self.row.clear()
self.waiter.dfsFind(self, self.waiter.lastStep, 1)
#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
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
@ -87,12 +56,11 @@ class Game(object):
self.draw() self.draw()
self.waiter.move(self) 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) #print(self.waiterNumberInGrid)
self.fpsClock.tick(10) self.fpsClock.tick(10)
# WYRYSOWANIE KAZDEGO ELEMENTU Z GRIDU NA EKRAN
def draw(self): def draw(self):
tempTable = [] tempTable = []
for row in self.grid: for row in self.grid:
@ -103,7 +71,6 @@ class Game(object):
tempTable.append(gridElement) tempTable.append(gridElement)
for otherElement in tempTable: for otherElement in tempTable:
otherElement.draw() otherElement.draw()
pygame.display.flip()
def convert(self, object): def convert(self, object):
if object.type == "gridElement": if object.type == "gridElement":
@ -116,9 +83,6 @@ class Game(object):
return 'O' return 'O'
elif object.type == "pool": elif object.type == "pool":
return 'P' return 'P'
elif object.type == "wasteTable":
return 'Z'
def showGrid(self, grid): def showGrid(self, grid):
charakterList = [] charakterList = []
@ -128,33 +92,7 @@ class Game(object):
charakterList.append(row) charakterList.append(row)
print(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__": if __name__ == "__main__":
v1 = Game() Game()

View File

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

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.idTable += 1
game.idItem += 1 game.idItem += 1
self.number = game.idItem self.number = game.idItem
self.isWaiting = False self.isBusy = False
self.isClean = True
self.isOrdering = False
self.hasDish = False
self.id = game.idTable self.id = game.idTable
self.image = pygame.image.load("./Images/stolik.png") self.image = pygame.image.load("./Images/tableSmall.png")
#self.image = pygame.transform.scale(self.image, (50, 50))
self.type = "table" self.type = "table"
def draw(self): def draw(self):
self.table = pygame.Rect(self.x, self.y, 50, 50) self.table = pygame.Rect(self.x, self.y, 50, 50)
pygame.draw.rect(self.game.screen, (100, 0, 100), self.table) pygame.draw.rect(self.game.screen, (100, 0, 100), self.table)
if self.isOrdering: #self.game.screen.blit(self.image, (self.x, self.y))
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))

539
waiter.py
View File

@ -1,15 +1,11 @@
import asyncio
from multiprocessing import Queue
import pygame import pygame
import time import time
from pygame.math import Vector2 from pygame.math import Vector2
class Waiter(object): class Waiter(object):
def __init__(self, game, x, y): def __init__(self, game, x, y):
self.game = game self.game = game
self.grid = game.grid
game.idItem += 1 game.idItem += 1
self.size= self.game.screen.get_size() self.size= self.game.screen.get_size()
self.x = x self.x = x
@ -20,429 +16,236 @@ class Waiter(object):
self.image.set_colorkey((255, 255, 255)) self.image.set_colorkey((255, 255, 255))
self.type = "waiter" self.type = "waiter"
self.lastStep = [] self.lastStep = []
self.whatKeep = 0
self.dfsStack = []
self.dfsPaths = []
self.bfsQueue = [] def moveLeft(self, game):
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):
if self.positionX != 0: 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": if collisionObject.type == "gridElement":
self.game.grid[self.positionY][self.positionX - 1].x += 50 game.grid[self.positionY][self.positionX - 1].x += 50
self.game.grid[self.positionY][self.positionX].x -= 50 game.grid[self.positionY][self.positionX].x -= 50
self.game.grid[self.positionY][self.positionX - 1], \ game.grid[self.positionY][self.positionX - 1], \
self.game.grid[self.positionY][self.positionX] = \ game.grid[self.positionY][self.positionX] = \
self.game.grid[self.positionY][self.positionX], \ game.grid[self.positionY][self.positionX], \
self.game.grid[self.positionY][self.positionX - 1] game.grid[self.positionY][self.positionX - 1]
self.positionX -= 1 self.positionX -= 1
#print(self.positionX) #print(self.positionX)
self.lastStep.append("Left") self.lastStep.append("Left")
else: else:
self.work(collisionObject) pass
def moveRight(self): def moveRight(self, game):
if self.positionX != self.game.x-1: if self.positionX != game.x-1:
collisionObject = self.game.grid[self.positionY][self.positionX + 1] collisionObject = game.grid[self.positionY][self.positionX + 1]
if collisionObject.type == "gridElement": if collisionObject.type == "gridElement":
self.game.grid[self.positionY][self.positionX + 1].x -= 50 game.grid[self.positionY][self.positionX + 1].x -= 50
self.game.grid[self.positionY][self.positionX].x += 50 game.grid[self.positionY][self.positionX].x += 50
self.game.grid[self.positionY][self.positionX + 1], \ game.grid[self.positionY][self.positionX + 1], \
self.game.grid[self.positionY][self.positionX] = \ game.grid[self.positionY][self.positionX] = \
self.game.grid[self.positionY][self.positionX], \ game.grid[self.positionY][self.positionX], \
self.game.grid[self.positionY][self.positionX + 1] game.grid[self.positionY][self.positionX + 1]
self.positionX += 1 self.positionX += 1
#print(self.positionX) #print(self.positionX)
self.lastStep.append("Right") self.lastStep.append("Right")
else: else:
self.work(collisionObject) pass
def moveUp(self): def moveUp(self, game):
if self.positionY != 0: 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": if collisionObject.type == "gridElement":
self.game.grid[self.positionY - 1][self.positionX].y += 50 game.grid[self.positionY - 1][self.positionX].y += 50
self.game.grid[self.positionY][self.positionX].y -= 50 game.grid[self.positionY][self.positionX].y -= 50
self.game.grid[self.positionY - 1][self.positionX], \ game.grid[self.positionY - 1][self.positionX], \
self.game.grid[self.positionY][self.positionX] = \ game.grid[self.positionY][self.positionX] = \
self.game.grid[self.positionY][self.positionX], \ game.grid[self.positionY][self.positionX], \
self.game.grid[self.positionY - 1][self.positionX] game.grid[self.positionY - 1][self.positionX]
self.positionY -= 1 self.positionY -= 1
self.lastStep.append("Up") self.lastStep.append("Up")
else: else:
self.work(collisionObject) pass
def moveDown(self): def moveDown(self, game):
if self.positionY != self.game.y-1: if self.positionY != game.y-1:
collisionObject = self.game.grid[self.positionY + 1][self.positionX] collisionObject = game.grid[self.positionY + 1][self.positionX]
if collisionObject.type == "gridElement": if collisionObject.type == "gridElement":
self.game.grid[self.positionY + 1][self.positionX].y -= 50 game.grid[self.positionY + 1][self.positionX].y -= 50
self.game.grid[self.positionY][self.positionX].y += 50 game.grid[self.positionY][self.positionX].y += 50
self.game.grid[self.positionY + 1][self.positionX], \ game.grid[self.positionY + 1][self.positionX], \
self.game.grid[self.positionY][self.positionX] = \ game.grid[self.positionY][self.positionX] = \
self.game.grid[self.positionY][self.positionX], \ game.grid[self.positionY][self.positionX], \
self.game.grid[self.positionY + 1][self.positionX] game.grid[self.positionY + 1][self.positionX]
self.positionY += 1 self.positionY += 1
self.lastStep.append("Down") self.lastStep.append("Down")
else: else:
self.work(collisionObject) pass
# SPRAWDZA NACIŚNIĘTE KLAWISZE
def move(self, game): def move(self, game):
keys = pygame.key.get_pressed() keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]: if keys[pygame.K_LEFT]:
self.moveLeft() self.moveLeft(game)
if keys[pygame.K_RIGHT]: if keys[pygame.K_RIGHT]:
self.moveRight() self.moveRight(game)
if keys[pygame.K_UP]: if keys[pygame.K_UP]:
self.moveUp() self.moveUp(game)
if keys[pygame.K_DOWN]: if keys[pygame.K_DOWN]:
self.moveDown() self.moveDown(game)
if keys[pygame.K_s]: if keys[pygame.K_s]:
game.showGrid(game.grid) game.showGrid(game.grid)
def draw(self): def draw(self):
self.rect1 = pygame.Rect(self.x, self.y, 50, 50) self.rect1 = pygame.Rect(self.x, self.y, 50, 50)
pygame.draw.rect(self.game.screen, (0, 150, 255), self.rect1) pygame.draw.rect(self.game.screen, (0, 150, 255), self.rect1)
if self.whatKeep == 0: #print(self.lastStep)
self.game.screen.blit(self.image, (self.x, self.y)) 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))
# 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 move == "Left":
if positionX == 0: if self.positionX == 0:
return False return False
if move == "Right": if move == "Right":
if positionX == 9: if self.positionX == 9:
return False return False
if move == "Up": if move == "Up":
if positionY == 0: if self.positionY == 0:
return False return False
if move == "Down": if move == "Down":
if positionY == 9: if self.positionY == 9:
return False return False
return True 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] if len(self.lastOperation) == 0:
positionY = position[1] if self.isMoveInRange("Up"):
self.collisionObjectUp = self.grid[self.positionY - 1][self.positionX]
if len(lastOperation) == 0: if self.collisionObjectUp.type == "gridElement":
if self.isMoveInRange("Up", position): self.stackMove.append("Up")
collisionObjectUp = self.grid[positionY - 1][positionX] if self.isMoveInRange("Down"):
if collisionObjectUp.type == "gridElement" or collisionObjectUp.type == "waiter": self.collisionObjectDown = self.grid[self.positionY + 1][self.positionX]
stackMove.append("Up") if self.collisionObjectDown.type == "gridElement":
if self.isMoveInRange("Down", position): self.stackMove.append("Down")
collisionObjectDown = self.grid[positionY + 1][positionX] if self.isMoveInRange("Left"):
if collisionObjectDown.type == "gridElement": self.collisionObjectLeft = self.grid[self.positionY][self.positionX - 1]
stackMove.append("Down") if self.collisionObjectLeft.type == "gridElement":
if self.isMoveInRange("Left", position): self.stackMove.append("Left")
collisionObjectLeft = self.grid[positionY][positionX - 1] if self.isMoveInRange("Right"):
if collisionObjectLeft.type == "gridElement" or collisionObjectLeft.type == "waiter": self.collisionObjectRight = self.grid[self.positionY][self.positionX + 1]
stackMove.append("Left") if self.collisionObjectRight.type == "gridElement":
if self.isMoveInRange("Right", position): self.stackMove.append("Right")
collisionObjectRight = self.grid[positionY][positionX + 1] return self.stackMove
if collisionObjectRight.type == "gridElement" or collisionObjectRight.type == "waiter":
stackMove.append("Right")
return stackMove
else: else:
last = lastOperation[-1] self.last = self.lastOperation[-1]
if last == "Left": if self.last == "Left":
if self.isMoveInRange("Up", position): if self.isMoveInRange("Up"):
collisionObjectUp = self.grid[positionY - 1][positionX] self.collisionObjectUp = self.grid[self.positionY - 1][self.positionX]
if collisionObjectUp.type == "gridElement": if self.collisionObjectUp.type == "gridElement":
stackMove.append("Up") self.stackMove.append("Up")
if self.isMoveInRange("Down", position): if self.isMoveInRange("Down"):
collisionObjectDown = self.grid[positionY + 1][positionX] self.collisionObjectDown = self.grid[self.positionY + 1][self.positionX]
if collisionObjectDown.type == "gridElement": if self.collisionObjectDown.type == "gridElement":
stackMove.append("Down") self.stackMove.append("Down")
if self.isMoveInRange("Left", position): if self.isMoveInRange("Left"):
collisionObjectLeft = self.grid[positionY][positionX - 1] self.collisionObjectLeft = self.grid[self.positionY][self.positionX - 1]
if collisionObjectLeft.type == "gridElement": if self.collisionObjectLeft.type == "gridElement":
stackMove.append("Left") self.stackMove.append("Left")
return stackMove return self.stackMove
if last == "Right": if self.last == "Right":
if self.isMoveInRange("Up", position): if self.isMoveInRange("Up"):
collisionObjectUp = self.grid[positionY - 1][positionX] self.collisionObjectUp = self.grid[self.positionY - 1][self.positionX]
if collisionObjectUp.type == "gridElement": if self.collisionObjectUp.type == "gridElement":
stackMove.append("Up") self.stackMove.append("Up")
if self.isMoveInRange("Down", position): if self.isMoveInRange("Down"):
collisionObjectDown = self.grid[positionY + 1][positionX] self.collisionObjectDown = self.grid[self.positionY + 1][self.positionX]
if collisionObjectDown.type == "gridElement": if self.collisionObjectDown.type == "gridElement":
stackMove.append("Down") self.stackMove.append("Down")
if self.isMoveInRange("Right", position): if self.isMoveInRange("Right"):
collisionObjectRight = self.grid[positionY][positionX + 1] self.collisionObjectRight = self.grid[self.positionY][self.positionX + 1]
if collisionObjectRight.type == "gridElement": if self.collisionObjectRight.type == "gridElement":
stackMove.append("Right") self.stackMove.append("Right")
return stackMove return self.stackMove
if last == "Up": if self.last == "Up":
if self.isMoveInRange("Up", position): if self.isMoveInRange("Up"):
collisionObjectUp = self.grid[positionY - 1][positionX] self.collisionObjectUp = self.grid[self.positionY - 1][self.positionX]
if collisionObjectUp.type == "gridElement": if self.collisionObjectUp.type == "gridElement":
stackMove.append("Up") self.stackMove.append("Up")
if self.isMoveInRange("Left", position): if self.isMoveInRange("Left"):
collisionObjectLeft = self.grid[positionY][positionX - 1] self.collisionObjectLeft = self.grid[self.positionY][self.positionX - 1]
if collisionObjectLeft.type == "gridElement": if self.collisionObjectLeft.type == "gridElement":
stackMove.append("Left") self.stackMove.append("Left")
if self.isMoveInRange("Right", position): if self.isMoveInRange("Right"):
collisionObjectRight = self.grid[positionY][positionX + 1] self.collisionObjectRight = self.grid[self.positionY][self.positionX + 1]
if collisionObjectRight.type == "gridElement": if self.collisionObjectRight.type == "gridElement":
stackMove.append("Right") self.stackMove.append("Right")
return stackMove return self.stackMove
if last == "Down": if self.last == "Down":
if self.isMoveInRange("Down", position): if self.isMoveInRange("Down"):
collisionObjectDown = self.grid[positionY + 1][positionX] self.collisionObjectDown = self.grid[self.positionY + 1][self.positionX]
if collisionObjectDown.type == "gridElement": if self.collisionObjectDown.type == "gridElement":
stackMove.append("Down") self.stackMove.append("Down")
if self.isMoveInRange("Left", position): if self.isMoveInRange("Left"):
collisionObjectLeft = self.grid[positionY][positionX - 1] self.collisionObjectLeft = self.grid[self.positionY][self.positionX - 1]
if collisionObjectLeft.type == "gridElement": if self.collisionObjectLeft.type == "gridElement":
stackMove.append("Left") self.stackMove.append("Left")
if self.isMoveInRange("Right", position): if self.isMoveInRange("Right"):
collisionObjectRight = self.grid[positionY][positionX + 1] self.collisionObjectRight = self.grid[self.positionY][self.positionX + 1]
if collisionObjectRight.type == "gridElement": if self.collisionObjectRight.type == "gridElement":
stackMove.append("Right") self.stackMove.append("Right")
return stackMove return self.stackMove
# DFS
def dfsFind(self, position, currentOperation, visited, idTable):
#print("Sprawdzam czy stolik")
positionX = position[0]
positionY = position[1] def dfsFind(self, game, currentOperation, idTable):
#print("Pozycja kelnera: ", position) self.game = game
if self.isMoveInRange("Up", position): self.grid = game.grid
if self.grid[positionY - 1][positionX].type == "table": self.currentOperation = currentOperation
if self.grid[positionY - 1][positionX].id == idTable: print("Sprawdzam czy stolik")
self.dfsPaths.append(currentOperation) if self.isMoveInRange("Up"):
print("Dodalem sciezke: ", currentOperation) if self.grid[self.positionY - 1][self.positionX].type == "table":
return 0 if self.grid[self.positionY - 1][self.positionX].id == idTable:
if self.isMoveInRange("Down", position): return self.currentOperation
if self.grid[positionY + 1][positionX].type == "table": if self.isMoveInRange("Down"):
if self.grid[positionY + 1][positionX].id == idTable: if self.grid[self.positionY + 1][self.positionX].type == "table":
self.dfsPaths.append(currentOperation) if self.grid[self.positionY + 1][self.positionX].id == idTable:
print("Dodalem sciezke: ", currentOperation) return self.currentOperation
return 0 if self.isMoveInRange("Left"):
if self.isMoveInRange("Left", position): if self.grid[self.positionY][self.positionX - 1].type == "table":
if self.grid[positionY][positionX - 1].type == "table": if self.grid[self.positionY][self.positionX - 1].id == idTable:
if self.grid[positionY][positionX - 1].id == idTable: return self.currentOperation
self.dfsPaths.append(currentOperation) if self.isMoveInRange("Right"):
print("Dodalem sciezke: ", currentOperation) if self.grid[self.positionY][self.positionX + 1].type == "table":
return 0 if self.grid[self.positionY][self.positionX + 1].id == idTable:
if self.isMoveInRange("Right", position): return self.currentOperation
if self.grid[positionY][positionX + 1].type == "table": print("Sprawdzilem nie stolik")
if self.grid[positionY][positionX + 1].id == idTable:
self.dfsPaths.append(currentOperation)
print("Dodalem sciezke: ", currentOperation)
return 0
# print("Sprawdzilem nie jest to stolik")
steps = [] steps = []
steps.append(self.checkPoss(position, currentOperation)) steps.append(self.checkPoss(self.game, self.currentOperation))
allstep = steps[-1] step = steps[-1]
# print("Naszymi mozliwosciami sa ", allstep) print(step[-1])
if step[-1] == "Left":
if not allstep: self.moveLeft(self.game)
return 0 self.currentOperation.append("Left")
else: if step[-1] == "Right":
for step in allstep: self.moveRight(self.game)
newCurrentOperation = currentOperation[:] self.currentOperation.append("Right")
newCurrentOperation.append(step) if step[-1] == "Up":
newPosition = position[:] self.moveUp(self.game)
newVisited = visited[:] self.currentOperation.append("Up")
if step[-1] == "Down":
#print("newVisited", newVisited) self.moveDown(self.game)
if step == "Left": self.currentOperation.append("Down")
if [newPosition[0] - 1, newPosition[1]] in visited: game.draw()
# print("Tam gdzie chce isc bylem juz: ", step) time.sleep(.500)
continue pygame.display.flip()
newPosition[0] -= 1 self.dfsFind(self.game, self.currentOperation, idTable)
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)

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))