fix scoping on death_check change

pull/53/head
Nate Smith 2023-12-06 21:36:15 -08:00
parent ed7498bd4a
commit be770c6b5e
2 changed files with 8 additions and 8 deletions

View File

@ -318,7 +318,7 @@ if __name__ == '__main__':
my_plant = Plant(my_data.savefile_path) my_plant = Plant(my_data.savefile_path)
my_data.data_write_json(my_plant) my_data.data_write_json(my_plant)
# my_plant is either a fresh plant or an existing plant at this point # my_plant is either a fresh plant or an existing plant at this point
my_plant.start_life() my_plant.start_life(my_data)
my_data.start_threads(my_plant) my_data.start_threads(my_plant)
try: try:

View File

@ -323,13 +323,13 @@ class Plant:
def unlock_new_creation(self): def unlock_new_creation(self):
self.write_lock = False self.write_lock = False
def start_life(self): def start_life(self, dm):
# runs life on a thread # runs life on a thread
thread = threading.Thread(target=self.life, args=()) thread = threading.Thread(target=self.life, args=(dm,))
thread.daemon = True thread.daemon = True
thread.start() thread.start()
def life(self): def life(self, dm):
# I've created life :) # I've created life :)
generation_bonus = round(0.2 * (self.generation - 1), 1) generation_bonus = round(0.2 * (self.generation - 1), 1)
score_inc = 1 * (1 + generation_bonus) score_inc = 1 * (1 + generation_bonus)
@ -346,10 +346,10 @@ class Plant:
# Do something # Do something
pass pass
if self.dead_check(): if self.dead_check():
self.save_plant(this_plant) dm.save_plant(this_plant)
self.data_write_json(this_plant) dm.data_write_json(this_plant)
self.update_garden_db(this_plant) dm.update_garden_db(this_plant)
self.harvest_plant(this_plant) dm.harvest_plant(this_plant)
this_plant.unlock_new_creation() this_plant.unlock_new_creation()
# TODO: event check # TODO: event check
time.sleep(2) time.sleep(2)