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
37 changes: 34 additions & 3 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from room import Room

from player import Player
# Declare all the rooms

room = {
Expand Down Expand Up @@ -38,14 +38,45 @@
#

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

player = Player('Boris', room['outside'])
# Write a loop that:
#
# * Prints the current room name
# * Prints the current room name that the player is currently in.
# * Prints the current description (the textwrap module might be useful here).
# * 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.

while True:
print(f"current room: {player.current_room.name}")
print(f"current room description: {player.current_room.description}")
move_to = input('In which direction do you want the player to move (Valid commands are n, s, e, w. Press "q" to quit): ')
directions = ['n', 's', 'e', 'w']
if move_to == 'q':
print("You quit")
break
elif move_to not in directions:
print(f'Valid entries are {directions}')
elif move_to == 'n':
if player.current_room.n_to is None:
print('Cannot move in that direction')
else:
player.current_room = player.current_room.n_to
elif move_to == 's':
if player.current_room.s_to is None:
print('Cannot move in that direction')
else:
player.current_room = player.current_room.s_to
elif move_to == 'w':
if player.current_room.w_to is None:
print('Cannot move in that direction')
else:
player.current_room = player.current_room.w_to
elif move_to == 'e':
if player.current_room.e_to is None:
print('Cannot move in that direction')
else:
player.current_room = player.current_room.e_to
5 changes: 5 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# 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
11 changes: 10 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# 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
self.n_to = None
self.s_to = None
self.e_to = None
self.w_to = None