Thanks! I have the not-so-sneaking suspicion that the code could have been about half as long if I knew a little more.
For example, the prompts for every room are similar, but not the same. Anyone have any idea how I could have made a "prompt" class?
For example
First room:
Leogas' bedroom
def bedroom():
global leogasHp
print "Health: ", leogasHp
if leogasLeftBedroom == 0:
bed_Desc1()
else:
bed_Desc2()
# If you haven't left the room yet, this description will trigger
def bed_Desc1():
print "You are standing in your own bedroom. In the corner is a preposterously"
print "large, opulent four-poster bed. Empty wine bottles litter the floor and"
print "the top of the dresser. Discarded clothing lays strewn about the rich"
print "quarters. A faint, directionless light permeates the room."
print "You see exits leading (E)ast, (W)est and (S)outh."
print "Type 'help' for a list of commands."
print
prompt_bed()
# If you've already left the room, and are coming back, this description will trigger
def bed_Desc2():
print "You are standing in your own bedroom. While you were out, it seems the"
print "servants have inconspicuosly tidied up. Your bed was painstakingly made, "
print "and the floors and surfaces are free of clutter. Seems the maids aren't perfect,"
print "however, as one last bottle lays half-hidden beneath the bed. A faint,"
print "directionless light permeates the room."
print "You see exits leading (E)ast, (W)est and (S)outh."
print "Type 'help' for a list of commands."
print
prompt_bed()
#prompt for bedroom
def prompt_bed():
global leogasLeftBedroom
global inventory
prompt_b = raw_input("Your orders, my liege? ").lower()
try:
if prompt_b == "e":
leogasLeftBedroom = 1
library()
elif prompt_b == "w":
leogasLeftBedroom = 1
guardroom()
elif prompt_b == "s":
leogasLeftBedroom = 1
fungalGarden()
elif prompt_b == "help":
help1()
prompt_bed()
elif prompt_b == "look":
if leogasLeftBedroom == 0:
bed_Desc1()
else:
bed_Desc2()
elif prompt_b == "ex bed":
if leogasLeftBedroom == 0:
print "Your bed is a gigantic mess of slept-in silks and satins. Is that a"
print "splash of vomit you see on the brocade pillows?"
else:
print "Your voluminous bed, with its carved mahogany posts, has been"
print "meticulously made."
print
prompt_bed()
#You get a potion later. This ensures you can drink it while in the bedroom.
elif prompt_b == "drink potion" or prompt_b == "drink healing potion":
if "a healing potion" in inventory:
if leogasHp < 35:
leogasHp = 35
print "You've been healed! Your health is now ", leogasHp
inventory.remove("a healing potion")
else:
print "You really ought to save that for when it counts."
print
prompt_bed()
else:
print "You don't have a healing potion."
print
prompt_bed()
elif prompt_b == "ex clothes":
if leogasLeftBedroom == 0:
print "Your fine clothes lay rumpled in scattered heaps across the room. They"
print "smell like pipe smoke and are splotched with stains."
else:
print "Your clothes are hanging neatly in the closet."
print
prompt_bed()
elif prompt_b == "ex bottles" or prompt_b == "ex bottle" or prompt_b == "ex wine":
if leogasLeftBedroom == 0:
print "Countless wine bottles of every shape and size lay around the room."
print "Their emptiness is the only thing they have in common."
else:
print "The maids cleaned out all the bottles, except one, which you see poking"
print "out from beneath the bed."
print
prompt_bed()
elif prompt_b == "take bottles" or prompt_b == "take bottle" or prompt_b == "take wine":
if "an empty wine bottle" in inventory:
print "You're already carrying a wine bottle."
else:
print "You snatch up an empty bottle. Its pleasing heft comforts you."
inventory += ["an empty wine bottle"]
print "Your inventory now contains: "
for item in inventory:
print item
print
prompt_bed()
elif prompt_b == "take bed":
print "It's much too heavy, and anyway, you're in a weakened state."
print
prompt_bed()
elif prompt_b == "ex dresser":
print "This stunning dresser features ironwork handles and a stunning walnut finish."
print
prompt_bed()
elif prompt_b == "open dresser":
print "It's full of dresses. Always wondered why they called it that."
print
prompt_bed()
elif prompt_b == "take dresser":
print "An adventurous spirit is appreciated, but c'mon."
print
prompt_bed()
elif prompt_b == "take dresses":
print "Oh, how the servants would talk."
print
prompt_bed()
elif prompt_b == "take clothes":
print "You ought to wait until the Clean Clothes Fairy comes and washes them, don't"
print "you think?"
print
prompt_bed()
elif prompt_b == "ex pillow" or prompt_b == "ex pillows":
print "The pillows are crafted from the finest red velvet and exquisite brocade."
print "They smell of last night's dinner."
print
prompt_bed()
elif prompt_b == "take pillow" or prompt_b == "take pillows":
print "Pillow fights are for sissies. Or for sultry bar wenches in lingerie."
print "You are neither."
print
prompt_bed()
elif prompt_b == "i":
print "Your inventory contains: "
for item in inventory:
print item
print
prompt_bed()
#you get a spotted mushroom later in the game. If you eat it at any time, you die. This ensures you can eat it in the bedroom.
elif prompt_b == "eat mushroom" or prompt_b == "eat mushrooms":
if "a spotted mushroom" in inventory:
print "Colors and lights start to swirl before your eyes. You feel a portal"
print "to another world opening."
die()
else:
print "You don't have a spotted mushroom."
print
prompt_bed()
elif prompt_b == "q":
quit()
else:
print "Pardon, my lord, I'm sure I don't know what you mean."
print
prompt_bed()
except ValueError:
print "Pardon, my lord, I'm sure I don't know what you mean."
print
prompt_bed()
Third room:
# If you haven't opened the secret door, this description will trigger
def lib_Desc1():
print "You are standing in the library."
print "An unusual, carved bookshelf packed full of musty tomes is set into the"
print "northern wall. Fyrglyss lanterns, hung about at strategic locations, fill"
print "the room with an unearthly glow."
print "You see a single exit leading (W)est."
print "Type 'help' for a list of commands."
print
prompt_lib()
# If you have opened the secret door, this description will trigger
def lib_Desc2():
print "You are standing in the library."
print "Before you stands a darkened doorway to outside."
print "Fyrglyss lanterns, hung about at strategic locations, fill the room with"
print "an unearthly glow."
print "You see exits leading (W)est and (In)."
print "Type 'help' for a list of commands."
print
prompt_lib()
# The library prompt
def prompt_lib():
global inventory
global gotLantern
global bookOnShelf
prompt_l = raw_input("Your orders, my liege? ").lower()
try:
if prompt_l == "w":
bedroom()
if prompt_l == "in":
if bookOnShelf == 1:
chamber()
else:
print "I'm sorry, my lord, I'm sure I don't know what you mean."
print
prompt_lib()
elif prompt_l == "help":
help1()
prompt_lib()
elif prompt_l == "i":
print "Your inventory contains: "
for item in inventory:
print item
print
prompt_lib()
elif prompt_l == "look":
if bookOnShelf == 0:
lib_Desc1()
else:
lib_Desc2()
elif prompt_l == "ex shelf" or prompt_l == "ex bookshelf" or prompt_l == "ex shelves" or prompt_l == "ex bookshelves":
print "These old bookshelves contain all manner of volumes. You see your diary"
print "and an atlas among the rest of the arcane texts. You notice that there's"
print "an empty space where a book seems to be missing."
print
prompt_lib()
elif prompt_l == "ex diary":
print "'Dear Diary: Got drunk. Dear Diary: Got drunker.'"
print
prompt_lib()
elif prompt_l == "take diary":
print "Ugh, no thanks. Too depressing."
print
prompt_lib()
elif prompt_l == "ex atlas":
print "Maps of all the places you'll never see. Not if you stay locked up in"
print "here, at any rate."
print
prompt_lib()
elif prompt_l == "take atlas":
print "Maybe on the way out, when it'll be of some use."
print
prompt_lib()
elif prompt_l == "drink potion" or prompt_l == "drink healing potion":
if "a healing potion" in inventory:
if leogasHp < 35:
leogasHp = 35
print "You've been healed! Your health is now ", leogasHp
inventory.remove("a healing potion")
else:
print "You really ought to save that for when it counts."
print
prompt_lib()
else:
print "You don't have a healing potion."
print
prompt_lib()
elif prompt_l == "ex lantern" or prompt_l == "ex lanterns":
print "These shimmering lanterns sparkle with an ethereal glow."
print
prompt_lib()
elif prompt_l == "take lantern" or prompt_l == "take lanterns":
if "a fyrglyss lantern" in inventory:
print "You've already got a lantern."
else:
print "You take one of the lanterns down from its peg and hook it over your arm."
gotLantern = 1
inventory += ["a fyrglyss lantern"]
print "Your inventory now contains:"
for item in inventory:
print item
print
prompt_lib()
elif prompt_l == "ex space" or prompt_l == "ex empty space":
print "It's empty. There's nothing there. Totally blank. Full of zero. Packed with"
print "nada."
print
prompt_lib()
elif prompt_l == "take bookshelf" or prompt_l == "take shelf" or prompt_l == "take shelves" or prompt_l == "take bookshelves":
print "This is no time to re-arrange the furniture."
print
prompt_lib()
elif prompt_l == "put book on shelf" or prompt_l == "put book on bookshelf" or prompt_l == "put book on shelves" or prompt_l == "put strange book on shelf" or prompt_l == "put strange book on bookshelf" or prompt_l == "put strange book on shelves":
if "a strange book" in inventory:
print "You place the strange book in the empty space on the shelf."
bookOnShelf = 1
inventory.remove("a strange book")
print "Suddenly you hear a great rumbling as the bookshelf slides away."
print "Before you stands a darkened doorway and a flight of stairs leading down."
print "You can feel fresh air wafting in through the opening."
print "A way out!"
else:
print "You don't have a book in your possession."
print
prompt_lib()
elif prompt_l == "q":
quit()
#You can get a spotted mushroom later in the game. If you eat it at anytime, you die.
elif prompt_l == "eat mushroom" or prompt_l == "eat mushrooms":
if "a spotted mushroom" in inventory:
print "Colors and lights start to swirl before your eyes. You feel a portal"
print "to another world opening."
die()
else:
print "You don't have a spotted mushroom."
print
prompt_lib()
else:
print "Pardon, my lord, I'm sure I don't know what you mean."
print
prompt_lib()
except ValueError:
print "Pardon, my lord, I'm sure I don't know what you mean."
print
prompt_lib()
Can anyone help shorten this up? Alternate coding solutions welcome. I'm curious how else this could be done, since I only really know one way.