From ac32a5e0b78bc940db01405163e1a16963f7c68e Mon Sep 17 00:00:00 2001 From: Emil Gutkiewicz Date: Fri, 25 Mar 2022 06:52:06 +0100 Subject: [PATCH] added plants --- __pycache__/agent.cpython-38.pyc | Bin 1535 -> 1861 bytes __pycache__/common.cpython-38.pyc | Bin 704 -> 704 bytes __pycache__/field.cpython-38.pyc | Bin 3459 -> 4234 bytes __pycache__/settings.cpython-38.pyc | Bin 1700 -> 1700 bytes field.py | 35 +++++++-- main.py | 1 + plant.py | 108 ++++++++++++++++++++++++++++ 7 files changed, 137 insertions(+), 7 deletions(-) create mode 100644 plant.py diff --git a/__pycache__/agent.cpython-38.pyc b/__pycache__/agent.cpython-38.pyc index 22b0b5206e5661e9f7fb66cdf89a36e13c53393a..7fecea2bba6af01dd082642a310d3faf2db739d7 100644 GIT binary patch delta 881 zcma)4%We}f6t(BoNhULG3N0-aWl=?9D$yNu1C>yVph^@XN`#cnC>^`)r0Jxx9i*0^ zEZ_&K`2o6Q!-gGue!@Rf?lmtZ?E;T{Y>)4`zCOoS!H+0vhhdpOd;j?9{=Rz=F}iah zAB|b%6Y2OYWD$%dHoHgSIqmP}Qg!o`rxsFvHycI|`ZjdA0iZ~a_N)(f?!q^$>YxJg9?1`+;+2xdA+2Lr*fysNmZ6wB7p!zuH= zx#A5)=;|R?$%HIRz>vlddVcqhK^xb?CM>hYKthf=9{o3d5cI>8Anw4w*fI)s$_GQ< zPlkD>o>$}|H;XK4f}ixJ(l<~fMov! Dz)P!2 delta 558 zcma))%}N6?5XUpy{c5+ZZLJk5h$2E)@uXfwsYOdgiysK}uxdAAYi%W21f?SA*@Mjs z=+UG24C2Wb$jfME6~&%Rm|rH$KmXm#?rZYHN$w;PF`~xX^VH#uexLMV?w-%@ZxJ^x z?Q)w32kkno14_P!rdCr$Q3Wq31f&T~?Fxd(gYJV5UAQF}k9wDQhOa4_K2eU5b%sWg zxRw}&*|e)kozvD4L%S!!;^G|EqPQVoLr%OywJ?AsV2)Z?{09k@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l8{ z`<$_B(pqKB^G|VN*5q2;?eFwDFPNS?T6dg}{ckZs-dU$_LI}h&P>a1yR^}*fc?{3}4t(>sHS%yr_ zVdAqJt<6C%X(hchYi+B+RuUI^D=&6r8nssUcGu%{pjLa4D%Mo=s2Hf$Mw(=DX?s^! zyGaq|g-ZKfS}9+IVzyuwKbF5OVg0qYKsR5S%Lp>Qt6|t1$eoPZwJ`j7 zC(6nZg_vT>Csl#cwY-RmH0~wE=0K`>>Ze_&RE6Dr=2{GGEDjz)9u-B=}2kzAx}5(LI;)+N3-U&2``M?1}`s$)zo zkZO>6ht%7o-Xul1N>`tw)+JJB`IUl;X5c^mf%04J(&-vQ?+Su%pwW&6RT5KW4k$M5LXa&{W$t&VoX zb#g`1HBOySL-j!1C_1!u%#v;J z;G;`_1~GNTM^FpPfQZpI^U$jF%+&7$HMV5=gl%xc(+|8S$kV{5YO2MZR25oC=$Xnr zqDrfpms!CIFg>sits_Q1TSlQ~qj>J%ZLU7WOl7XoLTku%B@E*Xl{yT|=o<67No$hp z8S<0%AHzb8IExjPIb}-Xn3bMCUOi5-Y_x;%%@;J;>_sQ~8ZwQJ`d$$_cX_bBj<<#z zo6rA=Pf?z$uSkvIDRYNOF44dWWCU%Y-1*!5~Dn%UB{RdrOlaPLaY8r-Z5?MA&`Yxs>yy#kHD Fe*nZ^PV)c& diff --git a/__pycache__/settings.cpython-38.pyc b/__pycache__/settings.cpython-38.pyc index 9c65d0bde49fffdcdb310f211d5a626cbbbb1273..63ef74460fe88d6a9aa559ef77ff23185db58d3c 100644 GIT binary patch delta 20 acmZ3&yM&iJl$V!_0SNY(+HT~Y$p!!|as+Sy delta 20 acmZ3&yM&iJl$V!_0SF|vYHj46$p!!`mjpQg 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] + + + + +