uporządkowanie kodu, odnawianie na stacji

This commit is contained in:
Tomasz Adamczyk 2021-04-03 00:16:53 +02:00
parent 9355d382e5
commit bbffd5b933
14 changed files with 268 additions and 218 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$/resources/rail_detector_powered.png" beforeDir="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" />
@ -96,6 +99,8 @@
<workItem from="1617370723478" duration="1838000" />
<workItem from="1617372800679" duration="949000" />
<workItem from="1617383739568" duration="1714000" />
<workItem from="1617396071094" duration="3170000" />
<workItem from="1617399305318" duration="2444000" />
</task>
<servers />
</component>
@ -103,22 +108,22 @@
<option name="version" value="1" />
</component>
<component name="WindowStateProjectService">
<state width="1879" height="364" key="GridCell.Tab.0.bottom" timestamp="1617385468328">
<state width="1879" height="295" key="GridCell.Tab.0.bottom" timestamp="1617401771495">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="364" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1617385468328" />
<state width="1879" height="364" key="GridCell.Tab.0.center" timestamp="1617385468327">
<state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1617401771495" />
<state width="1879" height="295" key="GridCell.Tab.0.center" timestamp="1617401771495">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="364" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1617385468327" />
<state width="1879" height="364" key="GridCell.Tab.0.left" timestamp="1617385468327">
<state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1617401771495" />
<state width="1879" height="295" key="GridCell.Tab.0.left" timestamp="1617401771494">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="364" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1617385468327" />
<state width="1879" height="364" key="GridCell.Tab.0.right" timestamp="1617385468327">
<state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1617401771494" />
<state width="1879" height="295" key="GridCell.Tab.0.right" timestamp="1617401771495">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="364" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1617385468327" />
<state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1617401771495" />
<state width="1879" height="364" key="GridCell.Tab.1.bottom" timestamp="1617385468328">
<screen x="0" y="0" width="1920" height="1080" />
</state>
@ -135,12 +140,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="1617383739858">
<state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1617396163208">
<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="1617383739858" />
<state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1617396163208" />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/SmartTractor$py.coverage" NAME="py Coverage Results" MODIFIED="1617385384539" 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="1617401748390" 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

@ -40,7 +40,10 @@ POTATOES_STAGE_2 = pygame.image.load(os.path.join('resources', 'potatoes_stage_2
POTATOES_STAGE_2 = pygame.transform.scale(POTATOES_STAGE_2, (BLOCK_SIZE, BLOCK_SIZE))
POTATOES_STAGE_3 = pygame.image.load(os.path.join('resources', 'potatoes_stage_3.png'))
POTATOES_STAGE_3 = pygame.transform.scale(POTATOES_STAGE_3, (BLOCK_SIZE, BLOCK_SIZE))
WINDOW = pygame.display.set_mode((WIDTH, HEIGHT))
SPONGE = pygame.image.load(os.path.join('resources', 'sponge.png'))
SPONGE = pygame.transform.scale(SPONGE, (BLOCK_SIZE, BLOCK_SIZE))
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_FERTILIZER = 2
@ -66,3 +69,4 @@ WHEAT_STAGE_6 = pygame.image.load(os.path.join('resources', 'wheat_stage_6.png')
WHEAT_STAGE_6 = pygame.transform.scale(WHEAT_STAGE_6, (BLOCK_SIZE, BLOCK_SIZE))
WHEAT_STAGE_7 = pygame.image.load(os.path.join('resources', 'wheat_stage_7.png'))
WHEAT_STAGE_7 = pygame.transform.scale(WHEAT_STAGE_7, (BLOCK_SIZE, BLOCK_SIZE))
WINDOW = pygame.display.set_mode((WIDTH, HEIGHT))

87
map.py Normal file
View File

@ -0,0 +1,87 @@
import definitions
import field
import plant
import pygame
import soil
class Map:
def __init__(self, fields):
self.fields = fields
def get_fields(self):
return self.fields
def set_fields(self, fields):
self.fields = fields
def create_base_map(self):
for i in range(definitions.WIDTH_AMOUNT):
temp_map_field = []
for j in range(definitions.HEIGHT_AMOUNT):
temp_rect = pygame.Rect(i * definitions.BLOCK_SIZE, j * definitions.BLOCK_SIZE, definitions.BLOCK_SIZE, definitions.BLOCK_SIZE)
if i == 0 and j == 0:
temp_plant = plant.Plant("station", -1)
else:
temp_plant = plant.Plant("none", 0)
temp_soil = soil.Soil(False, False, False)
temp_field = field.Field(temp_plant, temp_rect, temp_soil)
temp_map_field.append(temp_field)
self.fields.append(temp_map_field)
def fill_map(self):
for i in range(definitions.WIDTH_AMOUNT):
for j in range(definitions.HEIGHT_AMOUNT):
field = self.fields[i][j]
rect = field.get_rect()
if field.get_plant().get_name() == "station" and field.get_plant().get_state() == -1:
block = definitions.STATION
elif field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() <= 1 * definitions.BEETROOTS_GROW_TIME:
block = definitions.BEETROOTS_STAGE_0
elif field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() > 1 * definitions.BEETROOTS_GROW_TIME and field.get_plant().get_state() <= 2 * definitions.BEETROOTS_GROW_TIME:
block = definitions.BEETROOTS_STAGE_1
elif field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() > 2 * definitions.BEETROOTS_GROW_TIME and field.get_plant().get_state() <= 3 * definitions.BEETROOTS_GROW_TIME:
block = definitions.BEETROOTS_STAGE_2
elif field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() == definitions.BEETROOTS_MAXIMUM_STATE:
block = definitions.BEETROOTS_STAGE_3
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() <= 1 * definitions.CARROTS_GROW_TIME:
block = definitions.CARROTS_STAGE_0
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() > 1 * definitions.CARROTS_GROW_TIME and field.get_plant().get_state() <= 2 * definitions.CARROTS_GROW_TIME:
block = definitions.CARROTS_STAGE_1
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() > 2 * definitions.CARROTS_GROW_TIME and field.get_plant().get_state() <= 3 * definitions.CARROTS_GROW_TIME:
block = definitions.CARROTS_STAGE_2
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() == definitions.CARROTS_MAXIMUM_STATE:
block = definitions.CARROTS_STAGE_3
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() > 0 and field.get_plant().get_state() <= 1 * definitions.POTATOES_GROW_TIME:
block = definitions.POTATOES_STAGE_0
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() > 1 * definitions.POTATOES_GROW_TIME and field.get_plant().get_state() <= 2 * definitions.POTATOES_GROW_TIME:
block = definitions.POTATOES_STAGE_1
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() > 2 * definitions.POTATOES_GROW_TIME and field.get_plant().get_state() <= 3 * definitions.POTATOES_GROW_TIME:
block = definitions.POTATOES_STAGE_2
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() == definitions.POTATOES_MAXIMUM_STATE:
block = definitions.POTATOES_STAGE_3
elif 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.WHEAT_STAGE_0
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.WHEAT_STAGE_1
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.WHEAT_STAGE_2
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.WHEAT_STAGE_3
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 4 * definitions.WHEAT_GROW_TIME and field.get_plant().get_state() <= 5 * definitions.WHEAT_GROW_TIME:
block = definitions.WHEAT_STAGE_4
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 5 * definitions.WHEAT_GROW_TIME and field.get_plant().get_state() <= 6 * definitions.WHEAT_GROW_TIME:
block = definitions.WHEAT_STAGE_5
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 6 * definitions.WHEAT_GROW_TIME and field.get_plant().get_state() <= 7 * definitions.WHEAT_GROW_TIME:
block = definitions.WHEAT_STAGE_6
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() == definitions.WHEAT_MAXIMUM_STATE:
block = definitions.WHEAT_STAGE_7
elif field.get_soil().get_state() is False:
block = definitions.DIRT
elif field.get_soil().get_state() is True and field.get_soil().get_water_level() is False:
block = definitions.FARMLAND_DRY
elif field.get_soil().get_state() is True and field.get_soil().get_water_level() is True:
block = definitions.FARMLAND_WET
if block == definitions.STATION:
definitions.WINDOW.blit(definitions.SPONGE, (rect.x, rect.y))
elif block != definitions.DIRT or block != definitions.FARMLAND_DRY or block != definitions.FARMLAND_WET:
definitions.WINDOW.blit(definitions.FARMLAND_WET, (rect.x, rect.y))
definitions.WINDOW.blit(block, (rect.x, rect.y))
def draw_window(self, tractor1_rect):
self.fill_map()
definitions.WINDOW.blit(definitions.TRACTOR, (tractor1_rect.x, tractor1_rect.y))
pygame.display.update()

View File

@ -1,3 +1,4 @@
import definitions
class Plant:
def __init__(self, name, state):
self.name = name
@ -10,3 +11,16 @@ class Plant:
return self.state
def set_state(self, state):
self.state = state
@staticmethod
def grow_plants(map1):
for i in range(definitions.WIDTH_AMOUNT):
for j in range(definitions.HEIGHT_AMOUNT):
field = map1.get_fields()[i][j]
if field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.BEETROOTS_MAXIMUM_STATE:
field.get_plant().set_state(field.get_plant().get_state() + 1)
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.CARROTS_MAXIMUM_STATE:
field.get_plant().set_state(field.get_plant().get_state() + 1)
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.POTATOES_MAXIMUM_STATE:
field.get_plant().set_state(field.get_plant().get_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:
field.get_plant().set_state(field.get_plant().get_state() + 1)

212
py.py
View File

@ -1,211 +1,17 @@
import definitions
import field
import map
import plant
import pygame
import random
import soil
import station
import tractor
pygame.display.set_caption("Smart Tractor")
fields = []
def create_base_map():
for i in range(definitions.WIDTH_AMOUNT):
temp_map_field = []
for j in range(definitions.HEIGHT_AMOUNT):
temp_rect = pygame.Rect(i * definitions.BLOCK_SIZE, j * definitions.BLOCK_SIZE, definitions.BLOCK_SIZE, definitions.BLOCK_SIZE)
temp_soil = soil.Soil(False, False, False)
temp_plant = plant.Plant("none", 0)
temp_field = field.Field(temp_plant, temp_rect, temp_soil)
temp_map_field.append(temp_field)
fields.append(temp_map_field)
def fill_map():
for i in range(definitions.WIDTH_AMOUNT):
for j in range(definitions.HEIGHT_AMOUNT):
field = fields[i][j]
rect = field.get_rect()
if field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() <= 1 * definitions.BEETROOTS_GROW_TIME:
block = definitions.BEETROOTS_STAGE_0
elif field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() > 1 * definitions.BEETROOTS_GROW_TIME and field.get_plant().get_state() <= 2 * definitions.BEETROOTS_GROW_TIME:
block = definitions.BEETROOTS_STAGE_1
elif field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() > 2 * definitions.BEETROOTS_GROW_TIME and field.get_plant().get_state() <= 3 * definitions.BEETROOTS_GROW_TIME:
block = definitions.BEETROOTS_STAGE_2
elif field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() == definitions.BEETROOTS_MAXIMUM_STATE:
block = definitions.BEETROOTS_STAGE_3
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() <= 1 * definitions.CARROTS_GROW_TIME:
block = definitions.CARROTS_STAGE_0
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() > 1 * definitions.CARROTS_GROW_TIME and field.get_plant().get_state() <= 2 * definitions.CARROTS_GROW_TIME:
block = definitions.CARROTS_STAGE_1
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() > 2 * definitions.CARROTS_GROW_TIME and field.get_plant().get_state() <= 3 * definitions.CARROTS_GROW_TIME:
block = definitions.CARROTS_STAGE_2
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() == definitions.CARROTS_MAXIMUM_STATE:
block = definitions.CARROTS_STAGE_3
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() > 0 and field.get_plant().get_state() <= 1 * definitions.POTATOES_GROW_TIME:
block = definitions.POTATOES_STAGE_0
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() > 1 * definitions.POTATOES_GROW_TIME and field.get_plant().get_state() <= 2 * definitions.POTATOES_GROW_TIME:
block = definitions.POTATOES_STAGE_1
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() > 2 * definitions.POTATOES_GROW_TIME and field.get_plant().get_state() <= 3 * definitions.POTATOES_GROW_TIME:
block = definitions.POTATOES_STAGE_2
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() == definitions.POTATOES_MAXIMUM_STATE:
block = definitions.POTATOES_STAGE_3
elif 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.WHEAT_STAGE_0
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.WHEAT_STAGE_1
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.WHEAT_STAGE_2
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.WHEAT_STAGE_3
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 4 * definitions.WHEAT_GROW_TIME and field.get_plant().get_state() <= 5 * definitions.WHEAT_GROW_TIME:
block = definitions.WHEAT_STAGE_4
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 5 * definitions.WHEAT_GROW_TIME and field.get_plant().get_state() <= 6 * definitions.WHEAT_GROW_TIME:
block = definitions.WHEAT_STAGE_5
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 6 * definitions.WHEAT_GROW_TIME and field.get_plant().get_state() <= 7 * definitions.WHEAT_GROW_TIME:
block = definitions.WHEAT_STAGE_6
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() == definitions.WHEAT_MAXIMUM_STATE:
block = definitions.WHEAT_STAGE_7
elif field.get_soil().get_state() is False:
block = definitions.DIRT
elif field.get_soil().get_state() is True and field.get_soil().get_water_level() is False:
block = definitions.FARMLAND_DRY
elif field.get_soil().get_state() is True and field.get_soil().get_water_level() is True:
block = definitions.FARMLAND_WET
if (block != definitions.DIRT or block != definitions.FARMLAND_DRY or block != definitions.FARMLAND_WET):
definitions.WINDOW.blit(definitions.FARMLAND_WET, (rect.x, rect.y))
definitions.WINDOW.blit(block, (rect.x, rect.y))
def do_work(tractor1, tractor1_rect):
loop = True
if tractor1.get_all_amount_of_seeds() == 0:
loop = False
x = int(tractor1_rect.x / definitions.BLOCK_SIZE)
y = int(tractor1_rect.y / definitions.BLOCK_SIZE)
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 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_soil().get_state() is True and field.get_soil().get_water_level() is True and field.get_plant().get_state() == 0:
while loop is True:
random1 = random.randint(1, 4)
if random1 == 1 and tractor1.get_amount_of_seeds("beetroot") > 0:
tractor1.set_amount_of_seeds("beetroot", tractor1.get_amount_of_seeds("beetroot") - 1)
field.get_plant().set_name("beetroot")
field.get_plant().set_state(1)
loop = False
elif random1 == 2 and tractor1.get_amount_of_seeds("carrot") > 0:
tractor1.set_amount_of_seeds("carrot", tractor1.get_amount_of_seeds("carrot") - 1)
field.get_plant().set_name("carrot")
field.get_plant().set_state(1)
loop = False
elif random1 == 3 and tractor1.get_amount_of_seeds("potato") > 0:
tractor1.set_amount_of_seeds("potato", tractor1.get_amount_of_seeds("potato") - 1)
field.get_plant().set_name("potato")
field.get_plant().set_state(1)
loop = False
elif random1 == 4 and tractor1.get_amount_of_seeds("wheat") > 0:
tractor1.set_amount_of_seeds("wheat", tractor1.get_amount_of_seeds("wheat") - 1)
field.get_plant().set_name("wheat")
field.get_plant().set_state(1)
loop = False
elif field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.BEETROOTS_MAXIMUM_STATE - definitions.BEETROOTS_GROW_TIME and tractor1.get_fertilizer("beetroot") > 0 and field.get_soil().get_is_fertilized() is False:
tractor1.set_fertilizer("beetroot", (tractor1.get_fertilizer("beetroot") - 1))
field.get_soil().set_is_fertilized(True)
field.get_plant().set_state(field.get_plant().get_state() + definitions.BEETROOTS_GROW_TIME)
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.CARROTS_MAXIMUM_STATE - definitions.CARROTS_GROW_TIME and tractor1.get_fertilizer("carrot") > 0 and field.get_soil().get_is_fertilized() is False:
tractor1.set_fertilizer("carrot", (tractor1.get_fertilizer("carrot") - 1))
field.get_soil().set_is_fertilized(True)
field.get_plant().set_state(field.get_plant().get_state() + definitions.CARROTS_GROW_TIME)
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.POTATOES_MAXIMUM_STATE - definitions.POTATOES_GROW_TIME and tractor1.get_fertilizer("potato") > 0 and field.get_soil().get_is_fertilized() is False:
tractor1.set_fertilizer("potato", (tractor1.get_fertilizer("potato") - 1))
field.get_soil().set_is_fertilized(True)
field.get_plant().set_state(field.get_plant().get_state() + definitions.POTATOES_GROW_TIME)
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 and field.get_soil().get_is_fertilized() is False:
tractor1.set_fertilizer("wheat", (tractor1.get_fertilizer("wheat") - 1))
field.get_soil().set_is_fertilized(True)
field.get_plant().set_state(field.get_plant().get_state() + definitions.WHEAT_GROW_TIME)
elif field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() == definitions.BEETROOTS_MAXIMUM_STATE and tractor1.get_all_collected_plants() < definitions.TRACTOR_MAXIMUM_COLLECTED_PLANTS:
field.get_plant().set_state(0)
field.get_soil().set_is_fertilized(False)
field.get_soil().set_water_level(False)
field.get_soil().set_state(False)
tractor1.set_collected_plants("beetroot", tractor1.get_collected_plants("beetroot") + 1)
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() == definitions.CARROTS_MAXIMUM_STATE and tractor1.get_all_collected_plants() < definitions.TRACTOR_MAXIMUM_COLLECTED_PLANTS:
field.get_plant().set_state(0)
field.get_soil().set_is_fertilized(False)
field.get_soil().set_water_level(False)
field.get_soil().set_state(False)
tractor1.set_collected_plants("carrot", tractor1.get_collected_plants("carrot") + 1)
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() == definitions.POTATOES_MAXIMUM_STATE and tractor1.get_all_collected_plants() < definitions.TRACTOR_MAXIMUM_COLLECTED_PLANTS:
field.get_plant().set_state(0)
field.get_soil().set_is_fertilized(False)
field.get_soil().set_water_level(False)
field.get_soil().set_state(False)
tractor1.set_collected_plants("potato", tractor1.get_collected_plants("potato") + 1)
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() == definitions.WHEAT_MAXIMUM_STATE and tractor1.get_all_collected_plants() < definitions.TRACTOR_MAXIMUM_COLLECTED_PLANTS:
field.get_plant().set_state(0)
field.get_soil().set_is_fertilized(False)
field.get_soil().set_water_level(False)
field.get_soil().set_state(False)
tractor1.set_collected_plants("wheat", tractor1.get_collected_plants("wheat") + 1)
def draw_window(tractor1_rect):
fill_map()
definitions.WINDOW.blit(definitions.TRACTOR, (tractor1_rect.x, tractor1_rect.y))
pygame.display.update()
def grow_plants():
for i in range(definitions.WIDTH_AMOUNT):
for j in range(definitions.HEIGHT_AMOUNT):
field = fields[i][j]
if field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.BEETROOTS_MAXIMUM_STATE:
field.get_plant().set_state(field.get_plant().get_state() + 1)
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.CARROTS_MAXIMUM_STATE:
field.get_plant().set_state(field.get_plant().get_state() + 1)
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.POTATOES_MAXIMUM_STATE:
field.get_plant().set_state(field.get_plant().get_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:
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:
return True
elif move == 2 and tractor1_rect.x - definitions.BLOCK_SIZE >= 0:
return True
elif move == 3 and tractor1_rect.x + definitions.BLOCK_SIZE + definitions.BLOCK_SIZE <= definitions.WIDTH:
return True
elif move == 4 and tractor1_rect.y - definitions.BLOCK_SIZE >= 0:
return True
else:
return False
def tractor1_handle_movement(tractor1, tractor1_rect):
loop = True
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()
tractor1_rect.x = tractor1.get_x()
tractor1_rect.y = tractor1.get_y()
loop = False
elif random1 == 2 and is_move_allowed(2, tractor1_rect) is True:
tractor1.move_left()
tractor1_rect.x = tractor1.get_x()
tractor1_rect.y = tractor1.get_y()
loop = False
elif random1 == 3 and is_move_allowed(3, tractor1_rect) is True:
tractor1.move_right()
tractor1_rect.x = tractor1.get_x()
tractor1_rect.y = tractor1.get_y()
loop = False
elif random1 == 4 and is_move_allowed(4, tractor1_rect) is True:
tractor1.move_up()
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()
map1 = map.Map([])
map1.create_base_map()
amount_of_seeds_dict = {"beetroot": definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE, "carrot": definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE, "potato": definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE, "wheat": definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE}
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_rect = pygame.Rect(tractor1.get_x(), tractor1.get_y(), definitions.BLOCK_SIZE, definitions.BLOCK_SIZE)
clock = pygame.time.Clock()
@ -215,10 +21,10 @@ def main():
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
draw_window(tractor1_rect)
tractor1_handle_movement(tractor1, tractor1_rect)
do_work(tractor1, tractor1_rect)
grow_plants()
map1.draw_window(tractor1_rect)
tractor1.tractor1_handle_movement(tractor1_rect)
tractor1.do_work(map1, station1, tractor1_rect)
plant.Plant.grow_plants(map1)
pygame.quit()
if __name__ == "__main__":
main()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 351 B

BIN
resources/rail_normal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 B

BIN
resources/sponge.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 837 B

View File

@ -1,4 +1,5 @@
import definitions
import random
class Tractor:
def __init__(self, amount_of_seeds, collected_plants, fertilizer, fuel, water_level, x, y):
self.amount_of_seeds = amount_of_seeds
@ -48,3 +49,136 @@ class Tractor:
self.x = self.x + definitions.BLOCK_SIZE
def move_up(self):
self.y = self.y - definitions.BLOCK_SIZE
def do_work(self, map1, station1, tractor1_rect):
loop = True
if self.get_all_amount_of_seeds() == 0:
loop = False
x = int(tractor1_rect.x / definitions.BLOCK_SIZE)
y = int(tractor1_rect.y / definitions.BLOCK_SIZE)
field = map1.get_fields()[x][y]
if x == 0 and y == 0:
station1.set_collected_plants("beetroot", station1.get_collected_plants("beetroot") + self.get_collected_plants("beetroot"))
self.set_collected_plants("beetroot", 0)
station1.set_collected_plants("carrot", station1.get_collected_plants("carrot") + self.get_collected_plants("carrot"))
self.set_collected_plants("carrot", 0)
station1.set_collected_plants("potato", station1.get_collected_plants("potato") + self.get_collected_plants("potato"))
self.set_collected_plants("potato", 0)
station1.set_collected_plants("wheat", station1.get_collected_plants("wheat") + self.get_collected_plants("wheat"))
self.set_collected_plants("wheat", 0)
self.set_amount_of_seeds("beetroot", definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE)
self.set_amount_of_seeds("carrot", definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE)
self.set_amount_of_seeds("potato", definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE)
self.set_amount_of_seeds("wheat", definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE)
self.set_fertilizer("beetroot", definitions.TRACTOR_FERTILIZER)
self.set_fertilizer("carrot", definitions.TRACTOR_FERTILIZER)
self.set_fertilizer("potato", definitions.TRACTOR_FERTILIZER)
self.set_fertilizer("wheat", definitions.TRACTOR_FERTILIZER)
self.set_fuel(definitions.TRACTOR_FUEL)
self.set_water_level(definitions.TRACTOR_WATER_LEVEL)
elif 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 and self.get_water_level() > 0:
self.set_water_level(self.get_water_level() - 1)
field.get_soil().set_water_level(True)
elif field.get_soil().get_state() is True and field.get_soil().get_water_level() is True and field.get_plant().get_state() == 0:
while loop is True:
random1 = random.randint(1, 4)
if random1 == 1 and self.get_amount_of_seeds("beetroot") > 0:
self.set_amount_of_seeds("beetroot", self.get_amount_of_seeds("beetroot") - 1)
field.get_plant().set_name("beetroot")
field.get_plant().set_state(1)
loop = False
elif random1 == 2 and self.get_amount_of_seeds("carrot") > 0:
self.set_amount_of_seeds("carrot", self.get_amount_of_seeds("carrot") - 1)
field.get_plant().set_name("carrot")
field.get_plant().set_state(1)
loop = False
elif random1 == 3 and self.get_amount_of_seeds("potato") > 0:
self.set_amount_of_seeds("potato", self.get_amount_of_seeds("potato") - 1)
field.get_plant().set_name("potato")
field.get_plant().set_state(1)
loop = False
elif random1 == 4 and self.get_amount_of_seeds("wheat") > 0:
self.set_amount_of_seeds("wheat", self.get_amount_of_seeds("wheat") - 1)
field.get_plant().set_name("wheat")
field.get_plant().set_state(1)
loop = False
elif field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.BEETROOTS_MAXIMUM_STATE - definitions.BEETROOTS_GROW_TIME and self.get_fertilizer("beetroot") > 0 and field.get_soil().get_is_fertilized() is False:
self.set_fertilizer("beetroot", (self.get_fertilizer("beetroot") - 1))
field.get_soil().set_is_fertilized(True)
field.get_plant().set_state(field.get_plant().get_state() + definitions.BEETROOTS_GROW_TIME)
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.CARROTS_MAXIMUM_STATE - definitions.CARROTS_GROW_TIME and self.get_fertilizer("carrot") > 0 and field.get_soil().get_is_fertilized() is False:
self.set_fertilizer("carrot", (self.get_fertilizer("carrot") - 1))
field.get_soil().set_is_fertilized(True)
field.get_plant().set_state(field.get_plant().get_state() + definitions.CARROTS_GROW_TIME)
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.POTATOES_MAXIMUM_STATE - definitions.POTATOES_GROW_TIME and self.get_fertilizer("potato") > 0 and field.get_soil().get_is_fertilized() is False:
self.set_fertilizer("potato", (self.get_fertilizer("potato") - 1))
field.get_soil().set_is_fertilized(True)
field.get_plant().set_state(field.get_plant().get_state() + definitions.POTATOES_GROW_TIME)
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 self.get_fertilizer("wheat") > 0 and field.get_soil().get_is_fertilized() is False:
self.set_fertilizer("wheat", (self.get_fertilizer("wheat") - 1))
field.get_soil().set_is_fertilized(True)
field.get_plant().set_state(field.get_plant().get_state() + definitions.WHEAT_GROW_TIME)
elif field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() == definitions.BEETROOTS_MAXIMUM_STATE and self.get_all_collected_plants() < definitions.TRACTOR_MAXIMUM_COLLECTED_PLANTS:
field.get_plant().set_state(0)
field.get_soil().set_is_fertilized(False)
field.get_soil().set_water_level(False)
field.get_soil().set_state(False)
self.set_collected_plants("beetroot", self.get_collected_plants("beetroot") + 1)
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() == definitions.CARROTS_MAXIMUM_STATE and self.get_all_collected_plants() < definitions.TRACTOR_MAXIMUM_COLLECTED_PLANTS:
field.get_plant().set_state(0)
field.get_soil().set_is_fertilized(False)
field.get_soil().set_water_level(False)
field.get_soil().set_state(False)
self.set_collected_plants("carrot", self.get_collected_plants("carrot") + 1)
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() == definitions.POTATOES_MAXIMUM_STATE and self.get_all_collected_plants() < definitions.TRACTOR_MAXIMUM_COLLECTED_PLANTS:
field.get_plant().set_state(0)
field.get_soil().set_is_fertilized(False)
field.get_soil().set_water_level(False)
field.get_soil().set_state(False)
self.set_collected_plants("potato", self.get_collected_plants("potato") + 1)
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() == definitions.WHEAT_MAXIMUM_STATE and self.get_all_collected_plants() < definitions.TRACTOR_MAXIMUM_COLLECTED_PLANTS:
field.get_plant().set_state(0)
field.get_soil().set_is_fertilized(False)
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):
if move == 1 and tractor1_rect.y + definitions.BLOCK_SIZE + definitions.BLOCK_SIZE <= definitions.HEIGHT:
return True
elif move == 2 and tractor1_rect.x - definitions.BLOCK_SIZE >= 0:
return True
elif move == 3 and tractor1_rect.x + definitions.BLOCK_SIZE + definitions.BLOCK_SIZE <= definitions.WIDTH:
return True
elif move == 4 and tractor1_rect.y - definitions.BLOCK_SIZE >= 0:
return True
else:
return False
def tractor1_handle_movement(self, tractor1_rect):
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()
tractor1_rect.x = self.get_x()
tractor1_rect.y = self.get_y()
loop = False
self.set_fuel(self.get_fuel() - 1)
if tractor1_rect.x == 0 and tractor1_rect.y == 0:
self.set_fuel(definitions.TRACTOR_FUEL)
self.set_water_level(definitions.TRACTOR_WATER_LEVEL)