diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..16f0391b94 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,4 +1,5 @@ from room import Room +from player import Player # Declare all the rooms @@ -21,7 +22,6 @@ earlier adventurers. The only exit is to the south."""), } - # Link rooms together room['outside'].n_to = room['foyer'] @@ -49,3 +49,33 @@ # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. + +game = True +player = Player('Brandon', room['outside']) + +while game: + try: + selection = input("Select where to go: ") + attribute = selection + "_to" + + def movement(dir): + player.move(attribute) + print(f'\n{player.name} moved {dir} to {player.current_room.name}') + print(f'{player.current_room.description}\n') + + if selection == "n": + movement('north') + if selection == "s": + movement('south') + if selection == "e": + movement('east') + if selection == "w": + movement('west') + if selection == "q": + print("Game over") + game = False + else: + print('Please select n, s, e, w, or q') + + except AttributeError: + print(f'You can\'t go that direction\n') diff --git a/src/player.py b/src/player.py index d79a175029..2425c949aa 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,12 @@ # Write a class to hold player information, e.g. what room they are in # currently. + +class Player: + def __init__(self, name, starting_room): + self.name = name + self.current_room = starting_room + + def move(self, dir): + getattr(self.current_room, dir) + if hasattr(self.current_room, dir): + self.current_room = getattr(self.current_room, dir) diff --git a/src/room.py b/src/room.py index 24c07ad4c8..07c634763b 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,5 @@ -# Implement a class to hold room information. This should have name and -# description attributes. \ No newline at end of file +class Room: + def __init__(self, name, description): + self.name = name + self.description = description +