Sztuczna_Inteligencja-projekt/field.py

48 lines
1.5 KiB
Python
Raw Permalink Normal View History

2021-05-10 14:36:55 +02:00
import pygame
from src.colors import *
from src.dimensions import *
2021-05-10 14:36:55 +02:00
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
2021-06-03 16:07:33 +02:00
self.fertility = 1
self.tractor_there = False
2021-05-10 14:36:55 +02:00
def hydrate(self):
2021-06-03 16:07:33 +02:00
if self.field_type == "soil" and self.hydration <= 5:
2021-05-10 14:36:55 +02:00
self.hydration += 1
# color field to it's hydration value
self.surf.fill(eval('BROWN' + str(self.hydration)))
2021-05-10 14:36:55 +02:00
def dehydrate(self):
if self.field_type == "soil" and self.hydration > 0:
self.hydration -= 1
# color field to it's hydration value
self.surf.fill(eval('BROWN' + str(self.hydration)))
2021-05-10 14:36:55 +02:00
def free(self):
self.planted = 0