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
128 changes: 110 additions & 18 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
import os
from room import Room

import player
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
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
chamber! Sadly, it has already been completely emptied by
earlier adventurers. The only exit is to the south."""),
'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 chamber! Sadly, it has already been completely emptied by 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']
Expand All @@ -33,11 +23,21 @@
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']

backpack = item.Item('backpack', 'something to hold your treasure.')
socks = item.Item('socks', 'nothing like a fresh pair of socks (freshness not guaranteed).')
gloves = item.Item('gloves', 'gotta keep those hands clean.')
toothbrush = item.Item('toothbrush', 'fresh breath is all you need.')

room['outside'].items = [socks, gloves, toothbrush]
room['overlook'].items = [backpack]
#
# Main
#

# Make a new player object that is currently in the 'outside' room.
character = player.Character('Mr. Gump', room['outside'])
player_action = "\n\tActions:\n\t[N] North\n\t[E] East\n\t[S] South\n\t[W] West\n\t[Q] Quit\n\t--------\n\t"
cant_move = "You are blocked from heading that direction.\n"

# Write a loop that:
#
Expand All @@ -49,3 +49,95 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.
os.system('clear')
print("\n\n\t", character.current_room.name)
print("\t", character.current_room.description)

# if character.current_room.items is not None:
# print('\n\tYou see a lump in the corner of the room and find: \n')
# for item in room['outside'].items:
# # print(f"{item.name} {item.description}")
# print("\t", item.name)

player_direction = input(player_action).lower()

while not player_direction == "q":
os.system('clear')

# if character.current_room.items is not None:
# print('\n\tYou see a lump in the corner of the room and find: \n')
# for item in room['outside'].items:
# print("\t", item.name)

if player_direction == 'n':
if character.current_room.n_to != None:
character.current_room = character.current_room.n_to
else:
print(cant_move)
elif player_direction == 's':
if character.current_room.s_to != None:
character.current_room = character.current_room.s_to
else:
print(cant_move)
elif player_direction == 'e':
if character.current_room.e_to != None:
character.current_room = character.current_room.e_to
else:
print(cant_move)
elif player_direction == 'w':
if character.current_room.w_to != None:
character.current_room = character.current_room.w_to
else:
print(cant_move)

elif 'inventory' in player_direction:
print('\n\tHere is your inventory:')
for i in character.inventory:
print(f"\t{i.name}")

elif 'get' in player_direction:
to_get = player_direction.split(" ", 1)[1]
# add to inventory
item_in_inventory = [True for x in character.inventory if x.name == to_get]
if item_in_inventory != True:
""" Add item to character inventory """
for x in character.current_room.items:
if to_get in x.name:
character.add_item(x)
item_index = character.current_room.items.index(x)
character.current_room.items.pop(item_index)
""" Remove item from room """

else:
print('how did you find that?')

print('\n\tYou added the', to_get, 'to your backpack')

elif 'drop' in player_direction:
to_drop = player_direction.split(" ", 1)[1]
# remove from inventory
for x in character.inventory:
if to_drop in x.name:
character.drop_item(x)
# add to room
character.current_room.items.append(x)

print('\n\tYou just dropped ', to_drop)

elif 'search' in player_direction:
""" See what items are hiding somewhere in the room """
if character.current_room.items != None:
print('\n\tAfter searching around, for what felt like hours you found:\n')
for i in character.current_room.items:
item.ShowItem(i)
else:
print('You search in vain, there is nothing here worth taking.')
else:
print('\n\tYou spin in circles not knowing which direction to go.\n')

print("\n\n\t", character.current_room.name)
print("\t", character.current_room.description)

player_direction = input(player_action).lower()

os.system('clear')
12 changes: 12 additions & 0 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Item:

def __init__(self, name, description):
self.name = name
self.description = description


class ShowItem:

def __init__(self, item=None):
if item != None:
print(f"\t{item.name}: {item.description}")
17 changes: 17 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# Write a class to hold player information, e.g. what room they are in
# currently.
class Character:

def __init__(self, name, current_room, inventory=None):
self.name = name
self.current_room = current_room

if inventory is None:
self.inventory = []
else:
self.inventory = inventory

def add_item(self, item):
#print(f"{item.name} {item.desc")
self.inventory.append(item)

def drop_item(self, item):
print(item.name)
28 changes: 27 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
# 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, n_to=None, s_to=None, e_to=None, w_to=None):
self.name = name
self.description = description

if items is None:
self.items = []
else:
self.items = items

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

def dropped_item(item):
""" A dropped item is added to the room """
pass

def picked_item(item):
""" A picked item is removed from the room and added to player inventory """
print(f"{item.name} {item.description}")