From a3f6ce16e722e6d26f3ce1809a6a4f4937debe9b Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 6 Apr 2014 15:12:53 +0200 Subject: Implements player's inventory listing --- src/esieequest/controller/Interpreter.java | 3 +++ src/esieequest/controller/Performer.java | 7 +++++++ src/esieequest/model/items/Inventory.java | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/src/esieequest/controller/Interpreter.java b/src/esieequest/controller/Interpreter.java index 8d0f703..ea01fd7 100644 --- a/src/esieequest/controller/Interpreter.java +++ b/src/esieequest/controller/Interpreter.java @@ -72,6 +72,9 @@ class Interpreter { case "eat": this.performer.eat(); return; + case "inventory": + this.performer.listItems(); + return; case "take": this.performer.take(command.getOption()); return; diff --git a/src/esieequest/controller/Performer.java b/src/esieequest/controller/Performer.java index 466f9da..7f41109 100644 --- a/src/esieequest/controller/Performer.java +++ b/src/esieequest/controller/Performer.java @@ -178,4 +178,11 @@ class Performer { dest.putItem(itemName, source.takeItem(itemName)); } + /** + * Lists the items contained in the player's inventory. + */ + public void listItems() { + this.echo(Utils.list(this.game.getPlayer().getInventory().getItemList(), "Items:", "No item in your inventory.")); + } + } diff --git a/src/esieequest/model/items/Inventory.java b/src/esieequest/model/items/Inventory.java index 86e86b5..228386e 100644 --- a/src/esieequest/model/items/Inventory.java +++ b/src/esieequest/model/items/Inventory.java @@ -74,6 +74,13 @@ public class Inventory { return Utils.list(this.items.keySet(), "Items:", "No items."); } + /** + * Returns the weight of the given item referred by its name. + * + * @param itemName + * the item's name + * @return + */ public int getItemWeight(final String itemName) { return this.items.get(itemName).getWeight(); } -- cgit v1.2.3