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
41 changes: 30 additions & 11 deletions src/adv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east.""", [Item('Sword', 'A weapon for a warrior'), Item('Wand', 'A weapon for a mage')]),
Expand All @@ -16,7 +16,7 @@
the distance, but there is no way across the chasm.""", [Item("Shield", "It's flimsy, but it'll do")]),

'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.""", []),

'treasure': Room("Treasure Chamber", """You've found the long-lost treasure
chamber! Sadly, it has already been completely emptied by
Expand Down Expand Up @@ -61,8 +61,6 @@
# if it's the correct type of input, check if there's a room in that direction
# if there's a room in that direction, then update player's current room to new room



selection = ''
# Test for quit input
while selection != 'q':
Expand Down Expand Up @@ -94,43 +92,64 @@
# Determine if room exists to the north, and then update current room if it exists
if player1.current_room.n_to != 'No room there.':
player1.current_room = player1.current_room.n_to
print(player1.current_room)
else:
print ('NO ROOM TO THE NORTH!')
# Determine if room exists to the south, and then update current room if it exists
elif selection == 's':
if player1.current_room.s_to != 'No room there.':
player1.current_room = player1.current_room.s_to
print(player1.current_room)
else:
print ('NO ROOM TO THE SOUTH!')
# Determine if room exists to the east, and then update current room if it exists
elif selection == 'e':
if player1.current_room.e_to != 'No room there.':
player1.current_room = player1.current_room.e_to
print(player1.current_room)
else:
print ('NO ROOM TO THE EAST!')
# Determine if room exists to the west, and then update current room if it exists
elif selection == 'w':
if player1.current_room.w_to != 'No room there.':
player1.current_room = player1.current_room.w_to
print(player1.current_room)
else:
print ('NO ROOM TO THE WEST!')
# Quit condition
elif selection == 'q':
print('Thanks for playing.')
elif len(selection) > 1:
selection = selection.split(' ')
# Check if command is to get or take an item
# Check if command is to gpythoet or take an item
if selection[0] == 'get' or selection[0] == 'take':
selection.pop(0)
itemCheck = ' '.join(selection)
itemNames = []
roomItemNames = []
# Create list of all items in room by name
for item in player1.current_room.inventory:
itemNames.append(item.name.lower())
if itemCheck in itemNames:
print("Item is here!")
roomItemNames.append(item.name.lower())
# Check if item input is in list of room items; if so, add to the player inventory and remove from room inventory
if itemCheck in roomItemNames:
itemIndex = roomItemNames.index(itemCheck)
player1.current_room.inventory[itemIndex].on_take()
player1.inventory.append(player1.current_room.inventory[itemIndex])
del player1.current_room.inventory[itemIndex]
else:
print("No such item in here!")
if selection[0] == 'drop':
selection.pop(0)
itemCheck = ' '.join(selection)
playerItemNames = []
# Create list of all items in player inventory by name
for item in player1.inventory:
playerItemNames.append(item.name.lower())
# Check if item input is in list of player items; if so, add to the room inventory and remove from player inventory
if itemCheck in playerItemNames:
itemIndex = playerItemNames.index(itemCheck)
player1.inventory[itemIndex].on_drop()
player1.current_room.inventory.append(player1.inventory[itemIndex])
del player1.inventory[itemIndex]
# Prompt to type correct input
else:
print('Please select a direction.')

print('Please select a direction.')
8 changes: 7 additions & 1 deletion src/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ def __init__(self, name, description):
def __str__(self):
output = ""
output += "> " + self.name + ": " + self.description
return output
return output

def on_take(self):
return print(F'You have picked up {self.name}!')

def on_drop(self):
return print(F'You have dropped {self.name}!')