Zaktualizuj 'field.py'

This commit is contained in:
Cezary Adamczak 2021-06-21 14:14:00 +02:00
parent e9c11d37d2
commit 4f5cf361ce

View File

@ -1,9 +1,7 @@
import pygame import pygame
from src.colors import * from src.colors import *
from src.dimensions import * from src.dimensions import *
class Field(pygame.sprite.Sprite): class Field(pygame.sprite.Sprite):
def __init__(self, row, column, field_type): def __init__(self, row, column, field_type):
super(Field, self).__init__() super(Field, self).__init__()
@ -26,22 +24,62 @@ class Field(pygame.sprite.Sprite):
self.position = [row, column] self.position = [row, column]
self.hydration = 0 self.hydration = 0
self.planted = 0 self.planted = 0
self.fertility = 1 self.fertility = 0
self.tractor_there = False self.tractor_there = False
def hydrate(self): def hydrate(self):
if self.field_type == "soil" and self.hydration <= 5: if self.field_type == "soil" and self.hydration <= 5:
self.hydration += 1 self.hydration += 1
if self.fertility == 1:
# color field to it's hydration value if self.hydration == 0:
self.surf.fill(eval('BROWN' + str(self.hydration))) self.surf.fill(REDDISH0)
self.fertility = 0
if self.hydration == 1:
self.surf.fill(REDDISH1)
if self.hydration == 2:
self.surf.fill(REDDISH2)
if self.hydration == 3:
self.surf.fill(REDDISH3)
if self.hydration == 4 or self.hydration == 5:
self.surf.fill(REDDISH4)
else:
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 or self.hydration == 5:
self.surf.fill(BROWN4)
def dehydrate(self): def dehydrate(self):
if self.field_type == "soil" and self.hydration > 0: if self.field_type == "soil" and self.hydration > 0:
self.hydration -= 1 self.hydration -= 1
if self.fertility == 1:
# color field to it's hydration value if self.hydration == 0:
self.surf.fill(eval('BROWN' + str(self.hydration))) self.surf.fill(REDDISH0)
self.fertility = 0
if self.hydration == 1:
self.surf.fill(REDDISH1)
if self.hydration == 2:
self.surf.fill(REDDISH2)
if self.hydration == 3:
self.surf.fill(REDDISH3)
if self.hydration == 4 or self.hydration == 5:
self.surf.fill(REDDISH4)
else:
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 or self.hydration == 5:
self.surf.fill(BROWN4)
def free(self): def free(self):
self.planted = 0 self.planted = 0