Created
October 30, 2017 22:15
-
-
Save Gwith/b611ca03c7f5e2d2a7b3b86a9abd3f3d 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
import json | |
with open('roomsjson.txt', encoding='utf-8') as data_file: | |
data = json.loads(data_file.read()) | |
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 | |
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) |
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
[ | |
{"Courtyard": | |
[ | |
"This is a Courtyard", | |
[ | |
{ | |
"1": ["North", "Courtyard"] | |
} | |
], | |
["Item1", "Item2"], | |
["Monster1", "Monster2"] | |
] | |
}, | |
{"Entrance": | |
[ | |
"This is a Entrance", | |
[ | |
{ | |
"1": ["North", "Courtyard"], | |
"2": ["South", "Courtyard"] | |
} | |
], | |
["Item1", "Item2"], | |
["Monster1", "Monster2"] | |
] | |
}, | |
{"Corridor": | |
[ | |
"This is a Corridor", | |
[ | |
{ | |
"1": ["South", "Courtyard"] | |
} | |
], | |
["Item1", "Item2"], | |
["Monster1", "Monster2"] | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment