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
110 changes: 88 additions & 22 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,67 @@
from room import Room
from player import Player
from item import Item

# 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"]

# Declare Items >> 10 items

shoe = Item("shoe", "smelly", "1")
book = Item("book", "leather", "1")
knife = Item("knife", "sparkly", "1")
fish = Item("fish", "kinda gross", "2")
apple = Item("apples", "sleepy", "10")
spoon = Item("spoons", "rusty", "2")
mote = Item("motes", "wistful", "5,000")
coin = Item("coins", "dull", "2")
bar = Item("bars", "shiny", "5")
pizza = Item("pizza", "probably ok", "1")

# Link Items to Rooms

room["outside"].items = [shoe, book]
room["foyer"].items = [fish, knife]
room["overlook"].items = [apple, spoon]
room["narrow"].items = [mote, coin]
room["treasure"].items = [bar, pizza]

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

player_one = Player("Player", room["outside"])

directions = ["n", "e", "s", "w"]
actions = ["get", "drop"]

print(f"\n{player_one}")

while True:

move = (
input(
"Move around with 'n', 'e', 's', or 'w'\nPick up/Drop items with 'get' & 'drop\nQuit with 'q'\n"
)
.lower()
.split()
)

if move[0] == "q":
print("\nBuh Bye\n")
break

elif len(move) == 1 and move[0] in directions:
player_one.change_room(move[0])

elif len(move) == 2 and move[0] == "get":
player_one.item_add(move[1])

elif len(move) == 2 and move[0] == "drop":
player_one.item_remove(move[1])

elif move[0] == "bag":
player_one.get_items()

else:
print("\nPlease enter a valid command\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, desc, amount):
self.name = name
self.desc = desc
self.amount = amount

def __str__(self):
return f"{self.amount} {self.desc} {self.name}"
43 changes: 43 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,45 @@
# 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}, you are in the {self.current_room}"

def change_room(self, direction):
new_room = getattr(self.current_room, f"{direction}_to")
if new_room:
self.current_room = new_room
print(f"\nYou are now in the {self.current_room}")
else:
print("...please choose a different direction")

def item_add(self, item_name):
for item in self.current_room.items:
if item.name == item_name:
self.items.append(item)
self.current_room.item_remove(item)
print(f">> {item} added to your bag")
else:
print(f">> There is no {item_name} in {self.current_room.name}")

def item_remove(self, item_name):
for item in self.items:
if item.name == item_name:
self.items.remove(item)
self.current_room.item_add(item)
print(f">> {item} removed from your bag")
else:
print(f">> {item_name} is not in your bag")

def get_items(self):
if len(self.items) == 0:
print("Your bag is empty")
else:
for item in self.items:
print(f">> {item}")
32 changes: 31 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.


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

self.n_to = None
self.e_to = None
self.s_to = None
self.w_to = None

self.items = []

def __str__(self):

items_in_room = ""

for item in self.items:
items_in_room += f"{item}\n"

return (
f"{self.name}\n-----\n{self.desc}\n-----\nItems available:\n{items_in_room}"
)

def item_add(self, item):
self.items.append(item)

def item_remove(self, item):
self.items.remove(item)