diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..87c1c3dba7 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,3 +1,4 @@ +from player import Player from room import Room # Declare all the rooms @@ -39,11 +40,74 @@ # Make a new player object that is currently in the 'outside' room. +player = Player(room['outside'], "player one has arrived outside the room.") + +def instructions(): + return """ + Welcome to the labyrinth dear wanderer... + + * use [L] to look around + * [N,S,E,W] [North, South, East, West] [Up, Down, Right, Left] to travel in those directions + * [q] to quit + """ + +def current_dirs(): + currentDirs = directions() + + if currentDirs.__contains__("n"): + currentDirs.extend(["north", "up", "forward", "forwards"]) + if currentDirs.__contains__("s"): + currentDirs.extend(["south", "down", "backward", "backwards"]) + if currentDirs.__contains__("e"): + currentDirs.extend(["east", "right"]) + if currentDirs.__contains__("w"): + currentDirs.extend(["west", "left"]) + + return currentDirs + +def directions(): + directions = [] + + if hasattr(player.current_room, "n_to"): + directions.append("n") + if hasattr(player.current_room, "s_to"): + directions.append("s") + if hasattr(player.current_room, "e_to"): + directions.append("e") + if hasattr(player.current_room, "w_to"): + directions.append("w") + + return directions + # Write a loop that: # # * Prints the current room name # * Prints the current description (the textwrap module might be useful here). # * Waits for user input and decides what to do. + +def travel(input): + + input = input.lower() + if input in current_dirs(): + if input == "n" or input == "north" or input == "up" or input == "forward" or input == "forwards": + player.current_room = player.current_room.n_to + elif input == "s" or input == "south" or input == "down" or input == "backward" or input == "backwards": + player.current_room = player.current_room.s_to + elif input == "e" or input == "east" or input == "right": + player.current_room = player.current_room.e_to + elif input == "w" or input == "west" or input == "left": + player.current_room = player.current_room.w_to + else: + print("Wrong Way! There's nothing over there.") + +def prompt(s): + # print a quicklist of commands + commands = f"(L to look around | {' | '.join(directions())} to travel | Q to quit | [Help|?] for common commands): " + prompt = f"\nWhat would you like to do, {player.name}?\n{commands}" + + return input(s + prompt) + + # # If the user enters a cardinal direction, attempt to move to the room there. # Print an error message if the movement isn't allowed. diff --git a/src/player.py b/src/player.py index d79a175029..006fbc5acc 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,8 @@ # Write a class to hold player information, e.g. what room they are in # currently. + + +class Player: + def __init__(self, name, current_room): + self.name = name + self.current_room = current_room \ No newline at end of file diff --git a/src/room.py b/src/room.py index 24c07ad4c8..b172774a9e 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,7 @@ # Implement a class to hold room information. This should have name and -# description attributes. \ No newline at end of file +# description attributes. + +class Room: + def __init__(self, name, description): + self.name = name + self.description = description