botany/botany.py

241 lines
6.8 KiB
Python
Raw Normal View History

2017-03-06 22:22:13 +00:00
from __future__ import division
2017-03-06 21:38:31 +00:00
import time
2017-03-06 22:22:13 +00:00
import pickle
2017-03-06 21:38:31 +00:00
import curses
import json
import math
import os.path
import random
import threading
2017-03-07 01:56:11 +00:00
import getpass
2017-03-06 21:38:31 +00:00
# ideas go here
# lifecycle of a plant
# seed -> seedling -> sprout -> young plant -> mature plant -> flower ->
# pollination -> fruit -> seeds
# mutations over time to yield different things? idk
# neighboring plants can cross pollinate for different plants
# health based on checkups and watering
# development plan
# build plant lifecycle just stepping through
2017-03-07 00:57:11 +00:00
# - What else should it do during life? growth alone is not all that
2017-03-06 21:38:31 +00:00
# interesting.
2017-03-07 00:57:11 +00:00
# - how long should each stage last ? thinking realistic lmao
# interaction
# - watering?
# - look at plant, how do you feel?
# - fertilize?
2017-03-06 21:38:31 +00:00
# build time system
# build persistence across sessions
2017-03-07 00:57:11 +00:00
2017-03-06 21:38:31 +00:00
# build ascii trees
# build gui?
# build multiplayer
# def display_update:
# myscreen = curses.initscr()
#
# myscreen.border(0)
# myscreen.addstr(1, 2, "you've planted a seed")
# myscreen.refresh()
#
# for i in range(1,20):
# myscreen.addstr(i, 2, str(i))
# time.sleep(1)
# myscreen.refresh()
#
# myscreen.getch()
#
# curses.endwin()
2017-03-07 01:56:11 +00:00
class Plant(object):
2017-03-06 23:20:31 +00:00
stage_dict = {
0: 'seed',
1: 'seedling',
2: 'young',
2017-03-06 23:29:23 +00:00
3: 'mature',
4: 'flowering',
5: 'fruiting',
2017-03-06 23:20:31 +00:00
}
color_dict = {
0: 'red',
1: 'orange',
2: 'yellow',
3: 'green',
4: 'blue',
5: 'indigo',
6: 'violet',
7: 'white',
8: 'black',
9: 'gold',
10: 'rainbow',
}
rarity_dict = {
0: 'common',
1: 'uncommon',
2: 'rare',
3: 'legendary',
4: 'godly',
}
species_dict = {
0: 'poppy',
1: 'cactus',
2: 'aloe',
3: 'venus flytrap',
2017-03-07 00:57:11 +00:00
4: 'jade plant',
2017-03-06 23:20:31 +00:00
5: 'fern',
2017-03-06 23:29:23 +00:00
6: 'daffodil',
2017-03-06 23:20:31 +00:00
}
mutation_dict = {
0: '',
1: 'humming',
2: 'noxious',
3: 'vorpal',
2017-03-06 23:29:23 +00:00
4: 'glowing',
5: 'electric',
2017-03-07 00:57:11 +00:00
6: 'icy',
2017-03-06 23:29:23 +00:00
7: 'flaming',
8: 'psychic',
2017-03-07 00:57:11 +00:00
9: 'screaming',
10: 'chaos',
11: 'hissing',
12: 'gelatinous',
13: 'deformed',
14: 'shaggy',
15: 'scaly',
16: 'depressed',
17: 'anxious',
18: 'metallic',
19: 'glossy',
2017-03-06 23:20:31 +00:00
}
2017-03-06 21:38:31 +00:00
def __init__(self):
self.stage = 0
self.mutation = 0
2017-03-06 23:20:31 +00:00
self.species = random.randint(0,len(self.species_dict)-1)
2017-03-07 00:57:11 +00:00
self.color = random.randint(0,len(self.color_dict)-1)
2017-03-06 21:38:31 +00:00
self.rarity = self.rarity_check()
2017-03-07 00:57:11 +00:00
self.ticks = 0
2017-03-06 21:38:31 +00:00
def rarity_check(self):
2017-03-06 22:22:13 +00:00
CONST_RARITY_MAX = 256.0
rare_seed = random.randint(1,CONST_RARITY_MAX)
common_range = round((2/3)*CONST_RARITY_MAX)
uncommon_range = round((2/3)*(CONST_RARITY_MAX-common_range))
rare_range = round((2/3)*(CONST_RARITY_MAX-common_range-uncommon_range))
legendary_range = round((2/3)*(CONST_RARITY_MAX-common_range-uncommon_range-rare_range))
godly_range = round((2/3)*(CONST_RARITY_MAX-common_range-uncommon_range-rare_range-legendary_range))
# print common_range, uncommon_range, rare_range, legendary_range, godly_range
common_max = common_range
uncommon_max = common_max + uncommon_range
rare_max = uncommon_max + rare_range
legendary_max = rare_max + legendary_range
godly_max = legendary_max + godly_range
# print common_max, uncommon_max, rare_max, legendary_max, godly_max
if 0 <= rare_seed <= common_max:
2017-03-06 21:38:31 +00:00
rarity = 0
2017-03-06 22:22:13 +00:00
elif common_max < rare_seed <= uncommon_max:
2017-03-06 21:38:31 +00:00
rarity = 1
2017-03-06 22:22:13 +00:00
elif uncommon_max < rare_seed <= rare_max:
2017-03-06 21:38:31 +00:00
rarity = 2
2017-03-06 22:22:13 +00:00
elif rare_max < rare_seed <= legendary_max:
2017-03-06 21:38:31 +00:00
rarity = 3
2017-03-06 22:22:13 +00:00
elif legendary_max < rare_seed <= CONST_RARITY_MAX:
2017-03-06 21:38:31 +00:00
rarity = 4
return rarity
def growth(self):
2017-03-07 00:57:11 +00:00
if self.stage < (len(self.stage_dict)-1):
2017-03-06 21:38:31 +00:00
self.stage += 1
# do stage growth stuff
2017-03-06 23:20:31 +00:00
CONST_MUTATION_RARITY = 9 # Increase this # to make mutation rarer (chance 1 out of x)
2017-03-06 22:22:13 +00:00
mutation_seed = random.randint(0,CONST_MUTATION_RARITY)
if mutation_seed == CONST_MUTATION_RARITY:
2017-03-06 23:20:31 +00:00
mutation = random.randint(0,len(self.mutation_dict)-1)
2017-03-06 21:38:31 +00:00
if self.mutation == 0:
self.mutation = mutation
else:
# do stage 5 stuff (after fruiting)
1==1
def parse_plant(self):
if self.mutation == 0:
2017-03-06 23:20:31 +00:00
print self.rarity_dict[self.rarity] +" "+ self.color_dict[self.color] +" "+ self.stage_dict[self.stage] +" "+ self.species_dict[self.species]
2017-03-06 21:38:31 +00:00
else:
2017-03-06 23:20:31 +00:00
print self.rarity_dict[self.rarity] +" "+ self.mutation_dict[self.mutation] +" "+ self.color_dict[self.color] +" "+ self.stage_dict[self.stage] +" "+ self.species_dict[self.species]
2017-03-06 21:38:31 +00:00
2017-03-07 00:57:11 +00:00
def live(self):
# I've created life :)
# life_stages = (5, 15, 30, 45, 60)
life_stages = (5, 10, 15, 20, 25)
self.parse_plant()
2017-03-07 01:56:11 +00:00
# while self.ticks <= 100:
# time.sleep(1)
# self.ticks += 1
# # print self.ticks
# if self.stage < len(self.stage_dict)-1:
# if self.ticks == life_stages[self.stage]:
# self.growth()
# self.parse_plant()
## DEBUG:
while my_plant.stage < len(my_plant.stage_dict)-1:
raw_input("...")
my_plant.growth()
my_plant.parse_plant()
class DataManager(object):
def __init__(self):
self.this_user = getpass.getuser()
self.savefile_name = self.this_user + '_plant.dat'
def check_plant(self):
if os.path.isfile(self.savefile_name):
print "found savefile!"
return True
else:
print "no savefile found"
return False
def save_plant(self, this_plant):
with open(self.savefile_name, 'wb') as f:
pickle.dump(this_plant, f, protocol=2)
def load_plant(self):
with open(self.savefile_name, 'rb') as f:
this_plant = pickle.load(f)
return this_plant
def data_write_json(self, this_plant):
json_filename = self.this_user + '_plant_data.json'
with open(json_filename, 'w') as outfile:
json.dump(this_plant.__dict__, outfile)
2017-03-07 00:57:11 +00:00
2017-03-06 21:38:31 +00:00
if __name__ == '__main__':
2017-03-07 01:56:11 +00:00
my_data = DataManager()
# if plant save file does not exist
if my_data.check_plant():
my_plant = my_data.load_plant()
# otherwise create new plant
else:
my_plant = Plant()
2017-03-06 23:20:31 +00:00
print my_plant.stage, my_plant.species, my_plant.color, my_plant.rarity, my_plant.mutation
2017-03-07 00:57:11 +00:00
my_plant.live()
2017-03-07 01:56:11 +00:00
my_data.save_plant(my_plant)
my_data.data_write_json(my_plant)
2017-03-06 21:38:31 +00:00
print "end"