This commit is contained in:
Tomasz Adamczyk 2021-03-27 21:31:22 +01:00
parent a431a57049
commit 9ab7b66267
10 changed files with 53 additions and 24 deletions

View File

@ -4,7 +4,10 @@
<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$/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" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -86,6 +89,7 @@
<workItem from="1616515878589" duration="110000" />
<workItem from="1616517453952" duration="124000" />
<workItem from="1616517732434" duration="704000" />
<workItem from="1616874983490" duration="2052000" />
</task>
<servers />
</component>
@ -93,22 +97,22 @@
<option name="version" value="1" />
</component>
<component name="WindowStateProjectService">
<state width="1879" height="295" key="GridCell.Tab.0.bottom" timestamp="1616518442382">
<state width="1879" height="295" key="GridCell.Tab.0.bottom" timestamp="1616877053760">
<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="1616518442382" />
<state width="1879" height="295" key="GridCell.Tab.0.center" timestamp="1616518442382">
<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">
<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="1616518442382" />
<state width="1879" height="295" key="GridCell.Tab.0.left" timestamp="1616518442382">
<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">
<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="1616518442382" />
<state width="1879" height="295" key="GridCell.Tab.0.right" timestamp="1616518442382">
<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">
<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="1616518442382" />
<state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1616877053760" />
<state width="1879" height="364" key="GridCell.Tab.1.bottom" timestamp="1616326478876">
<screen x="0" y="0" width="1920" height="1080" />
</state>
@ -125,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="1616517731968">
<state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1616874983207">
<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="1616517731968" />
<state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1616874983207" />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/SmartTractor$py.coverage" NAME="py Coverage Results" MODIFIED="1616518408138" 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="1616876630669" 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.

View File

@ -12,6 +12,7 @@ WIDTH, HEIGHT = 1000, 1000
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
WHEAT_MAXIMUM_STATE = 21
WHEATSTAGE1 = pygame.image.load(os.path.join('resources', 'wheat_stage1.png'))

7
fertilizer.py Normal file
View File

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

View File

@ -1,6 +1,11 @@
class Plant:
def __init__(self, state):
def __init__(self, name, state):
self.name = name
self.state = state
def get_name(self):
return self.name
def set_name(self, name):
self.name = name
def get_state(self):
return self.state
def set_state(self, state):

22
py.py
View File

@ -12,8 +12,8 @@ def create_base_map():
temp_map_field = []
for j in range(10):
temp_rect = pygame.Rect(i * definitions.BLOCK_SIZE, j * definitions.BLOCK_SIZE, definitions.BLOCK_SIZE, definitions.BLOCK_SIZE)
temp_soil = soil.Soil(False, False)
temp_plant = plant.Plant(0)
temp_soil = soil.Soil(None, False, False)
temp_plant = plant.Plant("wheat", 0)
temp_field = field.Field(temp_plant, temp_rect, temp_soil)
temp_map_field.append(temp_field)
fields.append(temp_map_field)
@ -22,15 +22,15 @@ def fill_map():
for j in range(10):
field = fields[i][j]
rect = field.get_rect()
if field.get_plant().get_state() > 0 and field.get_plant().get_state() <= 1 * definitions.WHEAT_GROW_TIME:
if field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 0 and field.get_plant().get_state() <= 1 * definitions.WHEAT_GROW_TIME:
block = definitions.WHEATSTAGE1
elif field.get_plant().get_state() > 1 * definitions.WHEAT_GROW_TIME and field.get_plant().get_state() <= 2 * definitions.WHEAT_GROW_TIME:
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 1 * definitions.WHEAT_GROW_TIME and field.get_plant().get_state() <= 2 * definitions.WHEAT_GROW_TIME:
block = definitions.WHEATSTAGE2
elif field.get_plant().get_state() > 2 * definitions.WHEAT_GROW_TIME and field.get_plant().get_state() <= 3 * definitions.WHEAT_GROW_TIME:
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 2 * definitions.WHEAT_GROW_TIME and field.get_plant().get_state() <= 3 * definitions.WHEAT_GROW_TIME:
block = definitions.WHEATSTAGE3
elif field.get_plant().get_state() > 3 * definitions.WHEAT_GROW_TIME and field.get_plant().get_state() <= 4 * definitions.WHEAT_GROW_TIME:
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 3 * definitions.WHEAT_GROW_TIME and field.get_plant().get_state() <= 4 * definitions.WHEAT_GROW_TIME:
block = definitions.WHEATSTAGE4
elif field.get_plant().get_state() == 4 *definitions.WHEAT_GROW_TIME + 1:
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() == 4 *definitions.WHEAT_GROW_TIME + 1:
block = definitions.WHEATSTAGE5
elif field.get_soil().get_state() is False:
block = definitions.DIRT
@ -48,8 +48,9 @@ def do_work(tractor1_rect):
elif field.get_soil().get_state() is True and field.get_soil().get_water_level() is False:
field.get_soil().set_water_level(True)
elif field.get_plant().get_state() == 0:
field.get_plant().set_name("wheat")
field.get_plant().set_state(1)
elif field.get_plant().get_state() == definitions.WHEAT_MAXIMUM_STATE:
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)
field.get_soil().set_state(False)
@ -61,7 +62,7 @@ def grow_plants():
for i in range(10):
for j in range(10):
field = fields[i][j]
if field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.WHEAT_MAXIMUM_STATE:
if field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.WHEAT_MAXIMUM_STATE:
field.get_plant().set_state(field.get_plant().get_state() + 1)
def is_move_allowed(move, tractor1_rect):
if ((move == 1) and (tractor1_rect.y + definitions.BLOCK_SIZE + definitions.BLOCK_SIZE <= definitions.HEIGHT)):
@ -100,7 +101,8 @@ def tractor1_handle_movement(tractor1, tractor1_rect):
loop = False
def main():
create_base_map()
tractor1 = tractor.Tractor(0, 0)
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_rect = pygame.Rect(tractor1.get_x(), tractor1.get_y(), definitions.BLOCK_SIZE, definitions.BLOCK_SIZE)
clock = pygame.time.Clock()
run = True

View File

@ -1,7 +1,12 @@
class Soil:
def __init__(self, state, water_level):
def __init__(self, fertilizer, state, water_level):
self.fertilizer = fertilizer
self.state = state
self.water_level = water_level
def get_fertilizer(self):
return self.fertilizer
def set_fertilizer(self, fertilizer):
self.fertilizer = fertilizer
def get_state(self):
return self.state
def set_state(self, state):

View File

@ -1,8 +1,13 @@
import definitions
class Tractor:
def __init__(self, x, y):
def __init__(self, fertilizer, x, y):
self.fertilizer = fertilizer
self.x = x
self.y = y
def get_fertilizer(self):
return self.fertilizer
def set_fertilizer(self, fertilizer):
self.fertilizer = fertilizer
def get_x(self):
return self.x
def set_x(self, x):