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
20 changes: 20 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 96 additions & 1 deletion 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 All @@ -18,6 +20,10 @@

'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."""),

'secret': Room("Secret", """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,13 +38,28 @@
room['narrow'].w_to = room['foyer']
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']
room['secret'].n_to = room['outside']


sword = Item("sword", "cutting through flesh")
axe = Item("axe", "battle axe")
torch = Item("torch", "torch")
dagger = Item("dagger", "hunting")
gold = Item("gold", "Yea Buddy")

room['outside'].items = []
room['foyer'].items = [torch]
room['overlook'].items = [dagger]
room['narrow'].items = [axe, sword]
room['treasure'].items = [gold]
room['secret'].items =[map]

#
# Main
#

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

newPlayer =Player('Dave', room['outside'])
# Write a loop that:
#
# * Prints the current room name
Expand All @@ -49,3 +70,77 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.

print("\033[1;31;40m \n")

while True:
action = input('Enter an action: ⚔🤩').split(" ")
if len(action) == 1 :
action = action[0]

elif len(action) == 2 :
new_item = action[1]
action = action[0]


if action == 'start😎':
if newPlayer.current_room:
print(f'{newPlayer.current_room}')
else:
print('no path in that direction')
if action == 'n':
if newPlayer.current_room.n_to:
newPlayer.current_room=newPlayer.current_room.n_to
print(f'{newPlayer.current_room}')
else:
print('you cannot go north')
if action == 's':
if newPlayer.current_room.s_to:
newPlayer.current_room=newPlayer.current_room.s_to
print(f'{newPlayer.current_room}')
else:
print('no path in that direction')
if action == 'e':
if newPlayer.current_room.e_to:
newPlayer.current_room=newPlayer.current_room.e_to
print(f'{newPlayer.current_room}')
else:
print('no path in that direction')
if action == 'w':
if newPlayer.current_room.w_to:
newPlayer.current_room=newPlayer.current_room.w_to
print(f'{newPlayer.current_room}')
else:
print('no path in that direction')
if action == 'q':
exit()

if action == 'look':
if newPlayer.current_room.items:
for obj in newPlayer.current_room.items:
print(obj.name)
else:
print('no items in your room')

if action == 'inv':
newPlayer.print_inventory()

if action in ["take", "get"]:
for inv in newPlayer.current_room.items:
if inv.name == new_item:
newPlayer.add(inv)
newPlayer.current_room.on_take(inv)
else:
print('item is not in the room')

if action in ["drop", "d"]:
for inv in newPlayer.inventory:
if inv.name == new_item:
newPlayer.remove(inv)
newPlayer.current_room.on_drop(inv)
else:
print('item is not in inventory')




8 changes: 8 additions & 0 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Item:
def __init__(self, name, description):
self.name = name
self.description = description

def __str__(self):
return f'{self.name}, {self.description}'

28 changes: 28 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
# Write a class to hold player information, e.g. what room they are in
# currently.

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

def __str__(self):
return f"Your name is {self.name}, and you are {self.current_room}"

def add(self, item): #method or function
self.inventory.append(item)
print(f"This {item} was added to your inventory ")

def remove(self, item):
self.inventory.remove(item)
print(f"This {item} has been removed from the inventory ")

def print_inventory(self):
if len(self.inventory) == 0:
print("Inventory Empty")
for inv in self.inventory:
print(inv)





24 changes: 23 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.
from item import Item
class Room:
def __init__(self, name, description,items=[]):
self.name = name
self.description = description
self.n_to = None
self.s_to = None
self.e_to = None
self.w_to = None
self.items = items

def on_drop(self, item):
self.items.append(item)
print(f'{item} has been dropped into room ')

def on_take(self, item):
self.items.remove(item)
print(f'{item} has been taken from room ')

def __str__(self):
return f"you are in the {self.name}, {self.description} "