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
77 changes: 70 additions & 7 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
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"),
'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.""",[Item("POTION","Life giving Elixr")]),

'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."""),
the distance, but there is no way across the chasm.""",[Item("SWORD","A Hero's Weapon")]),

'narrow': Room("Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air."""),
to north. The smell of gold permeates the air.""",[Item("SHEILD","A Heros best friend"),Item("DAGGER","Up close and personal")]),

'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."""),
chamber! Sadly, it is cursed. The choice is yours to tempt fate.The only exit is to the south.""",[Item("TREASURE","The beggining to a better life")]),
}


Expand All @@ -32,12 +32,75 @@
room['narrow'].w_to = room['foyer']
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']
x = hasattr(room, 'outside')
# if hasattr(player1.current_room, "n_to"):
# player1.current_room = player1.current_room.n_to

#
# Main
#

selection= input("What is your name Traveler? Enter Name or q to quit:").strip()
# Make a new player object that is currently in the 'outside' room.
if selection.upper() != "Q":
playerOne =Player(selection,room["outside"])
print("Welcome " + str(playerOne.name) + " you are currently in " + str(playerOne.current_room))
print("You can check your current Inventory by selecting i or Inventory")
print("If there is an item in the room you can get it by typing get and the name of the item")
print("If you wish to drop an item you can by typing drop and the name of the item")
print("Like get potion and drop potion. Notice the space between the words")
while selection[0].upper() != "Q":
selection = input("Choose an action or a direction N,S,E,W or Q to quit:").strip().split()
while not selection:
print("Please enter a valid selection fool!")
selection = input("Choose an action or a direction N,S,E,W or Q to quit:").strip().split()
if selection[0].upper() == "N":
if hasattr(playerOne.current_room,"n_to"):
playerOne.current_room = playerOne.current_room.n_to
print("You are entering " + str(playerOne.current_room))
else:
print("Fool you can't go that way")
elif selection[0].upper() == "S":
if hasattr(playerOne.current_room,"s_to"):
playerOne.current_room = playerOne.current_room.s_to
print("You are entering " + str(playerOne.current_room))
else:
print("Fool you can't go that way")
elif selection[0].upper() == "E":
if hasattr(playerOne.current_room,"e_to"):
playerOne.current_room = playerOne.current_room.e_to
print("You are entering " + str(playerOne.current_room))
else:
print("Fool you can't go that way")
elif selection[0].upper() == "W":
if hasattr(playerOne.current_room,"w_to"):
playerOne.current_room = playerOne.current_room.w_to
print("You are entering " + str(playerOne.current_room))
else:
print("Fool you can't go that way")
elif (selection[0].upper() == "GET" or selection[0].upper() == "TAKE") and (len(selection) == 2):
if len(playerOne.current_room.items) > 0:
playerOne.get_item(selection[1].upper())
print(str(playerOne.current_room))
else:
print("No items in here")
elif (selection[0].upper() == "DROP") and (len(selection) == 2):
if len(playerOne.items) > 0:
playerOne.drop_item(selection[1].upper())
print(str(playerOne.current_room))
else:
print("No items to drop")
elif (selection[0].upper() == "I") or (selection[0].upper() == "INVENTORY"):
playerOne.current_items()
elif selection[0].upper() == "Q":
break
elif len(selection) > 2:
print("Please enter a valid selection fool!")
else:
print("Please enter a valid selection fool!")


print('Goodbye!')

# Write a loop that:
#
Expand Down
14 changes: 14 additions & 0 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Item:
def __init__(self, name,description):
self.name = name
self.description = description

def __str__(self):
output = f"This is a {self.name}!"
output += f"\n {self.description}"
return output
def on_take(self):
print(f"You have picked up {self.name}")

def on_drop(self):
print(f"You have dropped {self.name}")
44 changes: 44 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
# Write a class to hold player information, e.g. what room they are in
# currently.
class Player:
def __init__(self, name,current_room,items=[]):
self.name = name
self.current_room = current_room
self.items = items
def current_items(self):
num = 1
item_output = "\n The items in your inventory are:"
if len(self.items) < 1:
item_output += "\n You are currently holding no items."
else:
for i in self.items:
item_output += "\n" + str(num) + " " + str(i)
num +=1
print(item_output)
def get_item(self,item_name):
for n in self.current_room.items:
if n.name == item_name:
n.on_take()
self.items.append(n)
self.current_room.items.remove(n)
else:
print("No item by that name")

def drop_item(self,item_name):
for n in self.items:
if n.name == item_name:
n.on_drop()
self.current_room.items.append(n)
self.items.remove(n)
else:
print("No item by that name")

def __str__(self):
num = 1
output = f"You are in the {self.current_room} room!"
if len(self.items) < 1:
output += "\n You are currently holding no items."
else:
output += "\n The items in your inventory are:"
for i in self.items:
output += "\n" + str(num) + ". " + str(i)
num += 1
return output
20 changes: 19 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.
class Room:
def __init__(self, name,description,items=[]):
self.name = name
self.description = description
self.items = items

def __str__(self):
num = 1
output = f"{self.name} room!"
output += f"\n {self.description}"
if len(self.items) < 1:
output += "\n There are no items in this room"
else:
output += "\n The Items in this room are:"
for i in self.items:
output += "\n " + str(num) + ". " + str(i)
num +=1
return output