Fix zombie plants

pull/1/head
Jake Funke 2017-03-08 23:04:09 +00:00
parent c0e943a6df
commit c26db83caa
2 changed files with 34 additions and 20 deletions

View File

@ -147,7 +147,9 @@ class Plant(object):
self.file_name = this_filename
self.start_time = int(time.time())
self.last_time = int(time.time())
self.watered_timestamp = int(0)
# must water plant first day
self.watered_timestamp = int(time.time())-(24*3601)
# self.watered_timestamp = int(time.time()) # debug
self.watered_times = 0
def rarity_check(self):
@ -192,9 +194,19 @@ class Plant(object):
def water(self):
# Increase plant growth stage
# TODO: overwatering? if more than once a day it dies?
if not self.dead:
self.watered_timestamp = int(time.time())
self.watered_times += 1
def dead_check(self):
time_delta_watered = int(time.time()) - self.watered_timestamp
# if it has been >5 days since watering, sorry plant is dead :(
# if time_delta_watered > 5: #debug
if time_delta_watered > (5 * (24 * 3600)):
self.dead = True
return self.dead
def mutate_check(self):
# Create plant mutation
# TODO: when out of debug this needs to be set to high number (1000
@ -240,7 +252,7 @@ class Plant(object):
# life_stages = (1*day, 2*day, 3*day, 4*day, 5*day)
# life_stages = (1, 2, 3, 4, 5)
# leave this untouched bc it works for now
while (self.stage < 5) or (self.dead == False):
while not self.dead:
time.sleep(1)
self.ticks += 1
# print self.ticks
@ -250,6 +262,8 @@ class Plant(object):
#print self.parse_plant()
if self.mutate_check():
1==1
if self.dead_check():
1==1
#print self.parse_plant()
# what kills the plant?
@ -307,13 +321,11 @@ class DataManager(object):
# TODO: this needs to check the current ticks w/ life stage
# compare timestamp of signout to timestamp now
time_delta_last = current_timestamp - this_plant.last_time
time_delta_watered = int(time.time()) - this_plant.watered_timestamp
is_dead = this_plant.dead_check()
# if it has been >5 days since watering, sorry plant is dead :(
if time_delta_watered > 5 * (24 * 3600):
this_plant.dead = True
if not is_dead:
this_plant.ticks += time_delta_last
return this_plant
def data_write_json(self, this_plant):

View File

@ -60,7 +60,6 @@ class CursedMenu(object):
self.__exit__()
traceback.print_exc()
def draw(self):
'''Draw the menu and lines'''
self.screen.refresh()
@ -74,13 +73,16 @@ class CursedMenu(object):
textstyle = self.highlighted
self.screen.addstr(5+index,4, "%d - %s" % (index+1, self.options[index]), textstyle)
self.screen.addstr(10,2, self.plant_string, curses.A_NORMAL)
self.screen.addstr(11,2, self.plant_ticks, curses.A_NORMAL)
self.screen.addstr(11,2, self.plant_string, curses.A_NORMAL)
self.screen.addstr(12,2, self.plant_ticks, curses.A_NORMAL)
if int(time.time()) <= self.plant.watered_timestamp + 5*24*3600:
if not self.plant.dead:
if int(time.time()) <= self.plant.watered_timestamp + 24*3600:
self.screen.addstr(6,13, " - plant watered today :)", curses.A_NORMAL)
else:
self.screen.addstr(6,13, " ", curses.A_NORMAL)
else:
self.screen.addstr(6,13, " - you can't water a dead plant :(", curses.A_NORMAL)
try:
self.screen.refresh()
except Exception as exception:
@ -91,10 +93,10 @@ class CursedMenu(object):
def update_plant_live(self):
# Updates plant data on menu screen, live!
# Will eventually use this to display ascii art...
if self.initialized:
while self.exit is not True:
while not self.exit:
self.plant_string = self.plant.parse_plant()
self.plant_ticks = str(self.plant.ticks)
if self.initialized:
self.draw()
time.sleep(1)