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
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ verify_ssl = true
name = "pypi"

[packages]
requests = "*"

[dev-packages]

[requires]
python_version = "3"
python_version = "3"
57 changes: 57 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

121 changes: 99 additions & 22 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,64 @@
from room import Room
from item import Item
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."""),

'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling
"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.""",
),
"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."""),

'treasure': Room("Treasure Chamber", """You've found the long-lost treasure
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.""",
),
"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."""),
earlier adventurers. The only exit is to the south.""",
),
}


# Link rooms together

room['outside'].n_to = room['foyer']
room['foyer'].s_to = room['outside']
room['foyer'].n_to = room['overlook']
room['foyer'].e_to = room['narrow']
room['overlook'].s_to = room['foyer']
room['narrow'].w_to = room['foyer']
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']
room["outside"].n_to = room["foyer"]
room["foyer"].s_to = room["outside"]
room["foyer"].n_to = room["overlook"]
room["foyer"].e_to = room["narrow"]
room["overlook"].s_to = room["foyer"]
room["narrow"].w_to = room["foyer"]
room["narrow"].n_to = room["treasure"]
room["treasure"].s_to = room["narrow"]

chair = Item(
"chair", " very heavy chair made of bricks, would not want to carry this around"
)
french_bread = Item(
"french bread", "hmm perhaps this has something to do with the room?"
)
rope = Item("short rope", "not long enough to use")
chapstick = Item(
"brand new expensive chapstick", "someone is going to be mad they dropped this"
)
coin = Item("gold coin", "wait....this is made of chocolate")

room["foyer"].items.append(chair)
room["foyer"].items.append(french_bread)
room["overlook"].items.append(rope)
room["narrow"].items.append(chapstick)
room["treasure"].items.append(coin)

#
# Main
Expand All @@ -49,3 +76,53 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.

currentRoom = room["outside"]

print(room["outside"])
user = input("[n] North [e] East [s] South [w] West [q] Quit\n")


while not user == "q":

# user chooses North
if user == "n":
if currentRoom.n_to == None:
print("Travel in this direction is impossible, choose again adventurer")
else:
currentRoom = currentRoom.n_to
print(currentRoom)
currentRoom.printItems()

# user chooses East
elif user == "e":
if currentRoom.e_to == None:
print("Travel in this direction is impossible, choose again adventurer")
else:
currentRoom = currentRoom.e_to
print(currentRoom)
currentRoom.printItems()

# user chooses South
elif user == "s":
if currentRoom.s_to == None:
print("Travel in this direction is impossible, choose again adventurer")
else:
currentRoom = currentRoom.s_to
print(currentRoom)
currentRoom.printItems()
# user chooses West
elif user == "w":
if currentRoom.w_to == None:
print("Travel in this direction is impossible, choose again adventurer")
else:
currentRoom = currentRoom.w_to
print(currentRoom)
currentRoom.printItems()

else:
print(f"{user}? What kind of direction is that? Choose again.")

print("Where to?")
user = input("[n] North [e] East [s] South [w] West [q] Quit\n")

8 changes: 8 additions & 0 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

class Item:
def __init__(self, name, description):
self.name = name
self.description= description

def __str__(self):
return f"{self.name}, {self.description}"
15 changes: 15 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# 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
self.items = []

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

def printItems(self):
print(f"Items in Player Inventory:")
for item in self.items:
print(f"{item}")
21 changes: 20 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
# 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
self.items = []

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

def printItems(self):
print(f"Items in Room:")
for item in self.items:
print(f"{item}")