This commit is contained in:
Tomasz Adamczyk 2021-04-09 14:38:25 +02:00
parent face109cb4
commit f5eea95c5b
6 changed files with 52 additions and 49 deletions

View File

@ -4,12 +4,7 @@
<list default="true" id="56453584-72bd-49f4-a39c-fccf91ab20c6" 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$/definitions.py" beforeDir="false" afterPath="$PROJECT_DIR$/definitions.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/field.py" beforeDir="false" afterPath="$PROJECT_DIR$/field.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/map.py" beforeDir="false" afterPath="$PROJECT_DIR$/map.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/plant.py" beforeDir="false" afterPath="$PROJECT_DIR$/plant.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/py.py" beforeDir="false" afterPath="$PROJECT_DIR$/py.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/soil.py" beforeDir="false" afterPath="$PROJECT_DIR$/soil.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/station.py" beforeDir="false" afterPath="$PROJECT_DIR$/station.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tractor.py" beforeDir="false" afterPath="$PROJECT_DIR$/tractor.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@ -106,6 +101,8 @@
<workItem from="1617399305318" duration="2444000" />
<workItem from="1617401891560" duration="232000" />
<workItem from="1617439271903" duration="2500000" />
<workItem from="1617794241086" duration="273000" />
<workItem from="1617966682687" duration="4169000" />
</task>
<servers />
</component>
@ -113,22 +110,22 @@
<option name="version" value="1" />
</component>
<component name="WindowStateProjectService">
<state width="1879" height="295" key="GridCell.Tab.0.bottom" timestamp="1617441783230">
<state width="1879" height="295" key="GridCell.Tab.0.bottom" timestamp="1617971848584">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1617441783230" />
<state width="1879" height="295" key="GridCell.Tab.0.center" timestamp="1617441783230">
<state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1617971848584" />
<state width="1879" height="295" key="GridCell.Tab.0.center" timestamp="1617971848584">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1617441783230" />
<state width="1879" height="295" key="GridCell.Tab.0.left" timestamp="1617441783230">
<state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1617971848584" />
<state width="1879" height="295" key="GridCell.Tab.0.left" timestamp="1617971848584">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1617441783230" />
<state width="1879" height="295" key="GridCell.Tab.0.right" timestamp="1617441783230">
<state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1617971848584" />
<state width="1879" height="295" key="GridCell.Tab.0.right" timestamp="1617971848584">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1617441783230" />
<state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1617971848584" />
<state width="1879" height="364" key="GridCell.Tab.1.bottom" timestamp="1617385468328">
<screen x="0" y="0" width="1920" height="1080" />
</state>
@ -145,12 +142,12 @@
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="364" key="GridCell.Tab.1.right/0.0.1920.1080@0.0.1920.1080" timestamp="1617385468328" />
<state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1617439275650">
<state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1617966682675">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1617439275650" />
<state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1617966682675" />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/SmartTractor$py.coverage" NAME="py Coverage Results" MODIFIED="1617441749283" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/SmartTractor$py.coverage" NAME="py Coverage Results" MODIFIED="1617971807019" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component>
</project>

Binary file not shown.

View File

@ -47,6 +47,10 @@ STATION = pygame.image.load(os.path.join('resources', 'rail_normal.png'))
STATION = pygame.transform.scale(STATION, (BLOCK_SIZE, BLOCK_SIZE))
TRACTOR = pygame.image.load(os.path.join('resources', 'minecart_command_block.png'))
TRACTOR = pygame.transform.scale(TRACTOR, (BLOCK_SIZE, BLOCK_SIZE))
TRACTOR_DIRECTION_EAST = 2
TRACTOR_DIRECTION_NORTH = 1
TRACTOR_DIRECTION_SOUTH = 3
TRACTOR_DIRECTION_WEST = 4
TRACTOR_FERTILIZER = 2
TRACTOR_FUEL = 200
TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE = 20

2
py.py
View File

@ -13,7 +13,7 @@ def main():
collected_plants_dict = {"beetroot": 0, "carrot": 0, "potato": 0, "wheat": 0}
fertilizer_dict = {"beetroot": definitions.TRACTOR_FERTILIZER, "carrot": definitions.TRACTOR_FERTILIZER, "potato": definitions.TRACTOR_FERTILIZER, "wheat": definitions.TRACTOR_FERTILIZER}
station1 = station.Station(collected_plants_dict)
tractor1 = tractor.Tractor(amount_of_seeds_dict, collected_plants_dict, fertilizer_dict, definitions.TRACTOR_FUEL, definitions.TRACTOR_WATER_LEVEL, 0, 0)
tractor1 = tractor.Tractor(amount_of_seeds_dict, collected_plants_dict, definitions.TRACTOR_DIRECTION_NORTH, fertilizer_dict, definitions.TRACTOR_FUEL, definitions.TRACTOR_WATER_LEVEL, 0, 0)
tractor1_rect = pygame.Rect(tractor1.get_x(), tractor1.get_y(), definitions.BLOCK_SIZE, definitions.BLOCK_SIZE)
clock = pygame.time.Clock()
run = True

View File

@ -1,9 +1,10 @@
import definitions
import random
class Tractor:
def __init__(self, amount_of_seeds, collected_plants, fertilizer, fuel, water_level, x, y):
def __init__(self, amount_of_seeds, collected_plants, direction, fertilizer, fuel, water_level, x, y):
self.amount_of_seeds = amount_of_seeds #amount_of_seeds to słownik, przechowuje informacje o posiadanej ilości ziaren dla danej rośliny
self.collected_plants = collected_plants #collected_plants to słownik, przechowuje informacje o zebranych plonach
self.direction = direction #w którą stronę patrzy, zgodnie ze wskazówkami zegara (1 -: godzina 12, 2 : godzina 3, 3 : godzina 6, 4 : godzina 9)
self.fertilizer = fertilizer #fertilizer to słownik, przechowuje informacje o ilości posiadanego nawozu dla konkretnej rośliny
self.fuel = fuel #aktualna ilość paliwa
self.water_level = water_level #aktualna ilość wody do podlewania
@ -21,6 +22,10 @@ class Tractor:
return self.collected_plants[name]
def set_collected_plants(self, name, value): #dla podanej rośliny (name) ustawia łączną ilość zebranych plonów (value)
self.collected_plants[name] = value
def get_direction(self):
return self.direction
def set_direction(self, direction):
self.direction = direction
def get_fertilizer(self, name): #zwraca łączną ilość posiadanego nawozu dla podanej rośliny (name)
return self.fertilizer[name]
def set_fertilizer(self, name, value): #dla podanej rośliny (name) ustawia ilość posiadanego nawozu (value)
@ -41,14 +46,25 @@ class Tractor:
return self.y
def set_y(self, y):
self.y = y
def move_down(self):
self.y = self.y + definitions.BLOCK_SIZE
def move_left(self):
self.x = self.x - definitions.BLOCK_SIZE
def move_right(self):
self.x = self.x + definitions.BLOCK_SIZE
def move_up(self):
self.y = self.y - definitions.BLOCK_SIZE
def move(self):
if self.direction == definitions.TRACTOR_DIRECTION_EAST:
self.x = self.x + definitions.BLOCK_SIZE
elif self.direction == definitions.TRACTOR_DIRECTION_NORTH:
self.y = self.y - definitions.BLOCK_SIZE
elif self.direction == definitions.TRACTOR_DIRECTION_SOUTH:
self.y = self.y + definitions.BLOCK_SIZE
elif self.direction == definitions.TRACTOR_DIRECTION_WEST:
self.x = self.x - definitions.BLOCK_SIZE
def rotate_left(self):
if self.direction == 1:
self.direction = 4
else:
self.direction = self.direction - 1
def rotate_right(self):
if self.direction == 4:
self.direction = 1
else:
self.direction = self.direction + 1
def station_restore(self, station1): #aktualizuje stan stacji pod względem oddanych plonów oraz uzupełnia zapasy traktora
station1.set_collected_plants("beetroot", station1.get_collected_plants("beetroot") + self.get_collected_plants("beetroot"))
self.set_collected_plants("beetroot", 0)
@ -145,41 +161,27 @@ class Tractor:
field.get_soil().set_water_level(False)
field.get_soil().set_state(False)
self.set_collected_plants("wheat", self.get_collected_plants("wheat") + 1)
def is_move_allowed(self, move, tractor1_rect): #sprawdza czy dany ruch, który chce wykonać traktor jest możliwy, zwraca prawdę lub fałsz
if move == 1 and tractor1_rect.y + definitions.BLOCK_SIZE + definitions.BLOCK_SIZE <= definitions.HEIGHT:
def is_move_allowed(self, tractor1_rect): #sprawdza czy dany ruch, który chce wykonać traktor jest możliwy, zwraca prawdę lub fałsz
if self.direction == definitions.TRACTOR_DIRECTION_EAST and tractor1_rect.x + definitions.BLOCK_SIZE < definitions.WIDTH:
return True
elif move == 2 and tractor1_rect.x - definitions.BLOCK_SIZE >= 0:
elif self.direction == definitions.TRACTOR_DIRECTION_NORTH and tractor1_rect.y - definitions.BLOCK_SIZE >= 0:
return True
elif move == 3 and tractor1_rect.x + definitions.BLOCK_SIZE + definitions.BLOCK_SIZE <= definitions.WIDTH:
elif self.direction == definitions.TRACTOR_DIRECTION_SOUTH and tractor1_rect.y + definitions.BLOCK_SIZE < definitions.HEIGHT:
return True
elif move == 4 and tractor1_rect.y - definitions.BLOCK_SIZE >= 0:
elif self.direction == definitions.TRACTOR_DIRECTION_WEST and tractor1_rect.x - definitions.BLOCK_SIZE >= 0:
return True
else:
return False
def tractor1_handle_movement(self, tractor1_rect): #odpowiada za poruszanie się traktora po mapie
loop = True
while loop and self.get_fuel() > 0:
random1 = random.randint(1, 4)
if random1 == 1 and self.is_move_allowed(1, tractor1_rect) is True:
self.move_down()
tractor1_rect.x = self.get_x()
tractor1_rect.y = self.get_y()
loop = False
elif random1 == 2 and self.is_move_allowed(2, tractor1_rect) is True:
self.move_left()
tractor1_rect.x = self.get_x()
tractor1_rect.y = self.get_y()
loop = False
elif random1 == 3 and self.is_move_allowed(3, tractor1_rect) is True:
self.move_right()
tractor1_rect.x = self.get_x()
tractor1_rect.y = self.get_y()
loop = False
elif random1 == 4 and self.is_move_allowed(4, tractor1_rect) is True:
self.move_up()
if self.is_move_allowed(tractor1_rect) is True:
self.move()
tractor1_rect.x = self.get_x()
tractor1_rect.y = self.get_y()
loop = False
else:
self.rotate_right()
self.set_fuel(self.get_fuel() - 1)
if tractor1_rect.x == 0 and tractor1_rect.y == 0:
self.set_fuel(definitions.TRACTOR_FUEL)