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.

116 changes: 99 additions & 17 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,52 @@
from room import Room

from player import Player
from item import Item
# Declare all the rooms

items = [
Item("potion", """Heals your wounds"""),
Item("sword", """To fight the bad guys"""),
Item("shoe", """Looks like someone left this here"""),
Item("gold", """Congratulations!"""),
]

# room = {
# 'outside': Room("Outside Cave Entrance", """North of you, the cave mount beckons.""",Item("No items", """---""")),

# 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
# passages run north and east.""", Item("a potion", """Heals your wounds""")),

# '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.""", Item("a sword", """To fight the bad guys""")),

# 'narrow': Room("Narrow Passage", """The narrow passage bends here from west
# to north. The smell of gold permeates the air.""", Item("an old shoe", """Looks like someone left this here""")),

# '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.""", Item("gold", """Congratulations!""")),
# }
room = {
'outside': Room("Outside Cave Entrance",
"North of you, the cave mount beckons"),
'outside': Room("Outside Cave Entrance", """North of you, the cave mount beckons.""", items[0]),

'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east."""),
passages run north and east.""", items[0]),

'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.""", items[1]),

'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.""", items[2]),

'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.""", items[3]),
}



# Link rooms together

room['outside'].n_to = room['foyer']
Expand All @@ -33,19 +58,76 @@
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']


#
# Main
#

print("\nWelcome to adventure time!\n")
# Make a new player object that is currently in the 'outside' room.
player = Player(input("\nName: "), room['outside'], '')

# 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.

player.items = []
print("\n\nWelcome", player.name)

# def on_take(item):
# if
while True:

print("\nYour position is currently: ", player.current_room.name)
print("\nThe description of your surroundings is: ", player.current_room.description)

choice = input("\n\nPlease enter [n] North [s] South [e] East [w] West to move [i/inventory] Inventory or [q] Quit \n")



if choice == 'n':
if player.current_room.n_to is not None:
print("\nYou moved north!\n")

player.current_room = player.current_room.n_to
print("Item: ", player.current_room.item)
else:
print("You're going the wrong way! Try again.")
elif choice == 's':
if player.current_room.s_to is not None:
print("\nYou moved south!\n")

player.current_room = player.current_room.s_to
print("Item: ", player.current_room.item)
else:
print("\nYou're going the wrong way! Try again.")
elif choice == 'e':
if player.current_room.e_to is not None:
print("\nYou moved east!\n")

player.current_room = player.current_room.e_to
print("Item: ", player.current_room.item)
else:
print("\nYou're going the wrong way! Try again.")
elif choice == 'w':
if player.current_room.w_to is not None:
print("\nYou moved west!\n")

player.current_room = player.current_room.w_to
print("Item: ", player.current_room.item)
else:
print("\nYou're going the wrong way! Try again.")
elif choice == 'take':
player.items.append(player.current_room.item.name)
player.current_room.item = None
print("You took an item!")
elif choice == 'drop':
player.items.pop()
print("You dropped an item!")
elif choice == 'inventory' or choice == 'i':
stuff = ""+", ".join(player.items)
print(f"\nYour inventory: {stuff}")
elif choice == 'q':
print("\nThanks for playing!\n")
break
else:
print("\nInvalid input, please use 'n', 's', 'e', 'w")


7 changes: 7 additions & 0 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Item:
def __init__(self, name, description):
self.name = name
self.description = description
# self.room = room
def __str__(self):
return f"{self.name} \nDescription: {self.description}"
6 changes: 6 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# Write a class to hold player information, e.g. what room they are in
# currently.
class Player():
def __init__(self, name, current_room, items ):
self.name = name
self.current_room = current_room
self.items = items

13 changes: 12 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.

#added none because getting typeerror that init is missing 4 required positional arguments
class Room():
def __init__(self, name, description, item):
self.name = name
self.description = description
self.n_to = None
self.s_to = None
self.e_to = None
self.w_to = None
self.item = item