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
44 changes: 44 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 @@ -38,6 +39,11 @@
#

# Make a new player object that is currently in the 'outside' room.
while True:
cmd = input("What is your name adventurer? \n")
player = Player(cmd,room['outside'])
print(player)
break

# Write a loop that:
#
Expand All @@ -49,3 +55,41 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.
while True:
cmd = input("->")
current_room = player.current_room

if cmd == "q":
print("Goodbye scardy cat!")
break
elif cmd == "n":
if current_room.n_to == None:
print(f'You hit a wall {player.name}')
else:
player.current_room = current_room.n_to
print("You move North")
print(current_room.n_to)
elif cmd == "s":
if current_room.s_to == None:
print(f'You hit a wall {player.name}')
else:
player.current_room = current_room.s_to
print("You move South")
print(current_room.s_to)
elif cmd == "e":
if current_room.e_to == None:
print(f'You hit a wall {player.name}')
else:
player.current_room = current_room.e_to
print("You move East")
print(current_room.e_to)
elif cmd == "w":
if current_room.w_to == None:
print(f'You hit a wall {player.name}')
else:
player.current_room = current_room.w_to
print("You move West")
print(current_room.w_to)
else:
print("ERROR: Valid Commands are n for north, s for south, e for east, w for west, or q for quit")

Empty file added src/items.py
Empty file.
7 changes: 7 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# 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 __repr__(self):
return f'{self.name} you are located {self.current_room}'
12 changes: 11 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
# 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
def __repr__(self):
return f"{self.name} \n {self.description}"