AI-Project/survival/components/time_component.py

33 lines
954 B
Python
Raw Normal View History

2021-04-18 19:53:51 +02:00
class TimeComponent:
2021-06-06 19:55:55 +02:00
def __init__(self, minute=0, hour=0, day=0, timer=0):
2021-04-18 19:53:51 +02:00
self.minute = minute
self.hour = hour
self.day = day
self.timer = timer
def add_time(self, minutes):
self.minute += minutes
if self.minute >= 60:
temp = self.minute - 60
self.hour += 1
if self.hour >= 24:
temp2 = self.hour - 24
self.day += 1
self.hour = temp2
self.minute = temp
2021-06-06 19:55:55 +02:00
def total_minutes(self):
return self.minute + self.hour * 60 + self.day * 1440
2021-04-18 19:53:51 +02:00
def __str__(self):
return f'Day {self.day}, {self.hour}:{self.minute}'
2021-06-06 19:55:55 +02:00
def __eq__(self, other):
return self.total_minutes() == other.total_minutes()
def __gt__(self, other):
return self.total_minutes() > other.total_minutes()
def __lt__(self, other):
return self.total_minutes() < other.total_minutes()