klasa ziemi (zmienione)
This commit is contained in:
parent
7930f1fab7
commit
f35adaea6b
@ -1,78 +1,78 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
class Soil:
|
class Soil:
|
||||||
|
|
||||||
def __init__(self, pH, dry):
|
def __init__(self, pH, dry):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
#self._id = ID
|
#self._id = ID
|
||||||
#self._x = x
|
#self._x = x
|
||||||
#self._y = y
|
#self._y = y
|
||||||
self._plant = -1 #nowa gleba nie ma roślinki
|
self._plant = -1 #nowa gleba nie ma roślinki
|
||||||
self._dry = dry #procent wysuszenia gleby, tworząc nową jest nawodniona w 100%
|
self._dry = dry #procent wysuszenia gleby, tworząc nową jest nawodniona w 100%
|
||||||
self._pH = pH
|
self._pH = pH
|
||||||
self._starttime = datetime.now()
|
self._starttime = datetime.now()
|
||||||
|
|
||||||
# def __del__(self):
|
# def __del__(self):
|
||||||
# self.plant_remove()
|
# self.plant_remove()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.have_plant():
|
if self.have_plant():
|
||||||
return f'pH={self._pH}, dry level={self._dry}, plant={self.get_plant().get_name()}'
|
return f'pH={self._pH}, dry level={self._dry}, plant={self.get_plant().get_name()}'
|
||||||
else:
|
else:
|
||||||
return f'soil: pH={self._pH}, dry level={self._dry}, plant=none'
|
return f'soil: pH={self._pH}, dry level={self._dry}, plant=none'
|
||||||
#return f'{self._x}, {self._y}), Plant: {self._plant}'
|
#return f'{self._x}, {self._y}), Plant: {self._plant}'
|
||||||
|
|
||||||
# współrzędne pola
|
# współrzędne pola
|
||||||
def get_coordinates(self):
|
def get_coordinates(self):
|
||||||
return self._x, self._y
|
return self._x, self._y
|
||||||
|
|
||||||
# id gleby
|
# id gleby
|
||||||
def get_id(self):
|
def get_id(self):
|
||||||
return self._id
|
return self._id
|
||||||
|
|
||||||
# zasadzenie roślinki
|
# zasadzenie roślinki
|
||||||
def add_plant(self, plant):
|
def add_plant(self, plant):
|
||||||
if not self.have_plant():
|
if not self.have_plant():
|
||||||
plant.add_soil(self)
|
plant.add_soil(self)
|
||||||
self._plant = plant
|
self._plant = plant
|
||||||
|
|
||||||
# zwraca czy w ziemi znajduje się roślinka
|
# zwraca czy w ziemi znajduje się roślinka
|
||||||
def have_plant(self):
|
def have_plant(self):
|
||||||
return self._plant != -1
|
return self._plant != -1
|
||||||
|
|
||||||
# zwraca roślinkę znajdującą się w ziemii
|
# zwraca roślinkę znajdującą się w ziemii
|
||||||
def get_plant(self):
|
def get_plant(self):
|
||||||
return self._plant
|
return self._plant
|
||||||
|
|
||||||
def get_pH(self):
|
def get_pH(self):
|
||||||
return self._pH
|
return self._pH
|
||||||
|
|
||||||
def get_dry_level(self):
|
def get_dry_level(self):
|
||||||
return self._dry
|
return self._dry
|
||||||
|
|
||||||
#sprawdza w ilu procentach ziemia jest sucha
|
#sprawdza w ilu procentach ziemia jest sucha
|
||||||
def is_dry(self):
|
def is_dry(self):
|
||||||
self.__drying()
|
self.__drying()
|
||||||
if self._dry < 30:
|
if self._dry < 30:
|
||||||
return 'False'
|
return 'False'
|
||||||
elif 30 <= self._dry < 70:
|
elif 30 <= self._dry < 70:
|
||||||
return 'Medium'
|
return 'Medium'
|
||||||
else:
|
else:
|
||||||
return 'True'
|
return 'True'
|
||||||
|
|
||||||
#metoda wysuszajaca ziemie. dodaje wysuszenie do ziemi, wywolywana w momencie sprawdzania czy ziemia jest sucha
|
#metoda wysuszajaca ziemie. dodaje wysuszenie do ziemi, wywolywana w momencie sprawdzania czy ziemia jest sucha
|
||||||
def __drying(self):
|
def __drying(self):
|
||||||
checktime = datetime.now()
|
checktime = datetime.now()
|
||||||
delta = checktime - self._starttime
|
delta = checktime - self._starttime
|
||||||
a = delta //60
|
a = delta //60
|
||||||
self._dry += a
|
self._dry += a
|
||||||
self._starttime = checktime
|
self._starttime = checktime
|
||||||
self.__is_dry()
|
self.__is_dry()
|
||||||
|
|
||||||
|
|
||||||
# usuwa roślinkę z ziemi i ją zwraca
|
# usuwa roślinkę z ziemi i ją zwraca
|
||||||
def plant_remove(self):
|
def plant_remove(self):
|
||||||
if self.have_plant():
|
if self.have_plant():
|
||||||
a = self.get_plant()
|
a = self.get_plant()
|
||||||
a.leave_soil()
|
a.leave_soil()
|
||||||
self._plant = -1
|
self._plant = -1
|
Loading…
Reference in New Issue
Block a user