Skip to content

Instantly share code, notes, and snippets.

@Gwith
Created October 30, 2017 22:18
Show Gist options
  • Save Gwith/3221ad4f2af340569f6e14dc7f8460fc to your computer and use it in GitHub Desktop.
Save Gwith/3221ad4f2af340569f6e14dc7f8460fc to your computer and use it in GitHub Desktop.
from dialogue_menus import *
from rooms import *
courtyard = Room(
'This is a courtyard',
{'North':'Entrance'},
['item1', 'item2'],
['monster1', 'monster2']
)
entrance = Room(
'This is the entrance',
{'North':'Corridor', 'South':'Courtyard'},
['item1', 'item2'],
['monster1', 'monster2']
)
corridor = Room(
'This is corridor',
{'South':'Entrance'},
['item1', 'item2'],
['monster1', 'monster2']
)
all_rooms = {
'Entrance': entrance,
'Corridor': corridor,
'Courtyard': courtyard
}
def play():
current_room = all_rooms['Courtyard']
game_running = True
while game_running:
direction = current_room.interact()
current_room = all_rooms[direction]
if __name__ == "__main__":
code = play()
sys.exit(code)
class Room:
def __init__(self, description, directions, items, monsters):
self.description = description
self.directions = directions
self.items = items
self.monsters = monsters
def __repr__(self):
return "{}\n{}".format(self.description, self.directions)
def interact(self):
direction_items = list(self.directions.items())
for index, (key, value) in enumerate(direction_items, 1):
print(index, key)
direction = int(input('Select a direction to go.\n>>>'))
for index, (key, value) in enumerate(direction_items, 1):
if index == direction:
return value
#assert 1 <= new_direction <= len(direction_items)
# return direction_items[new_direction - 1][1] # -1 since we enumerate from 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment