Skip to content

Instantly share code, notes, and snippets.

@kennethlove
Forked from CapnKernel/adventure.py
Last active December 16, 2015 03:59
Show Gist options
  • Save kennethlove/5373685 to your computer and use it in GitHub Desktop.
Save kennethlove/5373685 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
pages = {
"start": {
"text": "It's a dark night outside. Somewhere a wolf howls.",
"prompt": "Where will you take shelter, the haunted house, or the bat "
"cave?",
"next": ("haunted house", "bat cave"),
},
"haunted house": {
"text": "By the light of your flickering torch, you're able to make it"
" to\nthe haunted house. You find a candle and light it. You can"
" see\na winding staircase, and a hallway.",
"prompt": "Go upstairs, or into the hallway?",
"next": ("upstairs", "hallway"),
},
"upstairs": {
"text": "As you reach upstairs, something whooshes past you, knocking "
"out\nyour candle. Oh no, it's coming back again! You feel its "
"fur\nbrushing against your face. You wake in fright to find your"
" cat\nis on your bed, meowing at you. It was only a dream!",
},
"hallway": {
"text": "You move into the hallway, and trip over into an open coffin."
"The\ndoor slams shut. The haunted house has claimed another "
"victim!",
},
"bat cave": {
"text": "The rocks are very slippery here, too slippery. You're "
"unable to\nkeep your grip. The bats will feast well tonight!",
},
}
where = "start"
while True:
print
print pages[where]['text']
print
if not 'next' in pages[where]:
break
while True:
print "{0} ({1})?".format(
pages[where]['prompt'],
", ".join(pages[where]['next'])
)
to = raw_input()
if to in pages[where]['next']:
where = to
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment