Skip to content
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
38 changes: 35 additions & 3 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from room import Room
from player import Player

# Declare all the rooms

Expand Down Expand Up @@ -39,13 +40,44 @@

# Make a new player object that is currently in the 'outside' room.

name = input("\nWhat is your name, Adventurer? ")
player = Player(name, room['outside'])
print(f"\nWelcome to your new Adventure, {player.name}.")


# Write a loop that:

game_is_playing = True

while game_is_playing:
#
# * Prints the current room name
print(f"\nYou are currently {player.current_room.name}.")

# * Prints the current description (the textwrap module might be useful here).
print(f"\t{player.current_room.description}.")

# * Waits for user input and decides what to do.
#
# If the user enters a cardinal direction, attempt to move to the room there.
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.

player_input = input(f"\nWhich direction would you like to go, {player.name}? \n\tType n to travel North, s to travel South, e to travel East, or w to travel West.\n\n\t(You can also type q to end your adventure early.)\n").lower().strip()

if player_input == "q":
game_is_playing = False
print("Your adventure has ended.")
else:
print("Please choose a valid direction.")
print(player_input)

# If the user enters a cardinal direction, attempt to move to the room there.

cardinal_direction = ["n", "e", "s", "w"]

if player_input in cardinal_direction:
player.move_player(player_input)
else:
print("Please choose a valid direction.")

else:
game_is_playing = False
11 changes: 11 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# 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

def move_player(self, direction):
if getattr(self.current_room, f"{direction}_to") is not None:
self.current_room = getattr(self.current_room, f"{direction}_to")
else:
print(f"You've tried moving in the wrong direction, please choose another direction.")
14 changes: 13 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.

# class Room:

class Room:
def __init__(self, name, description, n_to = None, s_to = None, e_to = None, w_to = None):
self.name = name
self.description = description

self.n_to = n_to
self.s_to = s_to
self.e_to = e_to
self.w_to = w_to