Dodanie macierzy i pelne poruszanie
This commit is contained in:
parent
587f3733b2
commit
1ac31d6c06
@ -1,8 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<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="Dodanie listy wszystkich elementow">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/run.py" beforeDir="false" afterPath="$PROJECT_DIR$/run.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" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
@ -15,8 +17,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="204">
|
||||
<caret line="12" column="33" selection-start-line="12" selection-start-column="33" selection-end-line="12" selection-end-column="33" />
|
||||
<state>
|
||||
<caret column="13" lean-forward="true" selection-start-column="13" selection-end-column="13" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
@ -24,8 +26,8 @@
|
||||
<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="595">
|
||||
<caret line="35" lean-forward="true" selection-start-line="35" selection-end-line="35" />
|
||||
<state relative-caret-position="221">
|
||||
<caret line="25" column="16" selection-start-line="25" selection-start-column="16" selection-end-line="25" selection-end-column="16" />
|
||||
<folding>
|
||||
<element signature="e#0#13#0" expanded="true" />
|
||||
</folding>
|
||||
@ -36,8 +38,8 @@
|
||||
<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="102">
|
||||
<caret line="6" column="33" selection-start-line="6" selection-start-column="33" selection-end-line="6" selection-end-column="33" />
|
||||
<state relative-caret-position="221">
|
||||
<caret line="13" column="50" selection-start-line="13" selection-start-column="50" selection-end-line="13" selection-end-column="50" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
@ -45,8 +47,8 @@
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/run.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="537">
|
||||
<caret line="42" column="42" lean-forward="true" selection-start-line="42" selection-start-column="42" selection-end-line="42" selection-end-column="42" />
|
||||
<state relative-caret-position="112">
|
||||
<caret line="58" column="12" lean-forward="true" selection-start-line="58" selection-start-column="12" selection-end-line="58" selection-end-column="12" />
|
||||
<folding>
|
||||
<element signature="e#0#18#0" expanded="true" />
|
||||
</folding>
|
||||
@ -54,19 +56,10 @@
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<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="85">
|
||||
<caret line="5" selection-start-line="5" selection-end-line="5" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$USER_HOME$/Desktop/pygame-elsa/elsa_gra.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="537">
|
||||
<state relative-caret-position="1020">
|
||||
<caret line="66" column="32" selection-start-line="66" selection-start-column="17" selection-end-line="66" selection-end-column="32" />
|
||||
</state>
|
||||
</provider>
|
||||
@ -227,20 +220,21 @@
|
||||
</component>
|
||||
<component name="ToolWindowManager">
|
||||
<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.17913593" />
|
||||
<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" />
|
||||
<window_info anchor="bottom" id="Run" order="2" sideWeight="0.49947312" weight="0.32936078" />
|
||||
<window_info active="true" anchor="bottom" id="Run" order="2" sideWeight="0.49894625" visible="true" weight="0.32936078" />
|
||||
<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" />
|
||||
<window_info anchor="bottom" id="Event Log" order="9" sideWeight="0.50052685" 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" />
|
||||
<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" />
|
||||
@ -287,6 +281,13 @@
|
||||
<entry file="file://$PROJECT_DIR$/Images/tlo.jpg">
|
||||
<provider selected="true" editor-type-id="images" />
|
||||
</entry>
|
||||
<entry file="file://$USER_HOME$/Desktop/pygame-elsa/elsa_gra.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="1020">
|
||||
<caret line="66" column="32" selection-start-line="66" selection-start-column="17" selection-end-line="66" selection-end-column="32" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$USER_HOME$/Desktop/pygame-elsa/sprites/elsa.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="357">
|
||||
@ -294,6 +295,9 @@
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/Images/21_trisomy_-_Down_syndrome.png">
|
||||
<provider selected="true" editor-type-id="images" />
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/order.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="85">
|
||||
@ -301,41 +305,34 @@
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$USER_HOME$/Desktop/pygame-elsa/elsa_gra.py">
|
||||
<entry file="file://$PROJECT_DIR$/table.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="537">
|
||||
<caret line="66" column="32" selection-start-line="66" selection-start-column="17" selection-end-line="66" selection-end-column="32" />
|
||||
<state>
|
||||
<caret column="13" lean-forward="true" selection-start-column="13" selection-end-column="13" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/table.py">
|
||||
<entry file="file://$PROJECT_DIR$/gridElement.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="204">
|
||||
<caret line="12" column="33" selection-start-line="12" selection-start-column="33" selection-end-line="12" selection-end-column="33" />
|
||||
<state relative-caret-position="221">
|
||||
<caret line="13" column="50" selection-start-line="13" selection-start-column="50" selection-end-line="13" selection-end-column="50" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/run.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="537">
|
||||
<caret line="42" column="42" lean-forward="true" selection-start-line="42" selection-start-column="42" selection-end-line="42" selection-end-column="42" />
|
||||
<state relative-caret-position="112">
|
||||
<caret line="58" column="12" lean-forward="true" selection-start-line="58" selection-start-column="12" selection-end-line="58" selection-end-column="12" />
|
||||
<folding>
|
||||
<element signature="e#0#18#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/gridElement.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="102">
|
||||
<caret line="6" column="33" selection-start-line="6" selection-start-column="33" selection-end-line="6" selection-end-column="33" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/waiter.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="595">
|
||||
<caret line="35" lean-forward="true" selection-start-line="35" selection-end-line="35" />
|
||||
<state relative-caret-position="221">
|
||||
<caret line="25" column="16" selection-start-line="25" selection-start-column="16" selection-end-line="25" selection-end-column="16" />
|
||||
<folding>
|
||||
<element signature="e#0#13#0" expanded="true" />
|
||||
</folding>
|
||||
|
64
run.py
64
run.py
@ -2,34 +2,43 @@ import pygame, sys
|
||||
from waiter import Waiter
|
||||
from table import Table
|
||||
from gridElement import GridElement
|
||||
|
||||
from pygame.math import Vector2
|
||||
|
||||
class Game(object):
|
||||
def __init__(self):
|
||||
pygame.init()
|
||||
|
||||
self.screen = pygame.display.set_mode((1000, 900))
|
||||
self.x = 20
|
||||
self.y = 18
|
||||
self.screen = pygame.display.set_mode((self.x * 50, self.y * 50))
|
||||
self.fpsClock = pygame.time.Clock()
|
||||
self.idTable = 0
|
||||
self.idOrder = 0
|
||||
self.idItem = -1
|
||||
self.waiterNumberInGrid = 0
|
||||
self.waiterNumberInGrid = Vector2()
|
||||
pygame.display.set_caption('Automatic Waiter')
|
||||
self.background = pygame.image.load("./Images/tlo.jpg")
|
||||
|
||||
# The most important list
|
||||
# The most important lists
|
||||
self.grid = []
|
||||
self.row = []
|
||||
|
||||
|
||||
for b in range(18):
|
||||
for i in range(20):
|
||||
for b in range(self.y):
|
||||
for i in range(self.x):
|
||||
if ((i == 0) or (i == 8) or (i == 16)) and ((b == 2) or (b == 8)):
|
||||
self.grid.append(Table(i * 50, b * 50, self))
|
||||
self.row.append(Table(i * 50, b * 50, self))
|
||||
elif i == 18 and b == 14:
|
||||
self.grid.append(Waiter(self, i * 50, b * 50))
|
||||
self.waiterNumberInGrid = (b * 20) + i
|
||||
self.row.append(Waiter(self, i * 50, b * 50))
|
||||
self.waiterNumberInGrid.x = i
|
||||
self.waiterNumberInGrid.y = b
|
||||
|
||||
else:
|
||||
self.grid.append(GridElement(i * 50, b * 50, self))
|
||||
self.row.append(GridElement(i * 50, b * 50, self))
|
||||
if i == 19:
|
||||
self.grid.append(list(self.row))
|
||||
self.row.clear()
|
||||
|
||||
self.showGrid(self.grid)
|
||||
|
||||
|
||||
while True:
|
||||
|
||||
@ -38,22 +47,39 @@ class Game(object):
|
||||
sys.exit(0)
|
||||
|
||||
self.draw()
|
||||
self.grid[self.waiterNumberInGrid].move(self)
|
||||
self.grid[int(self.waiterNumberInGrid.y)][int(self.waiterNumberInGrid.x)].move(self)
|
||||
pygame.display.flip()
|
||||
print(self.waiterNumberInGrid)
|
||||
self.fpsClock.tick(10)
|
||||
|
||||
def draw(self):
|
||||
|
||||
tempTable = []
|
||||
for gridElement in self.grid:
|
||||
if gridElement.type == "gridElement":
|
||||
gridElement.draw()
|
||||
else:
|
||||
tempTable.append(gridElement)
|
||||
for row in self.grid:
|
||||
for gridElement in row:
|
||||
if gridElement.type == "gridElement":
|
||||
gridElement.draw()
|
||||
else:
|
||||
tempTable.append(gridElement)
|
||||
for otherElement in tempTable:
|
||||
otherElement.draw()
|
||||
|
||||
def convert(self, object):
|
||||
if object.type == "gridElement":
|
||||
return 'G'
|
||||
elif object.type == "table":
|
||||
return 'T'
|
||||
elif object.type == "waiter":
|
||||
return 'W'
|
||||
|
||||
def showGrid(self, grid):
|
||||
charakterList = []
|
||||
row = []
|
||||
for y in range(self.y):
|
||||
row = list(map(self.convert, grid[y]))
|
||||
charakterList.append(row)
|
||||
print(row)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Game()
|
||||
|
74
waiter.py
74
waiter.py
@ -14,20 +14,76 @@ class Waiter(object):
|
||||
self.type = "waiter"
|
||||
self.numberInGrid = game.idItem
|
||||
|
||||
def changePosition(self, vector):
|
||||
self.position += vector
|
||||
def moveLeft(self, game):
|
||||
if int(game.waiterNumberInGrid.x) != 0:
|
||||
collisionObject = game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x-1)]
|
||||
if collisionObject.type == "gridElement":
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x - 1)].x += 50
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)].x -= 50
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x - 1)], \
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)] = \
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)], \
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x-1)]
|
||||
game.waiterNumberInGrid.x -= 1
|
||||
else:
|
||||
pass
|
||||
def moveRight(self, game):
|
||||
if int(game.waiterNumberInGrid.x) != 19:
|
||||
collisionObject = game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x + 1)]
|
||||
if collisionObject.type == "gridElement":
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x + 1)].x -= 50
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)].x += 50
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x + 1)], \
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)] = \
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)], \
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x + 1)]
|
||||
game.waiterNumberInGrid.x += 1
|
||||
else:
|
||||
pass
|
||||
|
||||
def moveUp(self, game):
|
||||
if int(game.waiterNumberInGrid.y) != 0:
|
||||
collisionObject = game.grid[int(game.waiterNumberInGrid.y-1)][int(game.waiterNumberInGrid.x)]
|
||||
if collisionObject.type == "gridElement":
|
||||
game.grid[int(game.waiterNumberInGrid.y-1)][int(game.waiterNumberInGrid.x)].y += 50
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)].y -= 50
|
||||
game.grid[int(game.waiterNumberInGrid.y-1)][int(game.waiterNumberInGrid.x)], \
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)] = \
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)], \
|
||||
game.grid[int(game.waiterNumberInGrid.y-1)][int(game.waiterNumberInGrid.x)]
|
||||
game.waiterNumberInGrid.y -= 1
|
||||
else:
|
||||
pass
|
||||
|
||||
def moveDown(self, game):
|
||||
if int(game.waiterNumberInGrid.y) != 17:
|
||||
collisionObject = game.grid[int(game.waiterNumberInGrid.y + 1)][int(game.waiterNumberInGrid.x)]
|
||||
if collisionObject.type == "gridElement":
|
||||
game.grid[int(game.waiterNumberInGrid.y + 1)][int(game.waiterNumberInGrid.x)].y -= 50
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)].y += 50
|
||||
game.grid[int(game.waiterNumberInGrid.y + 1)][int(game.waiterNumberInGrid.x)], \
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)] = \
|
||||
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)], \
|
||||
game.grid[int(game.waiterNumberInGrid.y + 1)][int(game.waiterNumberInGrid.x)]
|
||||
game.waiterNumberInGrid.y += 1
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
def move(self, game):
|
||||
keys = pygame.key.get_pressed()
|
||||
if keys[pygame.K_LEFT]:
|
||||
tmp = game.grid[game.waiterNumberInGrid-1]
|
||||
tmp.x = tmp.x+50
|
||||
game.grid[game.waiterNumberInGrid-1] = game.grid[game.waiterNumberInGrid]
|
||||
game.grid[game.waiterNumberInGrid-1].x -= 50
|
||||
game.grid[game.waiterNumberInGrid] = tmp
|
||||
game.waiterNumberInGrid -= 1
|
||||
|
||||
if keys[pygame.K_LEFT]:
|
||||
self.moveLeft(game)
|
||||
if keys[pygame.K_RIGHT]:
|
||||
self.moveRight(game)
|
||||
if keys[pygame.K_UP]:
|
||||
self.moveUp(game)
|
||||
if keys[pygame.K_DOWN]:
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user