Update data structures

pull/6/head
Jake Funke 2017-09-21 14:29:11 -07:00
parent d24c52277a
commit fba9bacf07
2 changed files with 150 additions and 144 deletions

224
botany.py
View File

@ -21,112 +21,116 @@ from menu_screen import *
class Plant(object): class Plant(object):
# This is your plant! # This is your plant!
stage_dict = { stage_list = [
0: 'seed', 'seed',
1: 'seedling', 'seedling',
2: 'young', 'young',
3: 'mature', 'mature',
4: 'flowering', 'flowering',
5: 'seed-bearing', 'seed-bearing',
} ]
color_dict = { color_list = [
0: 'red', 'red',
1: 'orange', 'orange',
2: 'yellow', 'yellow',
3: 'green', 'green',
4: 'blue', 'blue',
5: 'indigo', 'indigo',
6: 'violet', 'violet',
7: 'white', 'white',
8: 'black', 'black',
9: 'gold', 'gold',
10: 'rainbow', 'rainbow',
} ]
rarity_dict = { rarity_list = [
0: 'common', 'common',
1: 'uncommon', 'uncommon',
2: 'rare', 'rare',
3: 'legendary', 'legendary',
4: 'godly', 'godly',
} ]
species_dict = { species_list = [
0: 'poppy', 'poppy',
1: 'cactus', 'cactus',
2: 'aloe', 'aloe',
3: 'venus flytrap', 'venus flytrap',
4: 'jade plant', 'jade plant',
5: 'fern', 'fern',
6: 'daffodil', 'daffodil',
7: 'sunflower', 'sunflower',
8: 'baobab', 'baobab',
9: 'lithops', 'lithops',
10: 'hemp', 'hemp',
11: 'pansy', 'pansy',
12: 'iris', 'iris',
13: 'agave', 'agave',
14: 'ficus', 'ficus',
15: 'moss', 'moss',
16: 'sage', 'sage',
17: 'snapdragon', 'snapdragon',
18: 'columbine', 'columbine',
19: 'brugmansia', 'brugmansia',
20: 'palm', 'palm',
} ]
mutation_dict = { mutation_list = [
0: '', '',
1: 'humming', 'humming',
2: 'noxious', 'noxious',
3: 'vorpal', 'vorpal',
4: 'glowing', 'glowing',
5: 'electric', 'electric',
6: 'icy', 'icy',
7: 'flaming', 'flaming',
8: 'psychic', 'psychic',
9: 'screaming', 'screaming',
10: 'chaotic', 'chaotic',
11: 'hissing', 'hissing',
12: 'gelatinous', 'gelatinous',
13: 'deformed', 'deformed',
14: 'shaggy', 'shaggy',
15: 'scaly', 'scaly',
16: 'depressed', 'depressed',
17: 'anxious', 'anxious',
18: 'metallic', 'metallic',
19: 'glossy', 'glossy',
20: 'psychedelic', 'psychedelic',
21: 'bonsai', 'bonsai',
22: 'foamy', 'foamy',
23: 'singing', 'singing',
24: 'fractal', 'fractal',
25: 'crunchy', 'crunchy',
26: 'goth', 'goth',
27: 'oozing', 'oozing',
28: 'stinky', 'stinky',
29: 'aromatic', 'aromatic',
30: 'juicy', 'juicy',
31: 'smug', 'smug',
32: 'vibrating', 'vibrating',
33: 'lithe', 'lithe',
34: 'chalky', 'chalky',
35: 'naive', 'naive',
36: 'ersatz', 'ersatz',
37: 'disco', 'disco',
38: 'levitating', 'levitating',
39: 'colossal', 'colossal',
} 'luminous',
'cosmic',
'ethereal',
]
def __init__(self, this_filename, generation=1): def __init__(self, this_filename, generation=1):
# Constructor # Constructor
self.plant_id = str(uuid.uuid4()) self.plant_id = str(uuid.uuid4())
self.life_stages = (3600*24, (3600*24)*3, (3600*24)*10, (3600*24)*20, (3600*24)*30) # self.life_stages = (3600*24, (3600*24)*3, (3600*24)*10, (3600*24)*20, (3600*24)*30)
self.life_stages = (5, 10, 15, 20, 25)
self.stage = 0 self.stage = 0
self.mutation = 0 self.mutation = 0
self.species = random.randint(0,len(self.species_dict)-1) self.species = random.randint(0,len(self.species_list)-1)
self.color = random.randint(0,len(self.color_dict)-1) self.color = random.randint(0,len(self.color_list)-1)
self.rarity = self.rarity_check() self.rarity = self.rarity_check()
self.ticks = 0 self.ticks = 0
self.age_formatted = "0" self.age_formatted = "0"
@ -150,14 +154,14 @@ class Plant(object):
# Converts plant data to human-readable format # Converts plant data to human-readable format
output = "" output = ""
if self.stage >= 3: if self.stage >= 3:
output += self.rarity_dict[self.rarity] + " " output += self.rarity_list[self.rarity] + " "
if self.mutation != 0: if self.mutation != 0:
output += self.mutation_dict[self.mutation] + " " output += self.mutation_list[self.mutation] + " "
if self.stage >= 4: if self.stage >= 4:
output += self.color_dict[self.color] + " " output += self.color_list[self.color] + " "
output += self.stage_dict[self.stage] + " " output += self.stage_list[self.stage] + " "
if self.stage >= 2: if self.stage >= 2:
output += self.species_dict[self.species] + " " output += self.species_list[self.species] + " "
return output.strip() return output.strip()
def rarity_check(self): def rarity_check(self):
@ -211,7 +215,7 @@ class Plant(object):
mutation_seed = random.randint(1,CONST_MUTATION_RARITY) mutation_seed = random.randint(1,CONST_MUTATION_RARITY)
if mutation_seed == CONST_MUTATION_RARITY: if mutation_seed == CONST_MUTATION_RARITY:
# mutation gained! # mutation gained!
mutation = random.randint(0,len(self.mutation_dict)-1) mutation = random.randint(0,len(self.mutation_list)-1)
if self.mutation == 0: if self.mutation == 0:
self.mutation = mutation self.mutation = mutation
return True return True
@ -220,7 +224,7 @@ class Plant(object):
def growth(self): def growth(self):
# Increase plant growth stage # Increase plant growth stage
if self.stage < (len(self.stage_dict)-1): if self.stage < (len(self.stage_list)-1):
self.stage += 1 self.stage += 1
def water(self): def water(self):
@ -267,7 +271,7 @@ class Plant(object):
if not self.dead: if not self.dead:
if self.watered_24h: if self.watered_24h:
self.ticks += 1 self.ticks += 1
if self.stage < len(self.stage_dict)-1: if self.stage < len(self.stage_list)-1:
if self.ticks >= self.life_stages[self.stage]: if self.ticks >= self.life_stages[self.stage]:
self.growth() self.growth()
if self.mutate_check(): if self.mutate_check():
@ -414,6 +418,8 @@ class DataManager(object):
def update_garden_db(self, this_plant): def update_garden_db(self, this_plant):
# insert or update this plant id's entry in DB # insert or update this plant id's entry in DB
# TODO: make sure other instances of user are deleted
# Could create a clean db function
self.init_database() self.init_database()
age_formatted = self.plant_age_convert(this_plant) age_formatted = self.plant_age_convert(this_plant)
conn = sqlite3.connect(self.garden_db_path) conn = sqlite3.connect(self.garden_db_path)
@ -480,17 +486,17 @@ class DataManager(object):
"is_dead":this_plant.dead, "is_dead":this_plant.dead,
"last_watered":this_plant.watered_timestamp, "last_watered":this_plant.watered_timestamp,
"file_name":this_plant.file_name, "file_name":this_plant.file_name,
"stage": this_plant.stage_dict[this_plant.stage], "stage": this_plant.stage_list[this_plant.stage],
"generation": this_plant.generation, "generation": this_plant.generation,
} }
if this_plant.stage >= 3: if this_plant.stage >= 3:
plant_info["rarity"] = this_plant.rarity_dict[this_plant.rarity] plant_info["rarity"] = this_plant.rarity_list[this_plant.rarity]
if this_plant.mutation != 0: if this_plant.mutation != 0:
plant_info["mutation"] = this_plant.mutation_dict[this_plant.mutation] plant_info["mutation"] = this_plant.mutation_list[this_plant.mutation]
if this_plant.stage >= 4: if this_plant.stage >= 4:
plant_info["color"] = this_plant.color_dict[this_plant.color] plant_info["color"] = this_plant.color_list[this_plant.color]
if this_plant.stage >= 2: if this_plant.stage >= 2:
plant_info["species"] = this_plant.species_dict[this_plant.species] plant_info["species"] = this_plant.species_list[this_plant.species]
with open(json_file, 'w') as outfile: with open(json_file, 'w') as outfile:
json.dump(plant_info, outfile) json.dump(plant_info, outfile)

View File

@ -128,29 +128,29 @@ class CursedMenu(object):
def draw_plant_ascii(self, this_plant): def draw_plant_ascii(self, this_plant):
ypos = 1 ypos = 1
xpos = int((self.maxx-37)/2 + 25) xpos = int((self.maxx-37)/2 + 25)
plant_art_dict = { plant_art_list = [
0: 'poppy', 'poppy',
1: 'cactus', 'cactus',
2: 'aloe', 'aloe',
3: 'flytrap', 'flytrap',
4: 'jadeplant', 'jadeplant',
5: 'fern', 'fern',
6: 'daffodil', 'daffodil',
7: 'sunflower', 'sunflower',
8: 'baobab', 'baobab',
9: 'lithops', 'lithops',
10: 'hemp', 'hemp',
11: 'pansy', 'pansy',
12: 'iris', 'iris',
13: 'agave', 'agave',
14: 'ficus', 'ficus',
15: 'moss', 'moss',
16: 'sage', 'sage',
17: 'snapdragon', 'snapdragon',
18: 'columbine', 'columbine',
19: 'brugmansia', 'brugmansia',
20: 'palm', 'palm',
} ]
if this_plant.dead == True: if this_plant.dead == True:
self.ascii_render('rip.txt', ypos, xpos) self.ascii_render('rip.txt', ypos, xpos)
@ -159,13 +159,13 @@ class CursedMenu(object):
elif this_plant.stage == 1: elif this_plant.stage == 1:
self.ascii_render('seedling.txt', ypos, xpos) self.ascii_render('seedling.txt', ypos, xpos)
elif this_plant.stage == 2: elif this_plant.stage == 2:
this_filename = plant_art_dict[this_plant.species]+'1.txt' this_filename = plant_art_list[this_plant.species]+'1.txt'
self.ascii_render(this_filename, ypos, xpos) self.ascii_render(this_filename, ypos, xpos)
elif this_plant.stage == 3 or this_plant.stage == 5: elif this_plant.stage == 3 or this_plant.stage == 5:
this_filename = plant_art_dict[this_plant.species]+'2.txt' this_filename = plant_art_list[this_plant.species]+'2.txt'
self.ascii_render(this_filename, ypos, xpos) self.ascii_render(this_filename, ypos, xpos)
elif this_plant.stage == 4: elif this_plant.stage == 4:
this_filename = plant_art_dict[this_plant.species]+'3.txt' this_filename = plant_art_list[this_plant.species]+'3.txt'
self.ascii_render(this_filename, ypos, xpos) self.ascii_render(this_filename, ypos, xpos)
def draw_default(self): def draw_default(self):
@ -314,8 +314,8 @@ class CursedMenu(object):
def get_plant_description(self, this_plant): def get_plant_description(self, this_plant):
output_text = "" output_text = ""
this_species = this_plant.species_dict[this_plant.species] this_species = this_plant.species_list[this_plant.species]
this_color = this_plant.color_dict[this_plant.color] this_color = this_plant.color_list[this_plant.color]
this_stage = this_plant.stage this_stage = this_plant.stage
stage_descriptions = { stage_descriptions = {
@ -421,9 +421,9 @@ class CursedMenu(object):
# if seedling # if seedling
if this_stage == 1: if this_stage == 1:
species_options = [this_plant.species_dict[this_plant.species], species_options = [this_plant.species_list[this_plant.species],
this_plant.species_dict[(this_plant.species+3) % len(this_plant.species_dict)], this_plant.species_list[(this_plant.species+3) % len(this_plant.species_list)],
this_plant.species_dict[(this_plant.species-3) % len(this_plant.species_dict)]] this_plant.species_list[(this_plant.species-3) % len(this_plant.species_list)]]
random.shuffle(species_options) random.shuffle(species_options)
plant_hint = "It could be a(n) " + species_options[0] + ", " + species_options[1] + ", or " + species_options[2] plant_hint = "It could be a(n) " + species_options[0] + ", " + species_options[1] + ", or " + species_options[2]
output_text += plant_hint + ".\n" output_text += plant_hint + ".\n"
@ -436,9 +436,9 @@ class CursedMenu(object):
# if mature plant # if mature plant
if this_stage == 3: if this_stage == 3:
color_options = [this_plant.color_dict[this_plant.color], color_options = [this_plant.color_list[this_plant.color],
this_plant.color_dict[(this_plant.color+3) % len(this_plant.color_dict)], this_plant.color_list[(this_plant.color+3) % len(this_plant.color_list)],
this_plant.color_dict[(this_plant.color-3) % len(this_plant.color_dict)]] this_plant.color_list[(this_plant.color-3) % len(this_plant.color_list)]]
random.shuffle(color_options) random.shuffle(color_options)
plant_hint = "You can see the first hints of " + color_options[0] + ", " + color_options[1] + ", or " + color_options[2] plant_hint = "You can see the first hints of " + color_options[0] + ", " + color_options[1] + ", or " + color_options[2]
output_text += plant_hint + ".\n" output_text += plant_hint + ".\n"
@ -497,7 +497,7 @@ class CursedMenu(object):
def harvest_confirmation(self): def harvest_confirmation(self):
self.clear_info_pane() self.clear_info_pane()
# get plant description before printing # get plant description before printing
max_stage = len(self.plant.stage_dict) - 1 max_stage = len(self.plant.stage_list) - 1
harvest_text = "" harvest_text = ""
if not self.plant.dead: if not self.plant.dead:
if self.plant.stage == max_stage: if self.plant.stage == max_stage: