diff --git a/__pycache__/agent.cpython-38.pyc b/__pycache__/agent.cpython-38.pyc index 22b0b52..7fecea2 100644 Binary files a/__pycache__/agent.cpython-38.pyc and b/__pycache__/agent.cpython-38.pyc differ diff --git a/__pycache__/common.cpython-38.pyc b/__pycache__/common.cpython-38.pyc index acf04c8..3523410 100644 Binary files a/__pycache__/common.cpython-38.pyc and b/__pycache__/common.cpython-38.pyc differ diff --git a/__pycache__/field.cpython-38.pyc b/__pycache__/field.cpython-38.pyc index ce5e88c..fd34ce3 100644 Binary files a/__pycache__/field.cpython-38.pyc and b/__pycache__/field.cpython-38.pyc differ diff --git a/__pycache__/settings.cpython-38.pyc b/__pycache__/settings.cpython-38.pyc index 9c65d0b..63ef744 100644 Binary files a/__pycache__/settings.cpython-38.pyc and b/__pycache__/settings.cpython-38.pyc differ diff --git a/field.py b/field.py index 484505b..93333d8 100644 --- a/field.py +++ b/field.py @@ -1,6 +1,7 @@ from enum import Enum import pygame import settings +import plant class Type(Enum): @@ -17,6 +18,20 @@ class Type(Enum): }[_type] +# Field Types START +class FieldType: + def __init__(self): + self.field = None + self.plowed = False + + def plow(self): + self.plowed = True + + def sow(self, seed: plant.Seeds): + if self.plowed: + self.field = plant.Seeds.seed_to_plant(seed) + + class Object: height = width = 0 name = 'default' @@ -29,7 +44,7 @@ class Object: return pygame.transform.scale(img, (self.width, self.height)) -class Tile(Object) : +class Tile(Object): def __init__(self, name: str, _type: Type): self.name = name self.type = _type @@ -37,7 +52,7 @@ class Tile(Object) : self.object = self.create() -class Block(Object) : +class Block(Object): def __init__(self, name: str, _type: Type): self.name = name self.type = _type @@ -49,28 +64,33 @@ class Block(Object) : class Field: type = Type.DEFAULT name = 'default' - + def __init__(self): self.tile = Tile(self.name, self.type) self.block = Block(self.name + "_block", self.type) + self.field_type = FieldType() + + def can_be_sown(self): + return self.type == Type.DEFAULT +# Tile Types START class Dirt(Field): type = Type.PLANT name = 'dirt' def __init__(self): super(Dirt, self).__init__() - - + + class Cobble(Field): type = Type.SPECIAL name = 'cobble' def __init__(self): super(Cobble, self).__init__() - - + + class Grass(Field): type = Type.DEFAULT name = 'grass' @@ -85,3 +105,4 @@ class Sand(Field): def __init__(self): super(Sand, self).__init__() +# Tile Types END \ No newline at end of file diff --git a/main.py b/main.py index a850cc3..d13a5cd 100644 --- a/main.py +++ b/main.py @@ -44,6 +44,7 @@ def read_img(agent, fields): window.blit(possibleFields['sand'].block.object, (0, 0)) elif current_field == possibleFields['cobble'].tile.object: window.blit(possibleFields['cobble'].block.object, (0, 0)) + pygame.display.update() pygame.time.delay(2000) common.set('state_imgShown', False) diff --git a/plant.py b/plant.py new file mode 100644 index 0000000..cee4e2d --- /dev/null +++ b/plant.py @@ -0,0 +1,108 @@ +from enum import Enum + + +class PlantGrowthStages(Enum): + PLANTED = 0 + GROWING = 1 + UNRIPE = 2 + RIPE = 3 + + @staticmethod + def can_be_harvested(_type): + return _type == PlantGrowthStages.RIPE + + @staticmethod + def next_growth_type(_type): + return { + PlantGrowthStages.PLANTED: PlantGrowthStages.GROWING, + PlantGrowthStages.GROWING: PlantGrowthStages.UNRIPE, + PlantGrowthStages.UNRIPE: PlantGrowthStages.RIPE, + PlantGrowthStages.RIPE: PlantGrowthStages.RIPE, + }[_type] + + +class Plant: + tick_decrease_amount: 1 + tick_increase_amount: 1 + + def __init__(self): + self.growth = PlantGrowthStages.PLANTED + self.canBeHarvested = False + self.water_level = 0 + self.fertilizer_level = 0 + self.growth_stage_level = 0 + self.growth_stage_threshold = 10000 + + def grow(self): + self.growth_stage_level = 0 + previous_growth = self.growth + self.growth = PlantGrowthStages.next_growth_type(self.growth) + if self.growth == previous_growth: + self.canBeHarvested = True + + def is_watered(self): + return self.water_level > 0 + + def water(self): + self.water_level = 100 + + def is_fertilized(self): + return self.fertilizer_level > 0 + + def fertilize(self): + self.fertilizer_level = 1000 + + def tick(self): + self.water_level -= self.tick_decrease_amount + self.fertilizer_level -= self.tick_decrease_amount + self.growth_stage_level += self.tick_increase_amount + if self.growth_stage_threshold == self.growth_stage_level: + self.grow() + + def harvest(self): + if PlantGrowthStages.can_be_harvested(self.growth): + return self + + @staticmethod + def sow(seed): + return { + PlantGrowthStages.PLANTED: PlantGrowthStages.GROWING, + PlantGrowthStages.GROWING: PlantGrowthStages.UNRIPE, + PlantGrowthStages.UNRIPE: PlantGrowthStages.RIPE, + PlantGrowthStages.RIPE: PlantGrowthStages.RIPE, + }[seed] + + +class Carrot(Plant): + def __init__(self): + super(Carrot, self).__init__() + self.growth_stage_threshold = 5000 + + +class Potato(Plant): + def __init__(self): + super(Potato, self).__init__() + + +class Wheat(Plant): + def __init__(self): + super(Wheat, self).__init__() + + +class Seeds(Enum): + Carrot = 0 + Potato = 1 + Wheat = 2 + + @staticmethod + def seed_to_plant(seed): + return { + Seeds.Carrot: Carrot(), + Seeds.Potato: Potato(), + Seeds.Wheat: Wheat(), + }[seed] + + + + +