From bc02986bb3f916a2b04a946fb54c2728f74246c9 Mon Sep 17 00:00:00 2001 From: Cezary Adamczak Date: Mon, 10 May 2021 14:36:55 +0200 Subject: [PATCH] Zaktualizuj 'field.py' --- field.py | 101 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 58 insertions(+), 43 deletions(-) diff --git a/field.py b/field.py index 977a16b..6f2f865 100644 --- a/field.py +++ b/field.py @@ -1,43 +1,58 @@ -import pygame -from colors import * -from dimensions import * - -class Field(pygame.sprite.Sprite): - def __init__(self, row, column): - super(Field, self).__init__() - self.surf = pygame.Surface((WIDTH, HEIGHT)) - self.surf.fill(BROWN) - self.rect = self.surf.get_rect( - topleft=((MARGIN + WIDTH) * row + MARGIN, (MARGIN + HEIGHT) * column + MARGIN)) - self.position = [row, column] - self.hydration = 0 - self.isRocky = False - self.planted = 0 - self.ferility = 1 - - def hydrate(self): - if self.hydration <= 3: - self.hydration += 1 - if self.hydration == 0: - self.surf.fill(BROWN) - if self.hydration == 1: - self.surf.fill(YELLOW) - if self.hydration == 2: - self.surf.fill(GREEN) - if self.hydration == 3: - self.surf.fill(BLUE) - - def dehydrate(self): - if self.hydration > 0: - self.hydration -= 1 - if self.hydration == 0: - self.surf.fill(BROWN) - if self.hydration == 1: - self.surf.fill(YELLOW) - if self.hydration == 2: - self.surf.fill(GREEN) - if self.hydration == 3: - self.surf.fill(BLUE) - - def free(self): - self.planted = 0 +import pygame +from colors import * +from dimensions import * + +class Field(pygame.sprite.Sprite): + def __init__(self, row, column, field_type): + super(Field, self).__init__() + self.surf = pygame.Surface((WIDTH, HEIGHT)) + self.field_type = field_type + if self.field_type == "soil": + self.moveCost = 3 + self.surf.fill(BROWN0) + elif self.field_type == "rocks": + self.moveCost = 5 + self.surf.fill(LBROWN) + elif self.field_type == "road": + self.moveCost = 1 + self.surf.fill(GREY) + elif self.field_type == "pond": + self.moveCost = 1000 + self.surf.fill(BLUE) + self.rect = self.surf.get_rect( + topleft=((MARGIN + WIDTH) * row + MARGIN, (MARGIN + HEIGHT) * column + MARGIN)) + self.position = [row, column] + self.hydration = 0 + self.planted = 0 + self.ferility = 1 + + def hydrate(self): + if self.field_type == "soil" and self.hydration <= 4: + self.hydration += 1 + if self.hydration == 0: + self.surf.fill(BROWN0) + if self.hydration == 1: + self.surf.fill(BROWN1) + if self.hydration == 2: + self.surf.fill(BROWN2) + if self.hydration == 3: + self.surf.fill(BROWN3) + if self.hydration == 4: + self.surf.fill(BROWN4) + + def dehydrate(self): + if self.field_type == "soil" and self.hydration > 0: + self.hydration -= 1 + if self.hydration == 0: + self.surf.fill(BROWN0) + if self.hydration == 1: + self.surf.fill(BROWN1) + if self.hydration == 2: + self.surf.fill(BROWN2) + if self.hydration == 3: + self.surf.fill(BROWN3) + if self.hydration == 4: + self.surf.fill(BROWN4) + + def free(self): + self.planted = 0