traktor/Tomato.py
marcinljablonski b7198cb910 .
2019-04-29 03:49:45 +02:00

56 lines
1.6 KiB
Python

from Plant import Plant
class Tomato(Plant):
def __init__(self):
self.__is_alive = True
self.__ttl = 38
self.__hydration = 41
self.__soil_level = 41
self.__dehydration_ratio = 0.7
self.__desoil_ratio = 0.8
self.__max_soil_lvl = 40
self.__max_hydration_lvl = 40
self.__ready = 10
def get_symbol(self):
if not self.__is_alive:
return ('x', None)
elif self.__hydration > (self.__max_hydration_lvl / 2) \
and self.__soil_level > (self.__max_soil_lvl / 2):
return ('p', "green") if (self.__ttl > self.__ready) \
else ('P', "green")
else:
return ('p', "yellow") if (self.__ttl > self.__ready) \
else ('P', "yellow")
def tick(self, n):
self.decrease_ttl(n)
self.decrase_hydration(n)
self.decrease_soillevel(n)
def decrease_ttl(self, n):
self.__ttl -= n
if self.__ttl == 0:
self.__is_life == False
def increase_hydration(self, n):
self.__hydration += n
if self.__hydration > 40:
self.__is_life = False
def decrase_hydration(self, n):
self.__hydration -= n * self.__dehydration_ratio
if self.__hydration < 1:
self.__is_life = False
def increase_soillevel(self, n):
self.__soil_level += n
if self.__soil_level > 40:
self.__is_life = False
def decrease_soillevel(self, n):
self.__soil_level -= n * self.__desoil_ratio
if self.__soil_level < 1:
self.__is_life = False