Created timer thread
This commit is contained in:
parent
6cc60b6f99
commit
852c672198
30
botany.py
30
botany.py
@ -6,8 +6,9 @@ import json
|
|||||||
import math
|
import math
|
||||||
import os.path
|
import os.path
|
||||||
import random
|
import random
|
||||||
import threading
|
|
||||||
import getpass
|
import getpass
|
||||||
|
import threading
|
||||||
|
|
||||||
|
|
||||||
# ideas go here
|
# ideas go here
|
||||||
# lifecycle of a plant
|
# lifecycle of a plant
|
||||||
@ -53,7 +54,6 @@ import getpass
|
|||||||
#
|
#
|
||||||
# curses.endwin()
|
# curses.endwin()
|
||||||
|
|
||||||
|
|
||||||
class Plant(object):
|
class Plant(object):
|
||||||
stage_dict = {
|
stage_dict = {
|
||||||
0: 'seed',
|
0: 'seed',
|
||||||
@ -126,6 +126,7 @@ class Plant(object):
|
|||||||
self.color = random.randint(0,len(self.color_dict)-1)
|
self.color = random.randint(0,len(self.color_dict)-1)
|
||||||
self.rarity = self.rarity_check()
|
self.rarity = self.rarity_check()
|
||||||
self.ticks = 0
|
self.ticks = 0
|
||||||
|
self.dead = False
|
||||||
|
|
||||||
def rarity_check(self):
|
def rarity_check(self):
|
||||||
CONST_RARITY_MAX = 256.0
|
CONST_RARITY_MAX = 256.0
|
||||||
@ -182,21 +183,30 @@ class Plant(object):
|
|||||||
output += self.species_dict[self.species] + " "
|
output += self.species_dict[self.species] + " "
|
||||||
print output
|
print output
|
||||||
|
|
||||||
def live(self):
|
def start_life(self):
|
||||||
|
# runs forever
|
||||||
|
thread = threading.Thread(target=self.life, args=())
|
||||||
|
thread.daemon = True
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
def life(self):
|
||||||
# I've created life :)
|
# I've created life :)
|
||||||
# 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)
|
||||||
self.parse_plant()
|
# TODO: stopped here 3/6 evening
|
||||||
while self.stage < 5:
|
# leave this untouched bc it works for now
|
||||||
|
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()
|
||||||
self.parse_plant()
|
self.parse_plant()
|
||||||
|
|
||||||
raw_input("...")
|
# raw_input("...")
|
||||||
|
|
||||||
|
# what kills the plant?
|
||||||
|
|
||||||
## DEBUG:
|
## DEBUG:
|
||||||
# while my_plant.stage < len(my_plant.stage_dict)-1:
|
# while my_plant.stage < len(my_plant.stage_dict)-1:
|
||||||
@ -231,17 +241,21 @@ class DataManager(object):
|
|||||||
with open(json_filename, 'w') as outfile:
|
with open(json_filename, 'w') as outfile:
|
||||||
json.dump(this_plant.__dict__, outfile)
|
json.dump(this_plant.__dict__, outfile)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
my_data = DataManager()
|
my_data = DataManager()
|
||||||
# if plant save file does not exist
|
# if plant save file does not exist
|
||||||
if my_data.check_plant():
|
if my_data.check_plant():
|
||||||
my_plant = my_data.load_plant()
|
my_plant = my_data.load_plant()
|
||||||
|
my_plant.parse_plant()
|
||||||
# otherwise create new plant
|
# otherwise create new plant
|
||||||
else:
|
else:
|
||||||
my_plant = Plant()
|
my_plant = Plant()
|
||||||
|
|
||||||
# print my_plant.stage, my_plant.species, my_plant.color, my_plant.rarity, my_plant.mutation
|
# print my_plant.stage, my_plant.species, my_plant.color, my_plant.rarity, my_plant.mutation
|
||||||
my_plant.live()
|
my_plant.start_life()
|
||||||
|
print "Thread's running!"
|
||||||
|
raw_input('...')
|
||||||
my_data.save_plant(my_plant)
|
my_data.save_plant(my_plant)
|
||||||
my_data.data_write_json(my_plant)
|
my_data.data_write_json(my_plant)
|
||||||
print "end"
|
print "end"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user