Plant only grows when it has been watered :)
parent
c26db83caa
commit
c32a18b157
90
botany.py
90
botany.py
|
@ -24,7 +24,6 @@ from menu_screen import *
|
||||||
# - how long should each stage last ? thinking realistic lmao
|
# - how long should each stage last ? thinking realistic lmao
|
||||||
|
|
||||||
# interaction
|
# interaction
|
||||||
# - watering?
|
|
||||||
# - look at plant, how do you feel? (also gets rid of pests)
|
# - look at plant, how do you feel? (also gets rid of pests)
|
||||||
#
|
#
|
||||||
# if >5 days with no water, plant dies
|
# if >5 days with no water, plant dies
|
||||||
|
@ -33,6 +32,7 @@ from menu_screen import *
|
||||||
# - rain
|
# - rain
|
||||||
# - bugs
|
# - bugs
|
||||||
#
|
#
|
||||||
|
# build multiplayer
|
||||||
# neighborhood system
|
# neighborhood system
|
||||||
# - create plant id (sort of like userid)
|
# - create plant id (sort of like userid)
|
||||||
# - list sorted by plantid that wraps so everybody has 2 neighbors :)
|
# - list sorted by plantid that wraps so everybody has 2 neighbors :)
|
||||||
|
@ -44,13 +44,8 @@ from menu_screen import *
|
||||||
# garden system
|
# garden system
|
||||||
# - can plant your plant in the garden to start a new plant
|
# - can plant your plant in the garden to start a new plant
|
||||||
|
|
||||||
# build time system
|
|
||||||
# build persistence across sessions
|
|
||||||
|
|
||||||
# build ascii trees
|
# build ascii trees
|
||||||
# build gui?
|
|
||||||
|
|
||||||
# build multiplayer
|
|
||||||
|
|
||||||
# def display_update:
|
# def display_update:
|
||||||
# myscreen = curses.initscr()
|
# myscreen = curses.initscr()
|
||||||
|
@ -77,7 +72,7 @@ class Plant(object):
|
||||||
2: 'young',
|
2: 'young',
|
||||||
3: 'mature',
|
3: 'mature',
|
||||||
4: 'flowering',
|
4: 'flowering',
|
||||||
5: 'fruiting',
|
5: 'seed-bearing',
|
||||||
}
|
}
|
||||||
|
|
||||||
color_dict = {
|
color_dict = {
|
||||||
|
@ -110,6 +105,9 @@ class Plant(object):
|
||||||
4: 'jade plant',
|
4: 'jade plant',
|
||||||
5: 'fern',
|
5: 'fern',
|
||||||
6: 'daffodil',
|
6: 'daffodil',
|
||||||
|
7: 'sunflower',
|
||||||
|
8: 'baobab',
|
||||||
|
9: 'lithops',
|
||||||
}
|
}
|
||||||
|
|
||||||
mutation_dict = {
|
mutation_dict = {
|
||||||
|
@ -123,7 +121,7 @@ class Plant(object):
|
||||||
7: 'flaming',
|
7: 'flaming',
|
||||||
8: 'psychic',
|
8: 'psychic',
|
||||||
9: 'screaming',
|
9: 'screaming',
|
||||||
10: 'chaos',
|
10: 'chaotic',
|
||||||
11: 'hissing',
|
11: 'hissing',
|
||||||
12: 'gelatinous',
|
12: 'gelatinous',
|
||||||
13: 'deformed',
|
13: 'deformed',
|
||||||
|
@ -143,7 +141,9 @@ 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.age_formatted = "0"
|
||||||
self.dead = False
|
self.dead = False
|
||||||
|
self.owner = getpass.getuser()
|
||||||
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())
|
||||||
|
@ -151,6 +151,7 @@ class Plant(object):
|
||||||
self.watered_timestamp = int(time.time())-(24*3601)
|
self.watered_timestamp = int(time.time())-(24*3601)
|
||||||
# self.watered_timestamp = int(time.time()) # debug
|
# self.watered_timestamp = int(time.time()) # debug
|
||||||
self.watered_times = 0
|
self.watered_times = 0
|
||||||
|
self.watered_24h = False
|
||||||
|
|
||||||
def rarity_check(self):
|
def rarity_check(self):
|
||||||
# Generate plant rarity
|
# Generate plant rarity
|
||||||
|
@ -197,9 +198,20 @@ class Plant(object):
|
||||||
# TODO: overwatering? if more than once a day it dies?
|
# TODO: overwatering? if more than once a day it dies?
|
||||||
if not self.dead:
|
if not self.dead:
|
||||||
self.watered_timestamp = int(time.time())
|
self.watered_timestamp = int(time.time())
|
||||||
|
#TODO: this should only be allowed once a day
|
||||||
self.watered_times += 1
|
self.watered_times += 1
|
||||||
|
self.watered_24h = True
|
||||||
|
|
||||||
|
def convert_seconds(self,seconds):
|
||||||
|
days, seconds = divmod(seconds, 24 * 60 * 60)
|
||||||
|
hours, seconds = divmod(seconds, 60 * 60)
|
||||||
|
minutes, seconds = divmod(seconds, 60)
|
||||||
|
return days, hours, minutes, seconds
|
||||||
|
|
||||||
def dead_check(self):
|
def dead_check(self):
|
||||||
|
# also updates age
|
||||||
|
d,h,m,s = self.convert_seconds(self.ticks)
|
||||||
|
self.age_formatted = ("%dd:%dh:%dm:%ds" % (d, h, m, s))
|
||||||
time_delta_watered = int(time.time()) - self.watered_timestamp
|
time_delta_watered = int(time.time()) - self.watered_timestamp
|
||||||
# if it has been >5 days since watering, sorry plant is dead :(
|
# if it has been >5 days since watering, sorry plant is dead :(
|
||||||
# if time_delta_watered > 5: #debug
|
# if time_delta_watered > 5: #debug
|
||||||
|
@ -207,6 +219,16 @@ class Plant(object):
|
||||||
self.dead = True
|
self.dead = True
|
||||||
return self.dead
|
return self.dead
|
||||||
|
|
||||||
|
def water_check(self):
|
||||||
|
# if plant has been watered in 24h then it keeps growing
|
||||||
|
# time_delta_watered is difference from now to last watered
|
||||||
|
self.time_delta_watered = int(time.time()) - self.watered_timestamp
|
||||||
|
if self.time_delta_watered <= (24 * 3600):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
self.watered_24h = False
|
||||||
|
return False
|
||||||
|
|
||||||
def mutate_check(self):
|
def mutate_check(self):
|
||||||
# Create plant mutation
|
# Create plant mutation
|
||||||
# TODO: when out of debug this needs to be set to high number (1000
|
# TODO: when out of debug this needs to be set to high number (1000
|
||||||
|
@ -227,7 +249,8 @@ class Plant(object):
|
||||||
# reads plant info (maybe want to reorg this into a different class
|
# reads plant info (maybe want to reorg this into a different class
|
||||||
# with the reader dicts...)
|
# with the reader dicts...)
|
||||||
output = ""
|
output = ""
|
||||||
output += self.rarity_dict[self.rarity] + " "
|
if self.stage >= 3:
|
||||||
|
output += self.rarity_dict[self.rarity] + " "
|
||||||
if self.mutation != 0:
|
if self.mutation != 0:
|
||||||
output += self.mutation_dict[self.mutation] + " "
|
output += self.mutation_dict[self.mutation] + " "
|
||||||
if self.stage >= 4:
|
if self.stage >= 4:
|
||||||
|
@ -248,31 +271,24 @@ class Plant(object):
|
||||||
# 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)
|
||||||
day = 3600*24
|
# day = 3600*24
|
||||||
# life_stages = (1*day, 2*day, 3*day, 4*day, 5*day)
|
# life_stages = (1*day, 2*day, 3*day, 4*day, 5*day)
|
||||||
# life_stages = (1, 2, 3, 4, 5)
|
|
||||||
# leave this untouched bc it works for now
|
# leave this untouched bc it works for now
|
||||||
while not self.dead:
|
while (not self.dead):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
self.ticks += 1
|
if self.watered_24h:
|
||||||
# print self.ticks
|
self.ticks += 1
|
||||||
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():
|
||||||
1==1
|
1==1
|
||||||
if self.dead_check():
|
if self.dead_check():
|
||||||
1==1
|
1==1
|
||||||
#print self.parse_plant()
|
if self.water_check():
|
||||||
|
1==1
|
||||||
# what kills the plant?
|
# TODO: event check
|
||||||
|
|
||||||
## DEBUG:
|
|
||||||
# while my_plant.stage < len(my_plant.stage_dict)-1:
|
|
||||||
# raw_input("...")
|
|
||||||
# my_plant.growth()
|
|
||||||
# my_plant.parse_plant()
|
|
||||||
|
|
||||||
class DataManager(object):
|
class DataManager(object):
|
||||||
# handles user data, puts a .botany dir in user's home dir (OSX/Linux)
|
# handles user data, puts a .botany dir in user's home dir (OSX/Linux)
|
||||||
|
@ -312,19 +328,21 @@ class DataManager(object):
|
||||||
# need to calculate lifetime ticks to determine stage of life
|
# 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
|
# compare timestamp of signout to timestamp now
|
||||||
time_delta_last = current_timestamp - this_plant.last_time
|
|
||||||
is_dead = this_plant.dead_check()
|
is_dead = this_plant.dead_check()
|
||||||
|
is_watered = this_plant.water_check()
|
||||||
|
|
||||||
# if it has been >5 days since watering, sorry plant is dead :(
|
# if it has been >5 days since watering, sorry plant is dead :(
|
||||||
if not is_dead:
|
if not is_dead:
|
||||||
this_plant.ticks += time_delta_last
|
if is_watered:
|
||||||
|
#need to use time AWAY (i.e. this_plant.last_time)
|
||||||
|
time_delta_last = int(time.time()) - this_plant.last_time
|
||||||
|
ticks_to_add = min(time_delta_last, 24*3600)
|
||||||
|
this_plant.time_delta_watered = 0
|
||||||
|
self.last_water_gain = time.time()
|
||||||
|
else:
|
||||||
|
ticks_to_add = 0
|
||||||
|
this_plant.ticks += ticks_to_add
|
||||||
|
|
||||||
return this_plant
|
return this_plant
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,6 @@ class CursedMenu(object):
|
||||||
options.append('Exit')
|
options.append('Exit')
|
||||||
self.options = options
|
self.options = options
|
||||||
|
|
||||||
|
|
||||||
def draw_menu(self):
|
def draw_menu(self):
|
||||||
'''Actually draws the menu and handles branching'''
|
'''Actually draws the menu and handles branching'''
|
||||||
request = ""
|
request = ""
|
||||||
|
@ -133,9 +132,10 @@ class CursedMenu(object):
|
||||||
if not self.instructiontoggle:
|
if not self.instructiontoggle:
|
||||||
instructions_txt = """welcome to botany. you've been given a seed
|
instructions_txt = """welcome to botany. you've been given a seed
|
||||||
that will grow into a beautiful plant. check
|
that will grow into a beautiful plant. check
|
||||||
in and water your plant every day to keep it
|
in and water your plant every 24h to keep it
|
||||||
alive. it depends on you to live! More info
|
growing. 5 Days without water = death. Your
|
||||||
is available in the readme :)
|
plant depends on you to live! More info is
|
||||||
|
available in the readme :)
|
||||||
cheers,
|
cheers,
|
||||||
curio"""
|
curio"""
|
||||||
self.instructiontoggle = not self.instructiontoggle
|
self.instructiontoggle = not self.instructiontoggle
|
||||||
|
@ -146,6 +146,7 @@ is available in the readme :)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# TODO:
|
# TODO:
|
||||||
self.instructiontoggle = not self.instructiontoggle
|
self.instructiontoggle = not self.instructiontoggle
|
||||||
|
|
Loading…
Reference in New Issue