dodanie stacji

This commit is contained in:
Tomasz Adamczyk 2021-03-29 17:58:15 +02:00
parent 9ab7b66267
commit 2b38eb30f3
11 changed files with 52 additions and 32 deletions

View File

@ -4,9 +4,8 @@
<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$/plant.py" beforeDir="false" afterPath="$PROJECT_DIR$/plant.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/fertilizer.py" beforeDir="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$/tractor.py" beforeDir="false" afterPath="$PROJECT_DIR$/tractor.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@ -90,6 +89,7 @@
<workItem from="1616517453952" duration="124000" />
<workItem from="1616517732434" duration="704000" />
<workItem from="1616874983490" duration="2052000" />
<workItem from="1617029025208" duration="4359000" />
</task>
<servers />
</component>
@ -97,22 +97,22 @@
<option name="version" value="1" />
</component>
<component name="WindowStateProjectService">
<state width="1879" height="295" key="GridCell.Tab.0.bottom" timestamp="1616877053760">
<state width="1879" height="295" key="GridCell.Tab.0.bottom" timestamp="1617033424354">
<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="1616877053760" />
<state width="1879" height="295" key="GridCell.Tab.0.center" timestamp="1616877053760">
<state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1617033424354" />
<state width="1879" height="295" key="GridCell.Tab.0.center" timestamp="1617033424354">
<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="1616877053760" />
<state width="1879" height="295" key="GridCell.Tab.0.left" timestamp="1616877053760">
<state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1617033424354" />
<state width="1879" height="295" key="GridCell.Tab.0.left" timestamp="1617033424354">
<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="1616877053760" />
<state width="1879" height="295" key="GridCell.Tab.0.right" timestamp="1616877053760">
<state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1617033424354" />
<state width="1879" height="295" key="GridCell.Tab.0.right" timestamp="1617033424354">
<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="1616877053760" />
<state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1617033424354" />
<state width="1879" height="364" key="GridCell.Tab.1.bottom" timestamp="1616326478876">
<screen x="0" y="0" width="1920" height="1080" />
</state>
@ -129,12 +129,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="1616326478875" />
<state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1616874983207">
<state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1617029024880">
<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="1616874983207" />
<state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1617029024880" />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/SmartTractor$py.coverage" NAME="py Coverage Results" MODIFIED="1616876630669" 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="1617033003775" 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.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -13,7 +13,9 @@ WIN = pygame.display.set_mode((WIDTH, HEIGHT))
TRACTOR = pygame.image.load(os.path.join('resources', 'tractor.png'))
TRACTOR = pygame.transform.scale(TRACTOR, (BLOCK_SIZE, BLOCK_SIZE))
TRACTOR_FERTILIZER = 2
WHEAT_GROW_TIME = 5
TRACTOR_FUEL = 5
TRACTOR_WATER_LEVEL = 3
WHEAT_GROW_TIME = 50
WHEAT_MAXIMUM_STATE = 21
WHEATSTAGE1 = pygame.image.load(os.path.join('resources', 'wheat_stage1.png'))
WHEATSTAGE1 = pygame.transform.scale(WHEATSTAGE1, (BLOCK_SIZE, BLOCK_SIZE))

View File

@ -1,7 +0,0 @@
class Fertilizer:
def __init__(self, name):
self.name = name
def get_name(self):
return self.name
def set_name(self, name):
self.name = name

20
py.py
View File

@ -39,17 +39,21 @@ def fill_map():
elif field.get_soil().get_state() is True and field.get_soil().get_water_level() is True:
block = definitions.FARMLANDMOIST
definitions.WIN.blit(block, (rect.x, rect.y))
def do_work(tractor1_rect):
def do_work(tractor1, tractor1_rect):
x = int(tractor1_rect.x/100)
y = int(tractor1_rect.y/100)
field = fields[x][y]
if field.get_soil().get_state() is False:
field.get_soil().set_state(True)
elif field.get_soil().get_state() is True and field.get_soil().get_water_level() is False:
elif field.get_soil().get_state() is True and field.get_soil().get_water_level() is False and tractor1.get_water_level() > 0:
tractor1.set_water_level(tractor1.get_water_level() - 1)
field.get_soil().set_water_level(True)
elif field.get_plant().get_state() == 0:
elif field.get_soil().get_state() is True and field.get_soil().get_water_level() is True and field.get_plant().get_state() == 0:
field.get_plant().set_name("wheat")
field.get_plant().set_state(1)
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.WHEAT_MAXIMUM_STATE - definitions.WHEAT_GROW_TIME and tractor1.get_fertilizer("wheat") > 0:
tractor1.set_fertilizer("wheat", (tractor1.get_fertilizer("wheat") - 1))
field.get_plant().set_state(field.get_plant().get_state() + definitions.WHEAT_GROW_TIME)
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() == definitions.WHEAT_MAXIMUM_STATE:
field.get_plant().set_state(0)
field.get_soil().set_water_level(False)
@ -77,7 +81,7 @@ def is_move_allowed(move, tractor1_rect):
return False
def tractor1_handle_movement(tractor1, tractor1_rect):
loop = True
while loop:
while loop and tractor1.get_fuel() > 0:
random1 = random.randint(1, 4)
if ((random1 == 1) and (is_move_allowed(1, tractor1_rect) is True)):
tractor1.move_down()
@ -99,10 +103,14 @@ def tractor1_handle_movement(tractor1, tractor1_rect):
tractor1_rect.x = tractor1.get_x()
tractor1_rect.y = tractor1.get_y()
loop = False
tractor1.set_fuel(tractor1.get_fuel() - 1)
if tractor1_rect.x == 0 and tractor1_rect.y == 0:
tractor1.set_fuel(definitions.TRACTOR_FUEL)
tractor1.set_water_level(definitions.TRACTOR_WATER_LEVEL)
def main():
create_base_map()
fertilizer_dict = {"beetroot": definitions.TRACTOR_FERTILIZER, "carrot": definitions.TRACTOR_FERTILIZER, "potato": definitions.TRACTOR_FERTILIZER, "wheat": definitions.TRACTOR_FERTILIZER}
tractor1 = tractor.Tractor(fertilizer_dict, 0, 0)
tractor1 = tractor.Tractor(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
@ -114,7 +122,7 @@ def main():
draw_window(tractor1_rect)
grow_plants()
tractor1_handle_movement(tractor1, tractor1_rect)
do_work(tractor1_rect)
do_work(tractor1, tractor1_rect)
pygame.quit()
if __name__ == "__main__":
main()

7
station.py Normal file
View File

@ -0,0 +1,7 @@
class Station:
def __init__(self, collected_plants):
self.collected_plants = collected_plants
def get_collected_plants(self, name):
return self.collected_plants[name]
def set_collected_plants(self, name, value):
self.collected_plants[name] = value

View File

@ -1,13 +1,23 @@
import definitions
class Tractor:
def __init__(self, fertilizer, x, y):
def __init__(self, fertilizer, fuel, water_level, x, y):
self.fertilizer = fertilizer
self.fuel = fuel
self.water_level = water_level
self.x = x
self.y = y
def get_fertilizer(self):
return self.fertilizer
def set_fertilizer(self, fertilizer):
self.fertilizer = fertilizer
def get_fertilizer(self, name):
return self.fertilizer[name]
def set_fertilizer(self, name, value):
self.fertilizer[name] = value
def get_fuel(self):
return self.fuel
def set_fuel(self, fuel):
self.fuel = fuel
def get_water_level(self):
return self.water_level
def set_water_level(self, water_level):
self.water_level = water_level
def get_x(self):
return self.x
def set_x(self, x):