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
31 changes: 31 additions & 0 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,6 +40,8 @@

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

newPlayer = Player(input("Please enter your name"), room['outside'])

# Write a loop that:
#
# * Prints the current room name
Expand All @@ -49,3 +52,31 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.

# def move():
# direction = input("> ")
# if direction != 'n' or 's' or 'e' or 'w':
# print("Please enter a valid direction!")
# else:
# print("Go ahead!")

# move()

while True:
currentLocation = newPlayer.location
print(currentLocation.name)
print(currentLocation.description)
cmd = input("Where do you want to go? > ")

if cmd == "q":
break
elif cmd == "n":
newPlayer.current_room = newPlayer.current_room.n_to
elif cmd == "s":
newPlayer.current_room = newPlayer.current_room.s_to
elif cmd == "w":
newPlayer.current_room = newPlayer.current_room.w_to
elif cmd == "e":
newPlayer.current_room = newPlayer.current_room.e_to
else:
print('Please enter a valid direction: "n", "s", "w", "e", or "q" to quit.')
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, current_room, name):
self.current_room = current_room
self.name = name
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.w_to = None
self.e_to = None