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

from player import Player
# 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."""),
passages run north and east with a small alove to the west."""),

'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling
into the darkness. Ahead to the north, a light flickers in
Expand All @@ -16,6 +16,8 @@
'narrow': Room("Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air."""),

'nook': Room("Small Nook", """You find the skeleton of an unlucky adventurer, turn back east before you meet the same end!"""),

'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 @@ -28,6 +30,8 @@
room['foyer'].s_to = room['outside']
room['foyer'].n_to = room['overlook']
room['foyer'].e_to = room['narrow']
room['foyer'].w_to = room['nook']
room['nook'].e_to = room['foyer']
room['overlook'].s_to = room['foyer']
room['narrow'].w_to = room['foyer']
room['narrow'].n_to = room['treasure']
Expand All @@ -37,7 +41,13 @@
# Main
#

game_run = True
name = input("What is you name adventurer?:")
# Make a new player object that is currently in the 'outside' room.
player = Player(name, room["outside"])
print(f"Current Location: {player.current_room.name}, {player.current_room.description}")

directions = [ "n", "e", "s", "w" ]

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

movement = input(f"{player.name} choose the direction you'd like to explore [N] [E] [S] [W] or [Q] to quit then [Enter]: ")

if movement in directions :
print(f"{player.name} is moving {movement}")
player.move(movement)

elif movement == "q":
game_run = False

else:
print("\n Invalid Input, try again")
18 changes: 16 additions & 2 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
# 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 __str__(self):
return f"PLAYER: {self.name}\nLOCATION: {self.current_room}"

def move(self,direction):
if getattr(self.current_room, f"{direction}_to"):
self.current_room = getattr(self.current_room, f"{direction}_to")
print(f"\n{self.name} has entered the {self.current_room.name}\n"
f"You look around and observe, {self.current_room.description}\n")
else:
print(f"You hit a wall, choose different direction\n")
15 changes: 13 additions & 2 deletions src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# Implement a class to hold room information. This should have name and
# description attributes.

class Room:
def __init__(self,name, description, n_to=None, s_to=None, e_to=None, w_to=None ):
self.name = name
self.description = description
self.n_to = None
self.s_to = None
self.e_to = None
self.w_to = None

def __str__(self):
return (f"{self.name}, {self.description}")