Skip to content
This repository was archived by the owner on Dec 8, 2023. It is now read-only.
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
91 changes: 82 additions & 9 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
from room import Room
from player import Player
import sys, os

# Declare all the rooms

# hOpt = {
# "name": sys.args[1] if len(sys.argv) >= 2 else None
# }
clear = lambda: os.system('clear')
room = {
'outside': Room("Outside Cave Entrance",
'outside': Room("outside","Outside a Cave Entrance",
"North of you, the cave mount beckons"),

'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
'foyer': Room("foyer", "in a 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
'overlook': Room("overlook", "at a 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.""", ['key']),

'narrow': Room("Narrow Passage", """The narrow passage bends here from west
'narrow': Room("narrow","in a 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
'treasure': Room("treasure","at the 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."""),
}
Expand All @@ -32,11 +37,11 @@
room['narrow'].w_to = room['foyer']
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']

# print(hOpt)
#
# Main
#

Hero = Player(room['outside'])
# Make a new player object that is currently in the 'outside' room.

# Write a loop that:
Expand All @@ -49,3 +54,71 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.
print(f'''
Welcome {Hero.name} the Hero!, \n
collect the 4 mystic keys to open the treasure after you find it to win.
There is a total of 4 keys, water, fire, earth and wind.
Collect all of them to open the treasure once you've found it.
If you can open the treasure you can find eternal glory!
(Yes like in harry potter part IV) Good Luck!
''')
while True:
# print(Hero)
if Hero.room.name == 'treasure':
pass
else:
print(f'CURRENT ROOM : {Hero.room.name.upper()}\n\n\n\n')
print(f'You find yourself {Hero.room.title}, \n{Hero.room.description}\n')
action = str(input('''
\n\n \t What to do next?
n -> Go north
s -> Go south
e -> Go east
w -> Go west
i -> To check items
s -> Search this room for items
q -> quit
'''))
if action == 'q':
print('Ok see you later.')
break
elif 'get' in action:
if len(Hero.room.items) == 0:
clear()
print('There is no items to get in this room \n\n')

else:
clear()
Hero.getItem(action.split()[1])
elif 'drop' in action:
if len(Hero.items) == 0:
clear()
print('There is no items to drop \n\n')

else:
clear()
Hero.dropItem(action.split()[1])
elif action == 'i':
if len(Hero.items) == 0:
clear()
print('You don\'t have any items \n\n')

else:
clear()
Hero.countItems()
elif action == 'search':
if len(Hero.room.items) == 0:
clear()
print('There is no items in this room\n\n')

else:
clear()
Hero.room.searchRoom()
else:
clear()
Hero.move(action)
if Hero.win:
break



49 changes: 49 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,51 @@
# Write a class to hold player information, e.g. what room they are in
# currently.
directionMap = { 'n': 'north', 's':'south', 'e': 'east', 'w': 'west'}
class Player:
def __init__(self, room, name="chicken little", items=[], win=False):
self.name = name
self.room = room
self.items = items
self.win = win
def countItems(self):
print(f'\nCongrats {self.name}, you\'ve found this items so far:\n')
for i in self.items:
print(f' - {i} \n')
print(f'Total: {len(self.items)} out of 1\n')
def __str__(self):
return f'''\n\tName: {self.name}\n\tRoom: {self.room}\n\tItems: {self.items} \n'''
def getItem(self, item=None):
if item is None:
print(f'Please provide an item name like so --> get example')
elif item not in self.room.items:
print(f'You do not have item --> {item}')
else:
print(f'You collected item --> {item}! \n\n')
self.items.append(self.room.items.pop(self.room.items.index(item)))
def dropItem(self, item=None):
if item is None:
print(f'Please provide an item name to drop like so --> drop example')
elif item not in self.items:
print(f'You do not have item --> {item}')
else:
print(f'You dropped the item --> {item}! \n\n')
self.room.items.append(self.items.pop(self.items.index(item)))
def move(self, direction):
# print('direction:', direction, 'golden' in self.items )
print(f'\n\n\n You\'ve choosen to go {directionMap.get(direction)}...\n')
nextRoom = getattr(self.room, f'{direction}_to', None)
if nextRoom is None:
print(f'There is nothing in this direction, so you go back...')
elif nextRoom.name == 'treasure':
if 'key' in self.items:
self.room = nextRoom
print(f'\t\nYou find yourself {self.room.title}, you use the key to open it')
print(f'\t\n{self.room.description}')
print(f'\t\nEnd of the game for our hero {self.name}')
self.win = True
else:
print(f'You find a massive vault door, it\'s locked and it seems to need a key')
print(f'to open, you go back trying to search for the key.\n')
else:
self.room = nextRoom

21 changes: 20 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.
x = "Theres nothing is this direction"
class Room:
def __init__(self, name, title, description, items=[]):
self.name = name
self.title = title
self.description = description
self.items = items
def __str__(self):
return f'''
\t\tName: {self.name}
\t\tTitle: {self.title}
\t\tDescription: {self.description}
\t\titems: {self.items}'''
def searchRoom(self):
print(f'You\'ve searched in {self.name}...')
print(f'Congrats, you\'ve found this items:\n')
for i in self.items:
print(f' - {i} \n')
print(f'\nUse "get [item name]" or "drop [item name]" to get/drop these items\n\n')