diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 7663586..f0adf19 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,7 +4,10 @@
+
+
+
@@ -96,6 +99,8 @@
+
+
@@ -103,22 +108,22 @@
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
@@ -135,12 +140,12 @@
-
+
-
+
-
+
\ No newline at end of file
diff --git a/__pycache__/definitions.cpython-37.pyc b/__pycache__/definitions.cpython-37.pyc
index 95a1261..3a029ae 100644
Binary files a/__pycache__/definitions.cpython-37.pyc and b/__pycache__/definitions.cpython-37.pyc differ
diff --git a/__pycache__/map.cpython-37.pyc b/__pycache__/map.cpython-37.pyc
new file mode 100644
index 0000000..c77bf29
Binary files /dev/null and b/__pycache__/map.cpython-37.pyc differ
diff --git a/__pycache__/plant.cpython-37.pyc b/__pycache__/plant.cpython-37.pyc
index e07bf5e..66788e1 100644
Binary files a/__pycache__/plant.cpython-37.pyc and b/__pycache__/plant.cpython-37.pyc differ
diff --git a/__pycache__/station.cpython-37.pyc b/__pycache__/station.cpython-37.pyc
new file mode 100644
index 0000000..7a18d03
Binary files /dev/null and b/__pycache__/station.cpython-37.pyc differ
diff --git a/__pycache__/tractor.cpython-37.pyc b/__pycache__/tractor.cpython-37.pyc
index 87fb753..8563cb4 100644
Binary files a/__pycache__/tractor.cpython-37.pyc and b/__pycache__/tractor.cpython-37.pyc differ
diff --git a/definitions.py b/definitions.py
index dc707e2..0a65f1e 100644
--- a/definitions.py
+++ b/definitions.py
@@ -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
@@ -65,4 +68,5 @@ WHEAT_STAGE_5 = pygame.transform.scale(WHEAT_STAGE_5, (BLOCK_SIZE, BLOCK_SIZE))
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))
\ No newline at end of file
+WHEAT_STAGE_7 = pygame.transform.scale(WHEAT_STAGE_7, (BLOCK_SIZE, BLOCK_SIZE))
+WINDOW = pygame.display.set_mode((WIDTH, HEIGHT))
\ No newline at end of file
diff --git a/map.py b/map.py
new file mode 100644
index 0000000..7e51071
--- /dev/null
+++ b/map.py
@@ -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()
\ No newline at end of file
diff --git a/plant.py b/plant.py
index 3f3f3b0..286ffdd 100644
--- a/plant.py
+++ b/plant.py
@@ -1,3 +1,4 @@
+import definitions
class Plant:
def __init__(self, name, state):
self.name = name
@@ -9,4 +10,17 @@ class Plant:
def get_state(self):
return self.state
def set_state(self, state):
- self.state = state
\ No newline at end of file
+ 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)
\ No newline at end of file
diff --git a/py.py b/py.py
index f20cbc3..07e23a6 100644
--- a/py.py
+++ b/py.py
@@ -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()
\ No newline at end of file
diff --git a/resources/rail_detector_powered.png b/resources/rail_detector_powered.png
deleted file mode 100644
index fa0a71d..0000000
Binary files a/resources/rail_detector_powered.png and /dev/null differ
diff --git a/resources/rail_normal.png b/resources/rail_normal.png
new file mode 100644
index 0000000..d609236
Binary files /dev/null and b/resources/rail_normal.png differ
diff --git a/resources/sponge.png b/resources/sponge.png
new file mode 100644
index 0000000..487ac43
Binary files /dev/null and b/resources/sponge.png differ
diff --git a/tractor.py b/tractor.py
index 7c32974..36e8e24 100644
--- a/tractor.py
+++ b/tractor.py
@@ -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
@@ -47,4 +48,137 @@ class Tractor:
def move_right(self):
self.x = self.x + definitions.BLOCK_SIZE
def move_up(self):
- self.y = self.y - definitions.BLOCK_SIZE
\ No newline at end of file
+ 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)
\ No newline at end of file