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
69 changes: 62 additions & 7 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
from room import Room
from player import Player
from item import Item

# Declare all the items
# bat = Item('bat', 'wilson wood')
# ball = Item('ball', 'bouncy ball')
# knife = Item('knife', 'sharp')

# items = {
# 'bat': Item('bat', 'wilson wood'),
# 'ball': Item('ball', 'bouncy ball'),
# 'knife': Item('knife', 'sharp')
# }

# Declare all the rooms

room = {
'outside': Room("Outside Cave Entrance",
"North of you, the cave mount beckons"),
"""North of you, the cave mount beckons""", [Item("bat", "wilson wood"), Item("ball", "bouncy ball")]),

'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east."""),
Expand All @@ -22,7 +34,6 @@
earlier adventurers. The only exit is to the south."""),
}


# Link rooms together

room['outside'].n_to = room['foyer']
Expand All @@ -43,34 +54,54 @@
player = Player('outside')
print(room[player.location].name)
print(room[player.location].description)
print(room[player.location].items)


def goNorth():
room[player.location] = room[player.location].n_to
if room[player.location] != 0:
print("\n")
print(room[player.location].name)
print(room[player.location].description)
print(room[player.location].items)


def goEast():
room[player.location] = room[player.location].e_to
if room[player.location] != 0:
print("\n")
print(room[player.location].name)
print(room[player.location].description)
print(room[player.location].items)


def goSouth():
room[player.location] = room[player.location].s_to
if room[player.location] != 0:
print("\n")
print(room[player.location].name)
print(room[player.location].description)
print(room[player.location].items)


def goWest():
room[player.location] = room[player.location].w_to
if room[player.location] != 0:
print("\n")
print(room[player.location].name)
print(room[player.location].description)
print(room[player.location].items)


# def pickupItem():
# # check if item exists in the room
# # append item to self.items list
# player.items.append(player.location.items[0])
# remove it from the current room inventory
# self.location.items.pop(item)

# def pickupItem0():
# player.items.append(room[player.location].items[0])

# print(player)

Expand Down Expand Up @@ -106,20 +137,44 @@ def goWest():
goSouth()

elif selection == 'w':
goWest()
goWest()

elif selection == '1':
player.pickupItem(room[player.location].items[0].name,
room[player.location].items[0].description)
print("\n")
print("Congrats, you picked up " + player.items[0].name)

elif selection == '2':
player.dropItem()
print("\n")
print("Bye bye...you dropped " +
room[player.location].items[0].name)

elif selection == '3':
player.pickupItem(room[player.location].items[1].name,
room[player.location].items[1].description)
print("\n")
print("Congrats, you picked up " + player.items[1].name)

elif selection == '4':
player.dropItem()
print("\n")
print("Bye bye...you dropped " +
room[player.location].items[1].name)

else:
print("\n")
print("Please input only the letter n, e, s, or w of the cardinal direction you'd like to move or type q to exit the game ")
print("Please input only the letter n, e, s, or w of the cardinal direction you'd like to move, input to take or drop an item with it's name, or type q to exit the game ")

except AttributeError:
print("\n")
print("Sorry, you've hit a wall, try another direction")

# Print an error message if the movement isn't allowed.
#
# branch table
#
#
# create a dictionary with n/s/e/w as keys and then make key equal to whatever function
# dic[selection]()
# "e": goEast
Expand Down Expand Up @@ -147,4 +202,4 @@ def goWest():
# ir = OP2
# self.branchtable[ir]("bar")
# c = Foo()
# c.run()
# c.run()
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"item {self.name} which is described as: {self.description}"

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

class Player():
from item import Item

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

def pickupItem(self, item_name, item_description):
# check if item exists in the room
# append item to self.items list
self.items.append(Item(item_name, item_description))
self.location.items.remove(Item(item_name, item_description))
# remove it from the current room inventory
# self.location.items.pop(item)

def dropItem(self):
self.items.remove(self.items[0])
self.location.items.append(self.items[0])
# check if item exists in the player's inventory
# append item to room items list
# remove it from the players inventory
15 changes: 12 additions & 3 deletions src/room.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# Implement a class to hold room information. This should have name and
# description attributes.

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

# need a method to be able to add an item to the room
def addItem(self, itemName):
pass

# need a method to be able to remove an item from the room
def removeItem(self, itemName):
pass

def __str__(self):
return f"room {self.name} which is described as: {self.description}"
return f"room {self.name} which is described as: {self.description} and has the following items available: {self.items}"