I have been working further on my text adventure (see thread: http://www.daniweb.com/forums/thread285737.html) and have come to the part where I would like to manage the change of time (of day) and adjust the date as time passes. I have some code that does it, but was wondering if there is a better way.
I have the following global variables:
# timeMgr variables
vtime = 4
vday = "Monday"
vdate = 14
vmonth = "March"
vyear = 514
vhour = "It is the morning of Monday, 14 March, 514"
and I call the following code after actions have occurred:
def timeMgr():
""" Time Manager for the village """
# global variables for the time manager
global vtime, vhour, vday, vdate, vmonth, vyear
# factor 1 hours for each activity
vtime += 1
if vtime < 12: # morning indicator
# format the vhour string for the time of day
vhour = "It is the morning of "
vhour += vday
vhour += ", "
vhour += str(vdate)
vhour += " "
vhour += vmonth
vhour += ", "
vhour += str(vyear)
vhour += "."
print vhour
else:
if vtime < 18: # afternoon indicator
vhour = "It is the afternoon of "
vhour += vday
vhour += ", "
vhour += str(vdate)
vhour += " "
vhour += vmonth
vhour += ", "
vhour += str(vyear)
vhour += "."
print vhour
else:
if vtime < 24: # evening indicator
vhour = "It is the evening of "
vhour += vday
vhour += ", "
vhour += str(vdate)
vhour += " "
vhour += vmonth
vhour += ", "
vhour += str(vyear)
vhour += "."
print vhour
elif vtime == 24: # end of day indicator
vhour = "The day has ended, you crawl to your bed and get some much needed rest!"
print vhour
vtime = 0
if vdate != 30:
vdate +=1
else:
vdate = 1
# cycle the end of the month to the next month
if vmonth == "March":
vmonth = "April"
elif vmonth == "April":
vmonth = "May"
elif vmonth == "May":
vmonth = "June"
elif vmonth == "June":
vmonth = "July"
elif vmonth == "July":
vmonth = "August"
elif vmonth == "August":
vmonth = "September"
elif vmonth == "September":
vmonth = "October"
elif vmonth == "October":
vmonth = "November"
elif vmonth == "November":
vmonth = "December"
elif vmonth == "December":
vmonth = "January"
elif vmonth == "January":
vmonth = "February"
elif vmonth == "February":
vmonth = "March"
else:
print "There is a month of the year problem!"
# cycle the end of the day to the next day
if vday == "Monday":
vday = "Tuesday"
elif vday == "Tuesday":
vday = "Wednesday"
elif vday == "Wednesday":
vday = "Thursday"
elif vday == "Thursday":
vday = "Friday"
elif vday == "Friday":
vday = "Saturday"
elif vday == "Saturday":
vday = "Sunday"
elif vday == "Sunday":
vday = "Monday"
else:
print "There is a day of the week problem!"
else:
print "There is an hour of the day problem!"
I keep thinking it is too much code, but can't find an easier way to handle it. Any help, clues or other notes would be appreciated.