From fee338aad3a8da01ae3caed4f33e4e777bac266e Mon Sep 17 00:00:00 2001 From: thepersonwithears Date: Sun, 3 Nov 2024 21:15:32 +0000 Subject: [PATCH] Added command to see inventory by typing "inventory" and it shows all items in the player.py inventory. --- dungeontext_lib/game.py | 4 ++++ dungeontext_lib/player.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/dungeontext_lib/game.py b/dungeontext_lib/game.py index d984425..5dc1123 100644 --- a/dungeontext_lib/game.py +++ b/dungeontext_lib/game.py @@ -4,6 +4,7 @@ from .utils import Clear from .utils import Commands + class Game: def __init__(self, player): self.player = player @@ -21,6 +22,9 @@ def interpret(self, command): elif command == "help": Clear() Commands() + elif command == "inventory": + Clear() + self.player.Show_Inventory() def take_item(self, item_name): item = next((i for i in self.player.current_room.items if i.name == item_name), None) if item: diff --git a/dungeontext_lib/player.py b/dungeontext_lib/player.py index d81e00f..5b81121 100644 --- a/dungeontext_lib/player.py +++ b/dungeontext_lib/player.py @@ -13,3 +13,12 @@ def move(self, direction): else: Clear() print("You can't go that way.") + + + def Show_Inventory(self): + if self.inventory: + print("You are carrying:") + for item in self.inventory: + print(f"- {item.name}") + else: + print("You are not carrying anything.") \ No newline at end of file