2020-04-07 19:15:42 +02:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
class Soil:
|
|
|
|
|
|
|
|
def __init__(self, x, y, ID):
|
|
|
|
super().__init__()
|
|
|
|
self._id = ID
|
|
|
|
self._x = x
|
|
|
|
self._y = y
|
|
|
|
self._plant = -1 #nowa gleba nie ma roślinki
|
|
|
|
self._dry = 0 #procent wysuszenia gleby, tworząc nową jest nawodniona w 100%
|
|
|
|
self._starttime = datetime.now()
|
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
self.plant_remove()
|
|
|
|
|
|
|
|
def __str__(self):
|
2020-04-07 20:28:04 +02:00
|
|
|
return f'{self._x}, {self._y}), Plant: {self._plant}'
|
2020-04-07 19:15:42 +02:00
|
|
|
|
|
|
|
# współrzędne pola
|
|
|
|
def get_coordinates(self):
|
|
|
|
return self._x, self._y
|
|
|
|
|
|
|
|
# id gleby
|
|
|
|
def get_id(self):
|
|
|
|
return self._id
|
|
|
|
|
|
|
|
# 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 is not -1
|
|
|
|
|
|
|
|
# zwraca roślinkę znajdującą się w ziemii
|
|
|
|
def get_plant(self):
|
|
|
|
return self._soil
|
|
|
|
|
|
|
|
#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'
|
|
|
|
|
|
|
|
#metoda wysuszajaca ziemie. dodaje wysuszenie do ziemi, wywolywana w momencie sprawdzania czy ziemia jest sucha
|
|
|
|
def __drying(self):
|
|
|
|
checktime = datetime.now()
|
|
|
|
delta = checktime - self._starttime
|
|
|
|
a = delta //60
|
|
|
|
self._dry += a
|
|
|
|
self._starttime = checktime
|
|
|
|
self.__is_dry()
|
|
|
|
|
|
|
|
|
|
|
|
# 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
|