Środowisko v.1.0
Wyświetlanie kraty, stworzenie obiektu bota (Waiter) wraz z atrybutami i metodami (razem z testowym poruszaniem się przy pomocy klawiszy) oraz obiektu stół (Table). Wyświetlony testowo 1 stół oraz bot na środku planszy.
This commit is contained in:
parent
3072ea9e89
commit
beec67e2ff
11
.idea/DSZI.iml
Normal file
11
.idea/DSZI.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TestRunnerService">
|
||||
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
|
||||
</component>
|
||||
</module>
|
4
.idea/encodings.xml
Normal file
4
.idea/encodings.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
|
||||
</project>
|
4
.idea/misc.xml
Normal file
4
.idea/misc.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
|
||||
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/DSZI.iml" filepath="$PROJECT_DIR$/.idea/DSZI.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
11
Restaurant/.idea/Restaurant.iml
Normal file
11
Restaurant/.idea/Restaurant.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.7" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TestRunnerService">
|
||||
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
|
||||
</component>
|
||||
</module>
|
4
Restaurant/.idea/encodings.xml
Normal file
4
Restaurant/.idea/encodings.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
|
||||
</project>
|
4
Restaurant/.idea/misc.xml
Normal file
4
Restaurant/.idea/misc.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
|
||||
</project>
|
8
Restaurant/.idea/modules.xml
Normal file
8
Restaurant/.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/Restaurant.iml" filepath="$PROJECT_DIR$/.idea/Restaurant.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
156
Restaurant/.idea/workspace.xml
Normal file
156
Restaurant/.idea/workspace.xml
Normal file
@ -0,0 +1,156 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="76f12f94-8135-4028-8378-41c67cca6cd2" name="Default Changelist" comment="" />
|
||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="FileEditorManager">
|
||||
<leaf>
|
||||
<file pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/main.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="277">
|
||||
<caret line="18" column="61" selection-start-line="18" selection-start-column="61" selection-end-line="18" selection-end-column="61" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
</leaf>
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Python Script" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="IdeDocumentHistory">
|
||||
<option name="CHANGED_PATHS">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/main.py" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectFrameBounds" extendedState="7">
|
||||
<option name="x" value="574" />
|
||||
<option name="y" value="-19" />
|
||||
<option name="width" value="694" />
|
||||
<option name="height" value="735" />
|
||||
</component>
|
||||
<component name="ProjectView">
|
||||
<navigator proportions="" version="1">
|
||||
<foldersAlwaysOnTop value="true" />
|
||||
</navigator>
|
||||
<panes>
|
||||
<pane id="Scope" />
|
||||
<pane id="ProjectPane">
|
||||
<subPane>
|
||||
<expand>
|
||||
<path>
|
||||
<item name="Restaurant" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="Restaurant" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
</expand>
|
||||
<select />
|
||||
</subPane>
|
||||
</pane>
|
||||
</panes>
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
|
||||
</component>
|
||||
<component name="RecentsManager">
|
||||
<key name="MoveFile.RECENT_KEYS">
|
||||
<recent name="C:\Users\Sara\PycharmProjects\Restaurant" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="RunDashboard">
|
||||
<option name="ruleStates">
|
||||
<list>
|
||||
<RuleState>
|
||||
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
|
||||
</RuleState>
|
||||
<RuleState>
|
||||
<option name="name" value="StatusDashboardGroupingRule" />
|
||||
</RuleState>
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="RunManager">
|
||||
<configuration name="main" type="PythonConfigurationType" factoryName="Python" temporary="true">
|
||||
<module name="Restaurant" />
|
||||
<option name="INTERPRETER_OPTIONS" value="" />
|
||||
<option name="PARENT_ENVS" value="true" />
|
||||
<envs>
|
||||
<env name="PYTHONUNBUFFERED" value="1" />
|
||||
</envs>
|
||||
<option name="SDK_HOME" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<option name="IS_MODULE_SDK" value="true" />
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/main.py" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||
<option name="EMULATE_TERMINAL" value="false" />
|
||||
<option name="MODULE_MODE" value="false" />
|
||||
<option name="REDIRECT_INPUT" value="false" />
|
||||
<option name="INPUT_FILE" value="" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Python.main" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<component name="SvnConfiguration">
|
||||
<configuration />
|
||||
</component>
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="76f12f94-8135-4028-8378-41c67cca6cd2" name="Default Changelist" comment="" />
|
||||
<created>1584915187051</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1584915187051</updated>
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="ToolWindowManager">
|
||||
<frame x="-8" y="-8" width="1382" height="744" extended-state="6" />
|
||||
<editor active="true" />
|
||||
<layout>
|
||||
<window_info id="Favorites" side_tool="true" />
|
||||
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.122023806" />
|
||||
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
|
||||
<window_info anchor="bottom" id="Version Control" />
|
||||
<window_info anchor="bottom" id="Python Console" />
|
||||
<window_info anchor="bottom" id="Terminal" />
|
||||
<window_info anchor="bottom" id="Event Log" sideWeight="0.50074404" side_tool="true" weight="0.3289689" />
|
||||
<window_info anchor="bottom" id="Message" order="0" />
|
||||
<window_info anchor="bottom" id="Find" order="1" />
|
||||
<window_info active="true" anchor="bottom" id="Run" order="2" sideWeight="0.49925596" visible="true" weight="0.3289689" />
|
||||
<window_info anchor="bottom" id="Debug" order="3" weight="0.39934534" />
|
||||
<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" />
|
||||
<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" />
|
||||
</layout>
|
||||
</component>
|
||||
<component name="editorHistoryManager">
|
||||
<entry file="file://$PROJECT_DIR$/main.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="277">
|
||||
<caret line="18" column="61" selection-start-line="18" selection-start-column="61" selection-end-line="18" selection-end-column="61" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</component>
|
||||
</project>
|
BIN
Restaurant/Table-croped.png
Normal file
BIN
Restaurant/Table-croped.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1008 B |
118
Restaurant/main.py
Normal file
118
Restaurant/main.py
Normal file
@ -0,0 +1,118 @@
|
||||
import pygame
|
||||
|
||||
|
||||
class Table(object):
|
||||
def __init__(self, pos):
|
||||
self.pos = pos
|
||||
|
||||
def move(self, newx, newy):
|
||||
self.pos[0] = newx
|
||||
self.pos[1] = newy
|
||||
|
||||
def draw(self, surface):
|
||||
image = pygame.image.load(r'Table-croped.png')
|
||||
image = pygame.transform.scale(image, (sizeBetween - 1, sizeBetween - 1))
|
||||
|
||||
i = self.pos[0]
|
||||
j = self.pos[1]
|
||||
|
||||
surface.blit(image, (i*sizeBetween+1, j*sizeBetween+1))
|
||||
|
||||
|
||||
class Waiter(object):
|
||||
def __init__(self, color, pos):
|
||||
self.color = color
|
||||
self.pos = pos
|
||||
self.dirnx = 0
|
||||
self.dirny = 1
|
||||
|
||||
def move(self):
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
pygame.quit()
|
||||
quit()
|
||||
|
||||
keys = pygame.key.get_pressed()
|
||||
|
||||
for key in keys:
|
||||
if keys[pygame.K_LEFT]:
|
||||
self.dirnx = -1
|
||||
self.dirny = 0
|
||||
self.pos = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny)
|
||||
break
|
||||
# te break musiałam dodać, bo w przeciwnym wypadku zamiast jednego kroku robił 303 - jeden za drugim
|
||||
# nie wiem dlaczego tak było, po zmianie sterowania z klawiatury na bota samego w sobie nie powinno
|
||||
# być z tym problemów, to jest na razie tylko, żeby pokazać, że ten ruch jest
|
||||
|
||||
elif keys[pygame.K_RIGHT]:
|
||||
self.dirnx = 1
|
||||
self.dirny = 0
|
||||
self.pos = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny)
|
||||
break
|
||||
|
||||
elif keys[pygame.K_UP]:
|
||||
self.dirnx = 0
|
||||
self.dirny = -1
|
||||
self.pos = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny)
|
||||
break
|
||||
|
||||
elif keys[pygame.K_DOWN]:
|
||||
self.dirnx = 0
|
||||
self.dirny = 1
|
||||
self.pos = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny)
|
||||
break
|
||||
|
||||
def reset(self, pos):
|
||||
self.pos = pos
|
||||
|
||||
def draw(self, surface):
|
||||
i = self.pos[0]
|
||||
j = self.pos[1]
|
||||
|
||||
pygame.draw.rect(surface, self.color, (i*sizeBetween+1, j*sizeBetween+1, sizeBetween-1, sizeBetween-1))
|
||||
|
||||
|
||||
def drawGrid(width, rows, surface):
|
||||
x = 0
|
||||
y = 0
|
||||
|
||||
for i in range(rows):
|
||||
x = x + sizeBetween
|
||||
y = y + sizeBetween
|
||||
|
||||
pygame.draw.line(surface, (255, 255, 255), (x, 0), (x, width))
|
||||
pygame.draw.line(surface, (255, 255, 255), (0, y), (width, y))
|
||||
|
||||
|
||||
def redrawWindow(surface):
|
||||
surface.fill(beige)
|
||||
bot.draw(surface)
|
||||
table1.draw(surface)
|
||||
drawGrid(width, rows, surface)
|
||||
pygame.display.update()
|
||||
|
||||
|
||||
def main():
|
||||
global width, rows, bot, beige, white, black, sizeBetween, table1
|
||||
# skróty do kolorów
|
||||
beige = (255, 205, 178)
|
||||
white = (255, 255, 255)
|
||||
black = (0, 0, 0)
|
||||
|
||||
width = 600
|
||||
rows = 15
|
||||
sizeBetween = width // rows
|
||||
window = pygame.display.set_mode((width, width))
|
||||
bot = Waiter((255, 0, 0), [7, 7])
|
||||
table1 = Table([5, 5])
|
||||
flag = True
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
while flag:
|
||||
pygame.time.delay(50)
|
||||
clock.tick(10)
|
||||
bot.move()
|
||||
redrawWindow(window)
|
||||
|
||||
|
||||
main()
|
Loading…
Reference in New Issue
Block a user