forked from s444426/AIProjekt
54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
from datetime import datetime
|
|
|
|
|
|
class Soil:
|
|
|
|
def __init__(self, pH, dry):
|
|
super().__init__()
|
|
self._plant = -1 # nowa gleba nie ma roślinki
|
|
self._dry = dry # procent wysuszenia gleby, tworząc nową jest nawodniona w 100%
|
|
self._pH = pH
|
|
|
|
def __str__(self):
|
|
if self.have_plant():
|
|
return f'pH={self._pH}, dry level={self._dry}, plant={self.get_plant().get_name()}'
|
|
else:
|
|
return f'soil: pH={self._pH}, dry level={self._dry}, plant=none'
|
|
|
|
# zasadzenie roślinki
|
|
def add_plant(self, plant):
|
|
if not self.have_plant():
|
|
plant.add_soil(self)
|
|
self._plant = plant
|
|
|
|
# zwraca czy w ziemi znajduje się roślinka
|
|
def have_plant(self):
|
|
return self._plant != -1
|
|
|
|
# zwraca roślinkę znajdującą się w ziemii
|
|
def get_plant(self):
|
|
return self._plant
|
|
|
|
def get_pH(self):
|
|
return self._pH
|
|
|
|
def get_dry_level(self):
|
|
return self._dry
|
|
|
|
# sprawdza w ilu procentach ziemia jest sucha
|
|
def is_dry(self):
|
|
self.__drying()
|
|
if self._dry < 30:
|
|
return 'False'
|
|
elif 30 <= self._dry < 70:
|
|
return 'Medium'
|
|
else:
|
|
return 'True'
|
|
|
|
# usuwa roślinkę z ziemi i ją zwraca
|
|
def plant_remove(self):
|
|
if self.have_plant():
|
|
a = self.get_plant()
|
|
a.leave_soil()
|
|
self._plant = -1
|
|
return a |