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
98 changes: 91 additions & 7 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
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", []),

'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east."""),
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."""),
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."""),
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."""),
earlier adventurers. The only exit is to the south.""", []),
}


Expand All @@ -33,19 +35,101 @@
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']

room['outside'].items= ['gold','silver','murr']
#
# Main
#

decisions = ('n','s','e','w','q', 'i', 'take')
# Make a new player object that is currently in the 'outside' room.

playerName = input("What is your name warrior?\n\n")
player = Player(playerName, room["outside"])
decision = input(f"Very well, {player.name}! You are about to embark on an adventure of great importance and many treasures, are you ready?\n\n[y] Yes [n] No [q] Quit\n")
# Write a loop that:
#
while (decision not in ['y','q']):
if( decision == 'n'):
decision = input(f"Have some courage, {player.name}! Come back when you're ready to face your fears. Stop wasting my time.\n\n\nOne year later...............\n\n\nAh, yes, you look familar are you ready to begin your quest? \n\n[y] Yes [n] No [q] Quit\n")
else:
decision = input("Quit dilly-dallying, make up your mind, lad! I haven't got all autumn. Make true, are you ready or not?\n\n\n[y] Yes [n] No [q] Quit\n")
while decision != 'q':
# * Prints the current room name
print(player.current_room.name)
# * Prints the current description (the textwrap module might be useful here).
print(player.current_room.description)
# * Waits for user input and decides what to do.
if( len(player.current_room.items) ):
print(f'Items in room: {", ".join(player.current_room.items)}\n')
decision = input("\nHow would you like to proceed?\n\n[n] North [s] South [e] East [w] West \n[take <item-name1> <item-name2> ....] Take Item(s) [take all] Take All Items \n[i] Open Inventory \n[q] Quit Game\n\n")
while decision.split(' ')[0] not in decisions:
print("\nPlease make a valid selection to proceed!")
decision = input("\n\n[n] North [s] South [e] East [w] West \n[take <item-name1> <item-name2> ...] Take Item(s) [take all] Take All Items\n[i] Open Inventory \n[q] Quit Game\n\n")
# for e in room:
# print("'{}' is the '{}' and is '{}'\n".format(e, room[e].name, room[e].description))
#
# If the user enters a cardinal direction, attempt to move to the room there.
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.
print("\n")
if(decision == 'q'):
print("Goodbye!")
elif(decision[:4] == 'take'):
grabList = decision.split(' ')
grabList.remove('take')
if( len(grabList) == 1 and grabList[0] == 'all'):
for x in player.current_room.items:
player.inventory.append(x)
player.current_room.items = []
elif( len(grabList) ):
i=0
while i < len(grabList):
if( grabList[i] in player.current_room.items ):
player.inventory.append(grabList[i])
player.current_room.items.remove(grabList[i])
else:
print("This room does not have that item.")
i+=1
print("You now have:",', '.join(player.inventory), 'in your inventory\n')
else:
print("The room is empty!\n")
elif(decision == 'i'):
if( len(player.inventory) ):
print('You have:', ', '.join(player.inventory), '\n' )
while decision != 'c':
decision = input("[drop <item-name1> <item-name2>....] Drop Item(s), [c] Close Inventory [q] Quit Game\n")
if( decision == 'c' ):
break
if( decision == 'q' ):
print("Goodbye!")
exit()
if( decision[:4] == 'drop' ):
dropList = decision.split(' ')
dropList.remove('drop')
if( len(dropList) == 1 and dropList[0] == 'all'):
for x in player.inventory:
player.current_room.items.append(x)
player.inventory=[]
else:
i=0
while i < len(dropList):
if( dropList[i] in player.inventory ):
player.current_room.items.append(dropList[i])
player.inventory.remove(dropList[i])
else:
print("You do not have that item.")
i+=1
if( len(player.inventory) ):
print(f"You now have: {', '.join(player.inventory)} in your inventory\n")
else:
print(f"You now have no items in your inventory\n")
decision = 'c'
else:
print("You are not carrying anything in your satchel of treasures.\n")
else:
move = decision+"_to"
if hasattr(player.current_room, move):
player.current_room=getattr(player.current_room, move)
print("\n\n")
else:
print("{} does not have a path in that direction.\n".format(player.current_room.name))
exit()
6 changes: 6 additions & 0 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Item:
def __init__(self, name, description):
self.name = name
self.description = description
def __str__(self):
return self.name, self.description
7 changes: 7 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# Write a class to hold player information, e.g. what room they are in
# currently.
class Player:
def __init__(self, name, current_room, inventory=[]):
self.name = name
self.current_room = current_room
self.inventory = inventory
def __str__(self):
return self.name, self.room, self.inventory
7 changes: 6 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# 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