Last active
May 1, 2020 01:18
-
-
Save dasm/7046721 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
world = { | |
'mesa': { | |
'name': 'Mesa', | |
'items': [], | |
'description': """People are going crazy. They are turning into | |
zombies. You need to save yourself. Look for Escape Pod.""", | |
'exits': ['toilet', 'kitchen', 'dumpster', 'corridor'], | |
}, | |
'toilet': { | |
'name': 'Toilet', | |
'items': [], | |
'description': 'You can wash your hands from blood.', | |
'exits': ['mesa'], | |
}, | |
'corridor': { | |
'name': 'Corridor', | |
'items': [], | |
'description': """You see a light! There is a hope. At the end of | |
corridor you see an escape pod.""", | |
'exits': ['mesa', 'escape'], | |
}, | |
'kitchen': { | |
'name': 'Kitchen', | |
'items': ['knife'], | |
'description': 'There are various kitchen utilities here. Including a row of very big knifes.', | |
'exits': ['mesa', 'dumpster'], | |
}, | |
'dumpster': { | |
'name': 'Dumpster', | |
'items': [], | |
'description': 'It stinks here. You might be hungry... but you\'re not.', | |
'exits': [], | |
}, | |
'escape': { | |
'name': 'Escape pod', | |
'items': [], | |
'description': 'Escape doesn\'t work. You died!', | |
'exits': [] | |
}, | |
} | |
def main(): | |
print """ | |
You wake up on Space Ship. You're hungry. You're going to mesa, to eat something. | |
""" | |
starting_room = world['mesa'] | |
current = Room('mesa', starting_room) | |
has_knife = False | |
while True: | |
print '' | |
current.print_description() | |
current.print_exits() | |
if current.items and not has_knife: | |
print "You picked a knife!" | |
has_knife = True | |
room_name = raw_input('Where to go: ') | |
current = next_room(current, room_name.lower()) | |
if current.key == 'corridor' and not has_knife: | |
print "\nWatch out! Zombies ahead of you! You moved back to mesa" | |
current = Room('mesa', starting_room) | |
if current.key == 'corridor' and has_knife: | |
print "You killed a zombie." | |
class Room(object): | |
def __init__(self, key, data): | |
self.key = key | |
self.name = data['name'] | |
self.description = data['description'] | |
self.exits = data['exits'] | |
self.items = data['items'] | |
def print_description(self): | |
print "You're in {}. {}".format(self.name, self.description) | |
def print_exits(self): | |
if not self.exits: | |
print "You have died, slowly and painfully" | |
sys.exit() | |
print 'Exits are: ', ', '.join(self.exits) | |
def next_room(current, room_name): | |
if room_name not in current.exits: | |
print "No such room" | |
return current | |
data = world.get(room_name) | |
return Room(room_name, data) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment