From 1b88dd6cb93f1e5eadaa9d2a940c00cc46283e65 Mon Sep 17 00:00:00 2001 From: Cezary Adamczak Date: Thu, 3 Jun 2021 16:12:40 +0200 Subject: [PATCH] Zaktualizuj 'plant.py' --- plant.py | 125 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 112 insertions(+), 13 deletions(-) diff --git a/plant.py b/plant.py index b35907c..0e24e0d 100644 --- a/plant.py +++ b/plant.py @@ -34,23 +34,122 @@ class Plant(pygame.sprite.Sprite): self.rect = self.surf.get_rect( topleft=((MARGIN + WIDTH) * self.position[0] + MARGIN, (MARGIN + HEIGHT) * self.position[1] + MARGIN)) self.growth = 0 - self.isHealthy = True + self.is_healthy = True field.planted = True + self.tickscount = 0 + self.ticks = 0 + + def dtree(self): + if self.field.hydration == 4: + if self.is_healthy == 1: + if self.field.tractor_there == 0: + if self.ticks == 0: + return 0 + elif self.ticks == 1: + return 1 + elif self.field.tractor_there == 1: + return 0 + elif self.is_healthy == 0: + return 0 + elif self.field.hydration == 2: + if self.species == "sorrel": + if self.ticks == 1: + if self.is_healthy == 1: + return 1 + elif self.is_healthy == 0: + return 0 + elif self.ticks == 0: + return 0 + elif self.species == "potato": + return 0 + elif self.species == "wheat": + return 0 + elif self.species == "strawberry": + return 0 + elif self.field.hydration == 1: + if self.species == "potato": + return 0 + elif self.species == "strawberry": + if self.ticks == 1: + return -1 + elif self.ticks == 0: + return 0 + elif self.species == "wheat": + return 0 + elif self.species == "sorrel": + if self.is_healthy == 0: + return 0 + elif self.is_healthy == 1: + if self.field.tractor_there == 0: + if self.ticks == 0: + return 0 + elif self.ticks == 1: + return 1 + elif self.field.tractor_there == 1: + return 0 + elif self.field.hydration == 3: + if self.ticks == 1: + if self.field.tractor_there == 0: + if self.is_healthy == 1: + if self.species == "potato": + if self.field.fertility == 1: + return 1 + elif self.field.fertility == 0: + return 0 + elif self.species == "strawberry": + return 1 + elif self.species == "sorrel": + return 1 + elif self.species == "wheat": + return 1 + elif self.is_healthy == 0: + return 0 + elif self.field.tractor_there == 1: + return 0 + elif self.ticks == 0: + return 0 + elif self.field.hydration == 5: + if self.field.tractor_there == 1: + return 0 + elif self.field.tractor_there == 0: + if self.is_healthy == 0: + return 0 + elif self.is_healthy == 1: + if self.ticks == 1: + return 1 + elif self.ticks == 0: + return 0 + elif self.field.hydration == 0: + if self.ticks == 0: + return 0 + elif self.ticks == 1: + return -1 + + def update(self): + if self.growth == 0: + self.surf = self.img0 + if self.growth == 1: + self.surf = self.img1 + if self.growth == 2: + self.surf = self.img2 + if self.growth == 3: + self.surf = self.img3 def grow(self): - if self.field.hydration >= self.humidity_needed: - self.growth += self.growth_speed - if self.field.hydration == 0: - self.growth -= self.growth_speed + if self.dtree() == 1: + self.growth += 1 + self.ticks = 0 + elif self.dtree() == -1: + self.growth -= 1 + self.ticks = 0 if self.growth > 4: self.growth = 4 if self.growth < 0: self.growth = 0 - if self.growth == 0: - self.surf = self.img0 - elif self.growth < 1: - self.surf = self.img1 - elif self.growth < 2: - self.surf = self.img2 - elif self.growth <= 3: - self.surf = self.img3 + self.update() + + def tick(self): + self.tickscount += 1 + if self.tickscount >= 25: + self.tickscount = 0 + self.ticks = 1