Skip to content

Instantly share code, notes, and snippets.

@ods94065
Created March 2, 2016 00:33
Show Gist options
  • Save ods94065/876c15966235660d642e to your computer and use it in GitHub Desktop.
Save ods94065/876c15966235660d642e to your computer and use it in GitHub Desktop.
The Dark Tower of Delphi (Intro to CS Sample Project)
rooms = ['parking lot', 'trees', 'yacht', 'office building']
descriptions = [
"You are in a deserted parking lot. There's nothing parked\n"
"here besides your old, beat-up car. A crumpled piece of\n"
"foil lies in the gutter, suggesting that someone was eating\n"
"food here not too long ago. To your left, you can hear the\n"
"sound of a busy highway that you dare not cross on foot.\n"
"The property extends to your right across an empty street.",
"You stand on a lawn at the beginning a long row of tall\n"
"trees. The deposits of waterfowl dot the lawn, forcing you\n"
"to step carefully. A large pool beckons in front of you and\n"
"to the right. To the left there's a street and a parking\n"
"lot.",
"You stand at a monument to those who have gone before. An\n"
"enormous racing yacht, mounted on concrete pillars sunk\n"
"into the pool, tilts dramatically above you. A plaque on the\n"
"shore recounts the glory of one of the most improbable\n"
"victories in sailing history. To your left stretches a long\n"
"row of trees; to your right is a gleaming office tower.",
"You stand at the entrance to a large cylindrical office\n"
"building which climbs to the heavens. Nobody is present and\n"
"the doors to the lobby are locked. You hear something like\n"
"a faint sigh, but you can't tell where the sound is\n"
"coming from. To your left is a pond with a large racing\n"
"yacht in it."
]
current_room = 0
current_room_described = False
num_rooms = len(rooms)
print("Welcome to... The Dark Tower of Delphi!")
print()
print(
"You are a student at Miskatonic University, studying the\n"
"history of arcane technologies.\n\n"
"Recently you have been unable to sleep, waking in cold\n"
"sweats with a dread presence haunting your thoughts.\n"
"Your colleagues at the University diganose your symptoms\n"
"as the creeping madness associated with Delphi, a nearby\n"
"corporation which produces mysterious circular disks said\n"
"to contain uncanny ethereal power.\n\n"
"You laugh at the way your colleagues' hands tremble as they\n"
"describe Delphi, and dismiss their diganosis at first...\n"
"but after another sleepless night you find yourself driving\n"
"to Delphi, arriving there before dawn."
)
while True:
# Describe the room, if we haven't already
if not current_room_described:
assert(0 <= current_room < len(descriptions))
print()
print(descriptions[current_room])
current_room_described = True
# Figure out what commands are allowed
available_commands = ['help', 'look', 'quit']
if current_room > 0:
available_commands.append('left')
if current_room < num_rooms - 1:
available_commands.append('right')
# Get a command from the user
command = None
while not command:
print()
user_input = input('Your command? ')
if user_input not in available_commands:
print("You can't do that.")
else:
command = user_input
# Perform the command
if user_input == 'help':
print('Available commands: ')
i = 0
while i < len(available_commands):
print(available_commands[i])
i += 1
elif command == 'quit':
# Break out of the game loop!
break
elif command == 'look':
print()
print(descriptions[current_room])
current_room_described = True
elif command == 'left':
current_room -= 1
assert(0 <= current_room < num_rooms)
current_room_described = False
elif command == 'right':
current_room += 1
assert(0 <= current_room < num_rooms)
current_room_described = False
else:
raise RuntimeError('Unhandled command!')
# We're about to exit.
print()
print(
"You flee back to your car and drive away, your mind\n"
"reeling from what you have seen. As Delphi disappears\n"
"into the distance, you fervently pray that the madness of\n"
"Delphi will not consume you in the end..."
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment