From 6e3e042a93492a2d3fac6ca2c90c3ae1f46c1a72 Mon Sep 17 00:00:00 2001 From: JakubStac Date: Sat, 23 Mar 2024 22:54:51 +0100 Subject: [PATCH] Added some crop protection products to tractor and finished some of its functions --- source/area/tractor.py | 48 +++++++++++++++++++++++++------ source/crop_protection_product.py | 3 +- source/tile.py | 5 ++-- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/source/area/tractor.py b/source/area/tractor.py index 71b0380..cc76559 100644 --- a/source/area/tractor.py +++ b/source/area/tractor.py @@ -1,24 +1,56 @@ +from crop_protection_product import CropProtectionProduct + + class Tractor: x = None y = None image = None - + cypermetryna = CropProtectionProduct("pests", "cereal") + diflufenikan = CropProtectionProduct("weeds", "cereal") + spirotetramat = CropProtectionProduct("pests", "fruit") + oksadiargyl = CropProtectionProduct("weeds", "fruit") + spinosad = CropProtectionProduct("pests", "vegetable") + metazachlor = CropProtectionProduct("weeds", "vegetable") # etc + def __init__(self, x, y): self.x = x self.y = y self.image = 'resources/images/tractor.png' - def work_on_field(self, ground, plant): - if plant is None: - pass # zasadz cos - if ground.pest == True: + def work_on_field(self, tile, ground, plant1): + if plant1 is None: + tile.randomizeContent() + # sprobuj zasadzic cos + elif plant1.growth_level == 100: + tile.plant = None + ground.nutrients -= 40 + ground.water -= 40 + else: + plant1.try_to_grow() + ground.nutrients -= 11 + ground.water -= 11 + if ground.pest: # traktor pozbywa sie szkodnikow + if plant1.plant_type == self.cypermetryna.plant_type: + t = "Tractor used Cypermetryna" + elif plant1.plant_type == self.spirotetramat.plant_type: + t = "Tractor used Spirotetramat" + elif plant1.plant_type == self.spinosad.plant_type: + t = "Tractor used Spinosad" + print(t) ground.pest = False - if ground.weed == True: + if ground.weed: # traktor pozbywa siÄ™ chwastow + if plant1.plant_type == self.diflufenikan.plant_type: + t = "Tractor used Diflufenikan" + elif plant1.plant_type == self.oksadiargyl.plant_type: + t = "Tractor used Oksadiargyl" + elif plant1.plant_type == self.metazachlor.plant_type: + t = "Tractor used Metazachlor" + print(t) ground.weed = False - if ground.water < plant.water_requirements: + if ground.water < plant1.water_requirements: ground.water += 20 - if ground.nutrients < plant.nutrients_requirements: + if ground.nutrients < plant1.nutrients_requirements: ground.nutrients += 20 diff --git a/source/crop_protection_product.py b/source/crop_protection_product.py index 941d36e..448591b 100644 --- a/source/crop_protection_product.py +++ b/source/crop_protection_product.py @@ -1,3 +1,4 @@ class CropProtectionProduct: - def __init__(self, strong_against): + def __init__(self, strong_against, plant_type): self.strong_against = strong_against # pestycyd, herbicyd + self.plant_type = plant_type diff --git a/source/tile.py b/source/tile.py index fb813ea..aa2ca51 100644 --- a/source/tile.py +++ b/source/tile.py @@ -35,7 +35,7 @@ class Tile: def randomizeContent(self): photo_path = self.randomize_photo() - i = random.randint(1, 3) #szansa 1/3 + i = random.randint(1, 3) # szansa 1/3 if i == 1: self.image = "resources/images/sampling.png" self.photo = photo_path @@ -44,5 +44,4 @@ class Tile: self.image = "resources/images/dirt.png" self.photo = "resources/images/background.jpg" -# DISCLAMER check column and choose plant type ("potato","wheat" etc) - +# DISCLAMER check column and choose plant type ("potato","wheat" etc.)