hello, i'm new to this website and well only have a few months of python exp. i decided to make a small, simple rather easy if HUMOR game. When is started, i did not know a whole lot other than how to make lists and scenes and make a way to get "a key" to "open doors" and hiding them under "lamps, beds, etc." I know a bit more from studying other peoples code. so here it is(Note it says version 2.0 because i this one has some slight "modifications" made to it, if you want, i could post version 1.0) :
# Title: All out of Cheese burgers, Version 2.0
# Genre: Humor/Text Adventure
# Date: November 16, 2009
import textwrap
import sys
# Intro text:
scenes = {
"The Harry Hamburger": {
"description": "You are standing in a long line at the register. To the NORTH of you is the order window, " \
"to the EAST of you is the kitchen, to the WEST of you is the MASCOT, and to the " \
"the SOUTH of you is the walk-in freezer.",
"paths": [
{ "go_to": "order window", "phrase": "Go north to the order window" },
{ "go_to": "kitchen", "phrase": "Go east to the kitchen" },
{ "go_to": "MASCOT", "phrase": "Go south to the MASCOT" },
{ "go_to": "walkin freezer", "phrase": "Go west to the walk-in freezer" }
]
},
"walkin freezer": {
"description": "You are standing at the door of the walk in freezer, which is locked. " \
"You'll need to find a way to open it. Perhaps a key is somewhere in the restraunt.",
"paths": [
{ "go_to": "kitchen", "phrase": "Go east to the kitchen" },
{ "go_to": "MASCOT", "phrase": "Go north to the mascot" }
]
},
"order window": {
"description": "You finally reach the order window at last. The fast food clerk " \
"tells you that they are all out of cheese burgers. None of the other " \
"items on the menu interest you. You leave the building in disappointment.",
"paths": [ ]
},
"kitchen": {
"description": "Sneaking in to the kitchen, you can't believe your eyes. Melted cheese on top of " \
"of sesame seed buns fill your nostrils and you almost could began to drool. You want to " \
"avoid detection as your goal is the walk-in freezer so you refrain from stealing anything.",
"paths": [
{ "go_to": "MASCOT", "phrase": "Go west to the MASCOT" }
]
},
"MASCOT": {
"description": "The Harry Hamburger mascot stands off to the side of the order window and is handing " \
"out free coupons to passer bys and on his side is a key. You quickly grab his key before anyone notices " \
"and you than go to the locked door and open the walk-in freezer. CONGRATS, YOU WIN!",
"paths": [ ]
}
}
scene = scenes["The Harry Hamburger"]
while 1 == 1:
next_step = None
description = scene["description"]
paths = scene["paths"]
print textwrap.fill(description)
for i in range(0, len(paths)):
path = paths[i]
menu_item = i + 1
print "\t", menu_item, path["phrase"]
print "\t(0 Quit)"
prompt = "Make a selection (0 - %i): " % len(paths)
while next_step == None:
try:
choice = raw_input(prompt)
menu_selection = int(choice)
if menu_selection == 0:
next_step = "quit"
else:
index = menu_selection - 1
next_step = paths[ index ]
except (IndexError, ValueError):
print choice, "Unknown Command!"
if next_step == "quit":
print "I hope you had fun, Bye!"
sys.exit()
else:
scene = scenes[next_step['go_to'] ]
print "You decided to:", next_step["phrase"]