Code: Select all
init python:
import datetime
class GameTime:
def __init__(self, dt="01 Jan 2018"):
self._dt = datetime.datetime.strptime( dt, "%d %b %Y" )
def alter(self, **kwargs):
self._dt += datetime.timedelta( **kwargs )
def __repr__(self):
return _strftime("%A, %d %b %Y %H:%M", self._dt.timetuple())
@property
def tod(self): #tod = time of day
return [ k[-1] for k in (
(0,1,2,3,4,5,6, "Night Time"),
(7,8,9,10,11, "Morning"),
(12, "Noon"),
(13,14,15,16,17, "Afternoon"),
(18,19,20, "Evening"),
(21,22,23, "Late Evening") ) if self._dt.hour in k ][0]
So I added a section into my game to check if it's "night time"
Code: Select all
if gt.tod == "Night Time":
"watch out for ghosts!"
I tried this:
Code: Select all
@property
def daytype(self):
return _strftime("%A", self._dt.timetuple())
Code: Select all
if gt.daytype == "Saturday" or "Sunday":
"It's the weekend!"