From b0154dc37e5eee65cb2f1f4d98810458d53bc68f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Ma=C5=82yszka?= Date: Tue, 7 Apr 2020 17:15:42 +0000 Subject: [PATCH] =?UTF-8?q?Prze=C5=9Blij=20pliki=20do=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dodanie klas soil i carrot --- carrot.py | 34 +++++++++++++++ plant.py | 125 ++++++++++++++++++++++++++++-------------------------- soil.py | 67 +++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+), 60 deletions(-) create mode 100644 carrot.py create mode 100644 soil.py diff --git a/carrot.py b/carrot.py new file mode 100644 index 0000000..c37dd32 --- /dev/null +++ b/carrot.py @@ -0,0 +1,34 @@ +from plant import Plant +from datetime import datetime + +class Carrot(Plant): + + def __init__(self): + super().__init__() + self._wasFertilized = False #roslina nie byla nawozona przy tworzeniu + self._starttime = datetime.now() + + def collect(self): + if self.have_soil(): + self.__growing() + if self._collect < 90: + return 'False' + elif 90 <= self._collect <= 105: + return 'True' + elif self._collect > 105: + return 'Delete' + + def fertillizing(self): + if 30 <= self._collect <= 50: + self._wasFertilized = True + return True + else: + return False + + #każde iles czasu zwieksza wzrost rosliny, wywolywana w momencie sprawdzania czy roslina jest gotowa do zbiorow + def __growing(self): + checktime = datetime.now() + delta = checktime - self._starttime + a = delta // 60 + self._collect += a + self._starttime = checktime diff --git a/plant.py b/plant.py index e37df46..5775abf 100644 --- a/plant.py +++ b/plant.py @@ -1,60 +1,65 @@ -from abc import abc, abstractmethod - -class Plant: - - #tworzymy jakas rosline co ma nazwe,i id. ID powiedzmy ze buraki będą miały 1, marchewki 2 itd. gleby powiedzmy tez damy 4 i beda mialy id 5-8 - def __init__(self, name, ID): - super().__init__() - self._soil = -1 #jak tworzymy rosline to nie bedzie ona miala gleby - self._name = name #to nazwa rosliny będzie np. burak1 - self._id = ID #id rosliny buraki bedą miały 1, i po tym inne obiekty beda rozpoznawac ten obiekt - - #to jest jakbysmy usuneli obiekt zabezpieczenie, zeby gleba pozniej była wolna - def __del__(self): - self.leave_soil() - - #to sie drukuje jak zapytamy o stworzony obiekt - def __str__(self): - return 'Plant: %s , Soil: %s , Status: %s' % (self._name, self._soil, self._collect()) - - #metoda abstrakcyjna, kazda roslina ma inny czas rosniecia wiec pass - @abstractmethod - def collect(self): - pass - - @abstractmethod - def protect(self, protection): - pass - - #pobieramy współrzędne roślinki - def get_coordinates(self): - if self.have_soil(): - a = self.get_soil() - a.get_coordinates(self) #get coordinates bedzie metodą w glebie - - #pobieramy id roślinki - def get_id(self): - return self._id - - #dodajemy glebe - def add_soil(self, soil): - self._soil = soil - - #zwraca czy roslinka znajduje sie w ziemii obecnie - jak nie ma gleby to znaczy ze nie jest zasadzona jeszcze albo już. - def have_soil(self): - return self._soil is not -1 - - #pobieramy jaka ma glebe, gleba tutaj będzie obiektem - def get_soil(self): - return self._soil - - #to w przypadku jak bedziemy wyciagac z ziemii roslinke - def leave_soil(self): - if self.have_soil(): - a = self.get_soil() - a.plant.remove(self) #to bedzie metoda w klasie Soil, bedzie usuwac roslinke z gleby - self._soil = -1 - - - - +from abc import abc, abstractmethod + +class Plant: + + #tworzymy jakas rosline co ma nazwe,i id. ID powiedzmy ze buraki beda mialy 1, marchewki 2 itd. gleby powiedzmy tez damy 4 i beda mialy id 5-8 + def __init__(self, name, ID): + super().__init__() + self._soil = -1 #jak tworzymy rosline to nie bedzie ona miala gleby + self._name = name #to nazwa rosliny będzie np. burak1 + self._id = ID #id rosliny buraki bedą mialy 1, i po tym inne obiekty beda rozpoznawac ten obiekt + self._collect = 0 #nowa roslina jest w 0% dojrzala + + #to jest jakbysmy usuneli obiekt. zabezpieczenie, zeby gleba pozniej byla wolna + def __del__(self): + self.leave_soil() + + #to sie drukuje jak zapytamy o stworzony obiekt + def __str__(self): + return 'Plant: %s , Soil: %s , Status: %s' % (self._name, self._soil, self._collect()) + + #metoda abstrakcyjna, kazda roslina ma inny czas rosniecia wiec pass + @abstractmethod + def collect(self): + pass + + @abstractmethod + def fertillizing(self): + pass + + @abstractmethod + def growing(self): + pass + + #pobieramy wspolrzedne roslinki + def get_coordinates(self): + if self.have_soil(): + a = self.get_soil() + a.get_coordinates(self) #get coordinates jest metoda w glebie + + #pobieramy id roślinki + def get_id(self): + return self._id + + #dodajemy glebe + def add_soil(self, soil): + self._soil = soil + + #zwraca czy roslinka znajduje sie w ziemii obecnie - jak nie ma gleby to znaczy ze nie jest zasadzona jeszcze albo już. + def have_soil(self): + return self._soil is not -1 + + #pobieramy jaka ma glebe, gleba tutaj będzie obiektem + def get_soil(self): + return self._soil + + #to w przypadku jak bedziemy wyciagac z ziemii roslinke + def leave_soil(self): + if self.have_soil(): + a = self.get_soil() + a.plant_remove() #to bedzie metoda w klasie Soil, bedzie usuwac roslinke z gleby + self._soil = -1 + + + + diff --git a/soil.py b/soil.py new file mode 100644 index 0000000..73f154c --- /dev/null +++ b/soil.py @@ -0,0 +1,67 @@ +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): + return '(%s, %s), Plant: %s' % (self._x, self._y, self.have_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 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 \ No newline at end of file