Skip to content
Snippets Groups Projects
Commit 062ca33e authored by Harry Wyatt's avatar Harry Wyatt
Browse files

Updated game.py to allow interaction of non-pickup-able items like chests and...

Updated game.py to allow interaction of non-pickup-able items like chests and enforces pickup/put down restrictions
parent d2f5ced6
No related branches found
No related tags found
No related merge requests found
......@@ -382,10 +382,15 @@ def print_menu(exits, room_items, inv_items):
print_exit(direction, exit_leads_to(exits, direction))
for item in room_items:
print("TAKE", item.id.upper(), "to take a", item.name + ".")
if item.can_pickup is True:
print("TAKE", item.id.upper(), "to take a", item.name + ".")
elif item.on_interaction is not None:
# In this case, it's an item we must interact with in the game space as it cannot be picked up
print(f"INTERACT {item.id.upper()} {item.on_interaction_description}.")
for item in inv_items:
print("DROP", item.id.upper(), "to drop your", item.name + ".")
if item.can_place is True:
print("DROP", item.id.upper(), "to drop your", item.name + ".")
print("INVENTORY to view your inventory")
print("MAP to view the map")
......@@ -403,7 +408,7 @@ def execute_go(direction):
def execute_take(item_id):
for item in player.current_room.items:
if item.id == item_id:
if item.id == item_id and item.can_pickup is True:
player.inventory.append(item)
player.current_room.items.remove(item)
return
......@@ -412,13 +417,22 @@ def execute_take(item_id):
def execute_drop(item_id):
for item in player.inventory:
if item.id == item_id:
if item.id == item_id and item.can_place is True:
player.inventory.remove(item)
player.current_room.items.append(item)
return
print("You cannot drop that")
def execute_interact(item_id):
for item in player.current_room.items:
if item.id == item_id and item.on_interaction is not None and not item.can_pickup:
# We need to check the item can't be picked up as then the on_interation is dedicated to use inside the inv
item.on_interaction(player)
return
print("You cannot interact with that")
def execute_command(command):
"""This function takes a command (a list of words as returned by
normalise_input) and, depending on the type of action (the first word of
......@@ -456,7 +470,10 @@ def execute_command(command):
elif command[0] == "help":
display_help()
elif command[0] == "interact":
execute_interact(command[1])
else:
print("This makes no sense.")
......@@ -480,7 +497,7 @@ def move(exits, direction):
def main():
# Generate random items in each room before we start the game
populate_rooms()
print("You suddenly wake up in an ancient abandoned manner house. Every window boarded, every door to the real world locked...")
print("The old house finds itself inhabited by a plethora of strange monsters, of which many seem violent. It is up to you...")
print("to trek forward and find a way out with what little you have - avoiding death as if it were around every corner.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment