I'm writing a little text based adventure game, and wanted to know if there's anything I can do better thus far. It is not completed to don't get mad when it ends. I'm just curious as to better ways to write the syntax, or different ways to do things.
from random import randint
BACKPACK = {} # What you will bring with you on your journey
SURVIVAL_TOOLS = {} # What you collect over the course of your journey
def create_player():
"""
Create your character name
"""
player_name = raw_input('Enter your characters name: ').capitalize()
return player_name
def formatter(width=50):
"""
Formatting for to keep everything all pretty
:type width: Integer
"""
return '*' * width
def die(why):
"""
Kill off the program becasue you did something stupid
:type why: String
"""
return "{}. You slowly fade into darkness. Game over.".format(why)
def gather_gear(player):
"""
Gather your gear from a set list of items you have available
:type player: String
"""
print formatter()
print "{}! Shouts Jack as he runs towards you." \
" Do you wanna go Hiking this weekend?" \
" You ponder this for a second." \
" What the hell, you think." \
" Can't be any worse then last time." \
" Sure, Jack! You say enthusiastically." \
" Just let me get some things prepared.".format(player)
options = { # All the items that are available to you before you leave
'fire starter': 1,
'matches': randint(1, 5), # Uses random integers as the value
'flash light': 1,
'sleeping bag': 1,
'canteen cup': 1,
'dried foods': randint(1, 6),
'shovel': 1,
'knife': 1
}
for key in options:
print "You have {} {}".format(options[key], key) # Print out all your items and make it look pretty
print "\n"
count = 3
num_in_pack = 0
while count != 0:
item = raw_input("What would you like to take? Choose {} items one at a time: ".format(str(count))).lower()
if item in options and item not in BACKPACK: # As long as the item is available you can use it
BACKPACK[item] = options[item] # Add the item value to your backpack constant
count -= 1
print "You throw a {} in your backpack".format(item)
num_in_pack += 1
if num_in_pack == 3: # If you have three items, lets begin!
print "Your backpack is now full."
start_adventure(player)
else:
print "Can't bring that item."
return BACKPACK
def start_adventure(player):
"""Start your adventure, you start out hiking and then someone dies
you freak out because your a wuss and run away like a little girl.
:type player: String
"""
print formatter() # Pretty formatting
print "You head out to your location." \
" On your way there you and Jack" \
" talk about your lives until you" \
" finally pull in to the trail." \
" You look at the map and notice there's" \
" an emergency number. " \
' "Jack" you say "Should we take down this number?"' \
' "Don\'t be such a baby {}" says Jack laughing' \
" You start walking the trail and come to a clearing." \
" When suddenly there's a loud growl, you turn around" \
" and see a mountain lion jump on Jack," \
" Jack starts screaming as the lion rips his throat out." \
" You begin to run, you hear Jack's screams fading away" \
" in the distance. You run for what seems like an hour" \
" and realize you have no idea where you are." \
" You lean against a trunk and think about what just" \
" happened. You have limited options.\n".format(player) # Well that escalated quickly O.O
options = ['Start a fire', 'Cry', 'Find food', 'Build a shelter']
print "Options are:"
for opt in options:
print "{}".format(opt) # Print out your possible options at this point
print "\n"
choice = raw_input('What do you want to do: ').capitalize()
def welcome_screen():
"""
Main program method, where all the magic happens
"""
player_name = create_player()
print "\nWelcome to the survival game {}.\n".format(player_name)
message = """The object of this game is fairly simple. Survive.
You will be given a set number of items to survive
with. Remember, small mistakes in the wilderness
can be the difference between life and death.
Are you ready to begin, {} [Y/N]?""".format(player_name)
print formatter()
print message
begin = raw_input()
if begin == 'y' or 'Y':
gather_gear(player_name)
elif begin == 'n' or 'N':
print 'Exiting game..'
else:
print "{} is not an option. try again.."
if __name__ == '__main__':
welcome_screen()