Skip to content

Finalized MVP, player can move, and errorHandler in place #519

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 1 commit 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
32 changes: 31 additions & 1 deletion 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 All @@ -21,7 +22,6 @@
earlier adventurers. The only exit is to the south."""),
}


# Link rooms together

room['outside'].n_to = room['foyer']
Expand Down Expand Up @@ -49,3 +49,33 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.

game = True
player = Player('Brandon', room['outside'])

while game:
try:
selection = input("Select where to go: ")
attribute = selection + "_to"

def movement(dir):
player.move(attribute)
print(f'\n{player.name} moved {dir} to {player.current_room.name}')
print(f'{player.current_room.description}\n')

if selection == "n":
movement('north')
if selection == "s":
movement('south')
if selection == "e":
movement('east')
if selection == "w":
movement('west')
if selection == "q":
print("Game over")
game = False
else:
print('Please select n, s, e, w, or q')

except AttributeError:
print(f'You can\'t go that direction\n')
10 changes: 10 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
# Write a class to hold player information, e.g. what room they are in
# currently.

class Player:
def __init__(self, name, starting_room):
self.name = name
self.current_room = starting_room

def move(self, dir):
getattr(self.current_room, dir)
if hasattr(self.current_room, dir):
self.current_room = getattr(self.current_room, dir)
7 changes: 5 additions & 2 deletions src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Implement a class to hold room information. This should have name and
# description attributes.
class Room:
def __init__(self, name, description):
self.name = name
self.description = description