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

# Declare all the rooms

Expand Down Expand Up @@ -37,8 +39,25 @@
# Main
#

# List of objects and assigned rooms

torch = Item('Torch', 'A flaming torch for light and warmth')
sword = Item('Sword', 'A old rusty sword dropped by a previous adventurer')
coin = Item('Coin', 'Coin used for purchasing goods and services')
bow = Item('Bow', 'Bow for when you want to stab someone who is far away from you')

room['outside'].add_item(torch)
room['foyer'].add_item(sword)
room['narrow'].add_item(coin)
room['overlook'].add_item(bow)

action = ['Get', 'Drop']

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

name = input("Please enter your player name: ")
player = Player(name, room['outside'], [])

# Write a loop that:
#
# * Prints the current room name
Expand All @@ -49,3 +68,107 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.


print('You are currently in', player.location.name)
print(player.location.description)
print(f'You find {player.location.items[0].description}')


while True:
cmd = input(
"Please enter a direction you would like to travel in.... \n [I] - Inventory \n [n] - North \n [e] - East \n [s] - South \n [w] - West, \n or press q to quit the game: ")

if cmd == 'n':
# If player.location.n_to is NOT "NONE", then assign player.location.n_to (foyer) the current location.
if player.location.n_to is not None:
player.location = player.location.n_to
print(
f'You are now in {player.location.name}, {player.location.description}')
else:
print('You cannot go that way!')
if player.location.items != []:
for v in player.location.items:
print(f'You find {v.description}')
i = input(
f'Would you like to pick up the {v.name}? [Get] [Item-name]: ')
if i == f'{action[0]} {player.location.items[0].name}':
player.pick_item(player.location.items[0])
print(
f'You have picked up the {player.location.items[0].name}!')
player.location.remove_item(player.location.items[0])
else:
print('The room is empty!')
elif cmd == 'e':
if player.location.e_to is not None:
player.location = player.location.e_to
print(
f'You are now in {player.location.name}, {player.location.description}')
else:
print('You cannot go that way!')
if player.location.items != []:
for v in player.location.items:
print(f'You find {v.description}')
i = input(
f'Would you like to pick up the {player.location.items[0].name}? [Get] [Item-name]: ')
if i == f'{action[0]} {player.location.items[0].name}':
player.pick_item(player.location.items[0])
print(
f'You have picked up the {player.location.items[0].name}!')
player.location.remove_item(player.location.items[0])
else:
print('The room is empty!')
elif cmd == 's':
if player.location.s_to is not None:
player.location = player.location.s_to
print(
f'You are now in {player.location.name}, {player.location.description}')
else:
print('You cannot go that way!')
if player.location.items != []:
for v in player.location.items:
print(f'You find {v.description}')
i = input(
f'Would you like to pick up the {player.location.items[0].name}? [Get] [Item-name]: ')
if i == f'{action[0]} {player.location.items[0].name}':
player.pick_item(player.location.items[0])
print(
f'You have picked up the {player.location.items[0].name}!')
player.location.remove_item(player.location.items[0])
else:
print('The room is empty!')
elif cmd == 'w':
if player.location.w_to is not None:
player.location = player.location.w_to
print(
f'You are now in {player.location.name}, {player.location.description}')
else:
print('You cannot go that way!')
if player.location.items != []:
for v in player.location.items:
print(f'You find {v.description}')
i = input(
f'Would you like to pick up the {player.location.items[0].name}? [Get] [Item-name]: ')
if i == f'{action[0]} {player.location.items[0].name}':
player.pick_item(player.location.items[0])
print(
f'You have picked up the {player.location.items[0].name}!')
player.location.remove_item(player.location.items[0])
else:
print('The room is empty!')
elif cmd == 'q':
exit()
elif cmd == 'I':
if player.inventory != []:
[print(s.name) for s in player.inventory]
d = input('Please select an item to remove: ')
for i in player.inventory:
if i.name == d:
player.drop_item(i)
print(f'You have dropped the {i.name}!')
player.location.add_item(i)
[print(j.name) for j in player.inventory]
elif player.inventory == []:
print('Your inventory is empty!')
else:
print('You must choose either [n] [s] [e] [w]!')
4 changes: 4 additions & 0 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Item:
def __init__(self, name, description):
self.name = name
self.description = description
13 changes: 13 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# Write a class to hold player information, e.g. what room they are in
# currently.


class Player:
def __init__(self, name, location, inventory):
self.name = name
self.location = location
self.inventory = []

def pick_item(self, item):
self.inventory.append(item)

def drop_item(self, item):
self.inventory.remove(item)
19 changes: 18 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.


class Room:
def __init__(self, name, description, items=None):
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 add_item(self, item):
self.items.append(item)

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