Skip to content

mvp mod3 #496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
101 changes: 99 additions & 2 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from room import Room
from player import Player
from item import Item

# Declare all the rooms

room = {
'outside': Room("Outside Cave Entrance",
"North of you, the cave mount beckons"),
"""North of you, the cave mount beckons"""),

'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east."""),
Expand Down Expand Up @@ -32,7 +34,7 @@
room['narrow'].w_to = room['foyer']
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']

room['overlook'].e_to = room['treasure']
#
# Main
#
Expand All @@ -49,3 +51,98 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.
directions = ['n', 's', 'e', 'w']

player = Player("Fady", room['outside'])

print(f"Game Instructions: q is to quit, directions are n, e, s, & w.\nIf you find an item you like in a room, type get (item name).\nIf you want to drop an item from your inventory, type drop (item name)")

room['outside'].item_list.append(Item("fishing-rod", "used for fishing"))
room['foyer'].item_list.append(Item("binoculars", "used to see afar"))
room['overlook'].item_list.append(Item("sword", "sword resting in a rock, there's something weird about this thing"))
room['narrow'].item_list.append(Item("fire-wood", "sometimes nights get cold, this will keep you warm!"))
room['treasure'].item_list.append(Item("gold", "so dusty, looks like the looters didn't find everything!"))



while True:



print(player.current_room.name)
print(player.current_room.description)

if len(player.current_room.item_list) > 0:
print("items in the room: ")
for item in player.current_room.item_list:
print(f'Item name: {item.name}\nItem description: {item.description}')



user_input = input(f"{player.name} What would you like to do?? >>>>>")

if len(user_input.split()) == 1:

if user_input == 'n':
if player.current_room.n_to:
player.current_room = player.current_room.n_to
else:
print("There's nothing in that direction, try again!")
if user_input == 's':
if player.current_room.s_to:
player.current_room = player.current_room.s_to
else:
print("There's nothing in that direction, try again!")
if user_input == 'e':
if player.current_room.e_to:
player.current_room = player.current_room.e_to
else:
print("There's nothing in that direction, try again!")
if user_input == 'w':
if player.current_room.w_to:
player.current_room = player.current_room.w_to
else:
print("There's nothing in that direction, try again!")

if user_input == 'q':
exit(0)

if user_input == 'i' or 'inventory':
if len(player.inventory) > 0:
for item in player.inventory:
print(f"Item name: {item.name}\nItem description: {item.description}")
else:
print(f"No items in you inventory")

# if user_input == 'inventory':
# if len(player.inventory) > 0:
# for item in player.inventory:
# print(f"Item name: {item.name}\nItem description: {item.description}")
# else:
# print(f"No items in you inventory")

elif len(user_input.split()) == 2:

if user_input.split()[0] == 'get':
if len(player.current_room.item_list) > 0:
for item in player.current_room.item_list:
if item.name == user_input.split()[1]:
player.current_room.item_list.remove(item)
player.inventory.append(item)
else:
print(f"{user_input.split()[1]} was not found in the {player.current_room.name}")
else:
print(f"No items are available to take in {player.current_room.name}")

if user_input.split()[0] == 'drop':
if len(player.inventory) >0:
for item in player.inventory:
if item.name == user_input.split()[1]:
player.inventory.remove(item)
player.current_room.item_list.append(item)
else:
print(f"{user_input.split()[1]} in not in the your inventory")
else:
print(f"There are no items to drop!")
else:
print("Your input is invalid")
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

def __str__(self):
return f"Name: {self.name}, Description: {self.description} "
17 changes: 17 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# 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):
player_string = f"Player is in the {self.current_room}"

def move(self, direction):
next_room = self.current_room.get_direction(direction)
if next_room is not None:
self.current_room = next_room
else:
print("There's no room in that direction!")


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

class Room:
def __init__(self, name, description):
self.name = name
self.description = description
self.n_to = None
self.s_to = None
self.e_to = None
self.w_to = None
self.item_list = []

def __str__(self):
ret = f"{self.name}\n"
for i, c in enumerate(self.item_list):
ret += " " + str(i+1) + ": " + c.name +"\n"
ret += " " + str(1+2) + ": Exit"

return ret

def get_direction(self, direction):
if direction == 'n':
return self.n_to
elif direction == 's':
return self.s_to
elif direction == 'e':
return self.e_to
elif direction == 'w':
return self.w_to
else:
return None