traktor/Tomato.py

56 lines
1.6 KiB
Python
Raw Normal View History

2019-04-29 03:49:45 +02:00
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:
2019-04-29 10:49:03 +02:00
self.__is_alive == False
2019-04-29 03:49:45 +02:00
def increase_hydration(self, n):
self.__hydration += n
if self.__hydration > 40:
2019-04-29 10:49:03 +02:00
self.__is_alive = False
2019-04-29 03:49:45 +02:00
def decrase_hydration(self, n):
self.__hydration -= n * self.__dehydration_ratio
if self.__hydration < 1:
2019-04-29 10:49:03 +02:00
self.__is_alive = False
2019-04-29 03:49:45 +02:00
def increase_soillevel(self, n):
self.__soil_level += n
if self.__soil_level > 40:
2019-04-29 10:49:03 +02:00
self.__is_alive = False
2019-04-29 03:49:45 +02:00
def decrease_soillevel(self, n):
self.__soil_level -= n * self.__desoil_ratio
if self.__soil_level < 1:
2019-04-29 10:49:03 +02:00
self.__is_alive = False