From 4cb24e14f8ae180eaca480c99deafd9a5a8dbedb Mon Sep 17 00:00:00 2001 From: Simone Ballard Date: Tue, 6 Apr 2021 00:00:30 -0600 Subject: [PATCH 1/2] adv.py updated --- src/adv.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..f7c6e8b9a3 100644 --- a/src/adv.py +++ b/src/adv.py @@ -39,11 +39,74 @@ # Make a new player object that is currently in the 'outside' room. +playerone = Playerone(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: + sys_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. From 6c340440a4c893234f6f3ce09ff307e7099e02bd Mon Sep 17 00:00:00 2001 From: Simone Ballard Date: Tue, 6 Apr 2021 00:25:28 -0600 Subject: [PATCH 2/2] player and room classes created --- src/adv.py | 5 +++-- src/player.py | 6 ++++++ src/room.py | 7 ++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/adv.py b/src/adv.py index f7c6e8b9a3..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,7 +40,7 @@ # Make a new player object that is currently in the 'outside' room. -playerone = Playerone(room['outside'], "player one has arrived outside the room.") +player = Player(room['outside'], "player one has arrived outside the room.") def instructions(): return """ @@ -97,7 +98,7 @@ def travel(input): elif input == "w" or input == "west" or input == "left": player.current_room = player.current_room.w_to else: - sys_print("Wrong Way! There's nothing over there.") + print("Wrong Way! There's nothing over there.") def prompt(s): # print a quicklist of commands 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