klasa ziemi (zmienione)
This commit is contained in:
parent
7930f1fab7
commit
f35adaea6b
@ -1,78 +1,78 @@
|
||||
from datetime import datetime
|
||||
|
||||
class Soil:
|
||||
|
||||
def __init__(self, pH, dry):
|
||||
super().__init__()
|
||||
#self._id = ID
|
||||
#self._x = x
|
||||
#self._y = y
|
||||
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
|
||||
self._starttime = datetime.now()
|
||||
|
||||
# def __del__(self):
|
||||
# self.plant_remove()
|
||||
|
||||
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'
|
||||
#return f'{self._x}, {self._y}), Plant: {self._plant}'
|
||||
|
||||
# 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 != -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'
|
||||
|
||||
#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()
|
||||
from datetime import datetime
|
||||
|
||||
class Soil:
|
||||
|
||||
def __init__(self, pH, dry):
|
||||
super().__init__()
|
||||
#self._id = ID
|
||||
#self._x = x
|
||||
#self._y = y
|
||||
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
|
||||
self._starttime = datetime.now()
|
||||
|
||||
# def __del__(self):
|
||||
# self.plant_remove()
|
||||
|
||||
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'
|
||||
#return f'{self._x}, {self._y}), Plant: {self._plant}'
|
||||
|
||||
# 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 != -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'
|
||||
|
||||
#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
|
Loading…
Reference in New Issue
Block a user