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
147 changes: 128 additions & 19 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from room import Room
from player import Player
from item import Item
import sys
import textwrap

# Declare all the rooms

Expand All @@ -8,45 +11,151 @@
"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 west."""),

'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."""),
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."""),
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."""),
chamber! Sadly, it has already been completely emptied by
earlier adventurers. The only exit is to the south."""),
}


# Link rooms together

'''

treasure overlook
| |
narrow ---- foyer
|
outside
'''

room['outside'].n_to = room['foyer']
room['foyer'].s_to = room['outside']
room['foyer'].n_to = room['overlook']
room['foyer'].e_to = room['narrow']
room['foyer'].w_to = room['narrow']
room['overlook'].s_to = room['foyer']
room['narrow'].w_to = room['foyer']
room['narrow'].e_to = room['foyer']
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']

roomKeys = [name for name in room]

print(roomKeys)

items = {
'sword': Item('sword', 'A sharpend piece of steel'),
'lamp': Item('lamp', 'An oil lamp'),
'flare': Item('flare', 'A stick with lighting power.'),
'gold': Item('gold', 'A sparkling piece of yellow metal')
}

room['outside'].set_items([items['lamp'], items['gold']])
room['foyer'].set_items([items['flare'], items['gold']])
room['treasure'].set_items([items['gold']])

# print(room['narrow'].w_to.n_to)

#
# Main
#

# def tryMove()

def parser(user_input):
# direction = user_input + '_to'
# player.move(player.currentRoom[direction])

inputs = user_input.split(' ')
# player.move(player.currentRoom.n_to)
# if direction in player.currentRoom:
# print('this is working')

if len(inputs) < 2:
# If the user enters a cardinal direction, attempt to move to the room there.
if user_input == 'n':
try:
player.move(player.currentRoom.n_to)
except AttributeError:
print('There is nothing!')
elif user_input == 'e':
try:
player.move(player.currentRoom.e_to)
except AttributeError:
print('There is nothing!')
elif user_input == 's':
try:
player.move(player.currentRoom.s_to)
except AttributeError:
print('There is nothing!')
elif user_input == 'w':
try:
player.move(player.currentRoom.w_to)
except AttributeError:
print('There is nothing!')
# If the user enters "q", quit the game.
elif user_input == 'q':
print('You have given up')
sys.exit()
else:
print('ERROR! Thous\'t cannout goest!')
else:
verb = inputs[0]
noun = inputs[1]
print('two words')
if verb == 'get':
'''
if not noun in items:
if not noun in player.currentRoom.items:
print(f'{noun} does not exist')
yield(1)
'''

if noun in items:
if items[noun] in player.currentRoom.items:
player.pickup_item(items[noun])
player.currentRoom.remove_item(items[noun])
else:
print(f'There is no {noun} in the room')
else:
print(f'{noun} does not exist')
elif verb == 'drop':
if noun in items:
if items[noun] in player.items:
player.drop_item(items[noun])
player.currentRoom.add_item(items[noun])
else:
print(f'You do not have {noun}')
else:
print(f'{noun} does not exist')

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

sword = Item('sword', 'A sharpend piece of steel')

player.pickup_item(items['sword'])

while True:
# * Prints the current room name
print(player.currentRoom.name, '\n')

# * Prints the current description (the textwrap module might be useful here).
# print(player.currentRoom.discription, '\n')
for line in textwrap.wrap(player.currentRoom.discription):
print(line)

print('You have these items:', [i.name for i in player.items])

print(f'You spot some items in the {player.currentRoom.name}!', [i.name for i in player.currentRoom.items])

# * Waits for user input and decides what to do.
action = input('doues\'t what?\n')
parser(action)

# 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.
#
# 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.
14 changes: 14 additions & 0 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

class Item:
def __init__(self, name, discription):
self.name = name
self.discription = discription

def __str__(self):
return self.name

def on_get(self):
print(f'{self.discription}')

def on_drop(self):
print(f'{self.name} falls to the ground')
19 changes: 17 additions & 2 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# Write a class to hold player information, e.g. what room they are in
# currently.
from item import Item

class Player:
def __init__(self):
pass
def __init__(self, currentRoom):
self.currentRoom = currentRoom
self.items = []

def move(self, room):
self.currentRoom = room

def pickup_item(self, item):
self.items.append(item)
print(f'Picked up {item.name}!')
item.on_get()

def drop_item(self, item):
self.items.remove(item)
print(f'Droped {item.name}')
item.on_drop()
11 changes: 11 additions & 0 deletions src/room.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# Implement a class to hold room information. This should have name and
# description attributes.
from item import Item

class Room:
def __init__(self, name, discription):
self.name = name
self.discription = discription
self.items = []

def set_items(self, items):
self.items = items

def add_item(self, item):
self.items.append(item)

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