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
86 changes: 80 additions & 6 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
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"),
"North of you, the cave mount beckons",
[Item("rake", "A dusty old thing. Looks like it is used to pick up leaves."), Item("bucket", "A bucket with holes in it. Not very useful")]),

'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east."""),
passages run north and east""", [Item("hour glass", "A broken hour glass. You can't keep track of the time with this.")]),

'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("candle", "A partially used candle. Just need a way to light it.")]),

'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("gold coin", "A gold coin. Must be getting close to the treasure room."), Item("torch", "An old torch. Needs a way to light it.")]),

'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""", [Item("empty chest", "A dusty, old chest. Completely useless."), Item("skull", "Skull of someone who has been dead for a long time.")])
}


Expand All @@ -38,9 +41,10 @@
#

# Make a new player object that is currently in the 'outside' room.

new_player = Player("Mosharraf", room["outside"], [])
# Write a loop that:
#

# * Prints the current room name
# * Prints the current description (the textwrap module might be useful here).
# * Waits for user input and decides what to do.
Expand All @@ -49,3 +53,73 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.
print(new_player.current_room)
selection = input(
'Please select a direction to move using n, s, e, w. You can add items to your inventory with g and drop them with d. If you want to quit, press q.\n')
while(selection != 'q'):
if selection == 'g':
if len(new_player.current_room.items) == 0:
selection = input(
'There are no more items to pick up. Please make your next move:\n')
else:
new_player.pickup_item(new_player.current_room.items[0])
new_player.current_room.remove_item(
new_player.current_room.items[0])
selection = input('Make your next move:\n')
elif selection == 'd':
if len(new_player.current_items) < 1:
selection = input(
'You have no items to drop. Please make your next move:\n')
else:
new_player.current_room.add_item(new_player.current_items[0])
new_player.drop_item(new_player.current_items[0])

elif new_player.current_room == room['outside'] and selection == 'n':
new_player.current_room = room['foyer']
print(new_player.current_room)
selection = input('Make your next move:\n')

elif new_player.current_room == room['foyer'] and selection == 's':
new_player.current_room = room['outside']
print(new_player.current_room)
selection = input(
'Please select a direction to move using n, s, e, w, or quit with q:\n')

elif new_player.current_room == room['foyer'] and selection == 'n':
new_player.current_room = room['overlook']
print(new_player.current_room)
selection = input(
'Please select a direction to move using n, s, e, w, or quit with q:\n')

elif new_player.current_room == room['overlook'] and selection == 's':
new_player.current_room = room['foyer']
print(new_player.current_room)
selection = input(
'Please select a direction to move using n, s, e, w, or quit with q:\n')

elif new_player.current_room == room['foyer'] and selection == 'e':
new_player.current_room = room['narrow']
print(new_player.current_room)
selection = input(
'Please select a direction to move using n, s, e, w, or quit with q:\n')

elif new_player.current_room == room['narrow'] and selection == 'w':
new_player.current_room = room['foyer']
print(new_player.current_room)
selection = input(
'Please select a direction to move using n, s, e, w, or quit with q:\n')

elif new_player.current_room == room['narrow'] and selection == 'n':
new_player.current_room = room['treasure']
print(new_player.current_room)
selection = input(
'Please select a direction to move using n, s, e, w, or quit with q:\n')

elif new_player.current_room == room['treasure'] and selection == 's':
new_player.current_room = room['narrow']
print(new_player.current_room)
selection = input(
'Please select a direction to move using n, s, e, w, or quit with q:\n')

else:
selection = input('Please try again. Make your next move:\n')
13 changes: 13 additions & 0 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Item:
def __init__(self, name, description):
self.name = name
self.description = description

def take_item(self):
print(f'You have picked up the {self.name}')

def drop_item(self):
print(f'You have dropped the {self.name}')

def __str__(self):
return f'item name: {self.name}, item description: {self.description}'
16 changes: 16 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
# Write a class to hold player information, e.g. what room they are in
# currently.
class Player:
def __init__(self, name, current_room, current_items):
self.name = name
self.current_room = current_room
self.current_items = current_items

def pickup_item(self, item):
self.current_items.append(item)
print(f'You picked up the {item.name}')

def drop_item(self, item):
self.current_items.remove(item)
print(f'You dropped the {item.name}')

def __str__(self):
return f'{self.name} is currently located in the {self.current_room}'
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 add_item(self, item):
self.items.append(item)

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

def __str__(self):
item_output = ""
for item in self.items:
item_output += f'\n{item}'
return f'You are currently located in the {self.name}. {self.description}. The following item(s) are in this room: {item_output}'