Implement growth while away

pull/1/head
Jake Funke 2017-03-08 08:45:21 +00:00
parent 013ad58b59
commit 5fc813acb7
1 changed files with 24 additions and 18 deletions

View File

@ -147,7 +147,8 @@ class Plant(object):
self.file_name = this_filename self.file_name = this_filename
self.start_time = int(time.time()) self.start_time = int(time.time())
self.last_time = int(time.time()) self.last_time = int(time.time())
self.watered_date = 0 self.watered_date = datetime.datetime.fromtimestamp(0)
self.watered_times = 0
def rarity_check(self): def rarity_check(self):
# Generate plant rarity # Generate plant rarity
@ -192,6 +193,7 @@ class Plant(object):
def water(self): def water(self):
# Increase plant growth stage # Increase plant growth stage
self.watered_date = datetime.datetime.now().date() self.watered_date = datetime.datetime.now().date()
self.watered_times += 1
def mutate_check(self): def mutate_check(self):
# Create plant mutation # Create plant mutation
@ -233,15 +235,15 @@ class Plant(object):
def life(self): def life(self):
# I've created life :) # I've created life :)
# TODO: change out of debug # TODO: change out of debug
# life_stages = (5, 15, 30, 45, 60) life_stages = (5, 15, 30, 45, 60)
life_stages = (1, 2, 3, 4, 5) # life_stages = (1, 2, 3, 4, 5)
# leave this untouched bc it works for now # leave this untouched bc it works for now
while (self.stage < 5) or (self.dead == False): while (self.stage < 5) or (self.dead == False):
time.sleep(1) time.sleep(1)
self.ticks += 1 self.ticks += 1
# print self.ticks # print self.ticks
if self.stage < len(self.stage_dict)-1: if self.stage < len(self.stage_dict)-1:
if self.ticks == life_stages[self.stage]: if self.ticks >= life_stages[self.stage]:
self.growth() self.growth()
#print self.parse_plant() #print self.parse_plant()
if self.mutate_check(): if self.mutate_check():
@ -291,8 +293,25 @@ class DataManager(object):
def load_plant(self): def load_plant(self):
# load savefile # load savefile
# need to calculate lifetime ticks to determine stage of life
with open(self.savefile_path, 'rb') as f: with open(self.savefile_path, 'rb') as f:
this_plant = pickle.load(f) this_plant = pickle.load(f)
current_timestamp = int(time.time())
current_date = datetime.datetime.now().date()
# i wonder if this is a better way to calculate ticks age?
time_delta_overall = current_timestamp - this_plant.start_time
# 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((current_date - this_plant.watered_date).days)
# if it has been >5 days since watering, sorry plant is dead :(
if time_delta_watered > 5:
this_plant.dead = True
this_plant.ticks += time_delta_last
return this_plant return this_plant
def data_write_json(self, this_plant): def data_write_json(self, this_plant):
@ -302,19 +321,6 @@ class DataManager(object):
with open(json_file, 'w') as outfile: with open(json_file, 'w') as outfile:
json.dump(this_plant.__dict__, outfile) json.dump(this_plant.__dict__, outfile)
def whats_happened(self,this_plant):
# need to calculate lifetime ticks to determine stage of life
# need to calculate if it's been too long since it's watered
current_timestamp = int(time.time())
current_date = datetime.datetime.now().date()
time_delta_overall = current_timestamp - this_plant.start_time
time_delta_last = current_timestamp - this_plant.last_time
time_delta_watered = (current_date - this_plant.watered_date).days
# compare timestamp of signout to timestamp now
# need to create timestamps to begin with..
# create plant birthday = unix datetime
if __name__ == '__main__': if __name__ == '__main__':
my_data = DataManager() my_data = DataManager()
# if plant save file exists # if plant save file exists