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
75 changes: 65 additions & 10 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
from room import Room
from textwrap import TextWrapper

# Declare all the rooms

room = {
'outside': Room("Outside Cave Entrance",
"North of you, the cave mount beckons"),

'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east."""),
'foyer': Room("Foyer", "Dim light filters in from the south. Dusty passages run north and east."),

'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling
into the darkness. Ahead to the north, a light flickers in
the distance, but there is no way across the chasm."""),
'overlook': Room("Grand Overlook", "A steep cliff appears before you, falling into the darkness. Ahead to the north, a light flickers in the distance, but there is no way across the chasm."),

'narrow': Room("Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air."""),
'narrow': Room("Narrow Passage", "The narrow passage bends here from west to north. The smell of gold permeates the air."),

'treasure': Room("Treasure Chamber", """You've found the long-lost treasure
chamber! Sadly, it has already been completely emptied by
earlier adventurers. The only exit is to the south."""),
'treasure': Room("Treasure Chamber", "You've found the long-lost treasure chamber! Sadly, it has already been completely emptied by earlier adventurers. The only exit is to the south."),
}


Expand All @@ -38,6 +33,17 @@
#

# Make a new player object that is currently in the 'outside' room.
class Player:
def __init__(self, name, location = room["outside"]):
self.name = name
self.location = location

def where(self):
print(f"{self.location.name}")

Player_1 = Player("Mark", room["outside"])
## Player_1.location = Player_1.location.n_to
Player_1.where()

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

def formatRoomDesc(description):
textwrapper = TextWrapper(50)
formatted_text = textwrapper.wrap(description)
return [print(text) for text in formatted_text]

def movePlayer():
# Waiting For User Input
userInput = input("Choose a direction (N, E, W, or S) to walk in... \n").lower()

if userInput == "n":
try:
Player_1.location = Player_1.location.n_to
except AttributeError:
print("You find that you cannot move any further North")

elif userInput == "e":
try:
Player_1.location = Player_1.location.e_to
except AttributeError:
print("You find that you cannot move any further East")

elif userInput == "w":
try:
Player_1.location = Player_1.location.w_to
except AttributeError:
print("You find that you cannot move any further West")

elif userInput == "s":
try:
Player_1.location = Player_1.location.s_to
except AttributeError:
print("You find that you cannot move any further South")

elif userInput == "q":
exit()

else:
return "Invalid option, please choose a cardinal direction (N, E, W, S) or quit (Q)"

return

def game_loop():
print(Player_1.location.name)
formatRoomDesc(Player_1.location.desc)
movePlayer()
game_loop()

game_loop()
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 = room["outside"]):
# self.name = name
# self.current_room = current_room
8 changes: 7 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.

class Room:
def __init__(self, name, desc, items = []):
self.name = name
self.desc = desc
self.items = items