Skip to content

Monday py #516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from player import Player
from room import Room

# Declare all the rooms
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.

class Room:
def __init__(self, name, description):
self.name = name
self.description = description