take and inventory command

This commit is contained in:
jslightham
2019-05-16 22:40:55 -04:00
parent 4506c1e17f
commit 2781520ba5
5 changed files with 66 additions and 29 deletions

View File

@@ -14,20 +14,10 @@ public class Player extends Entity{
super();
}
public boolean addToInventory(String item){
Class<?> clazz;
Item object;
try {
clazz = Class.forName("com.bayviewglen.zork.Items." + item.trim());
Constructor<?> ctor = clazz.getConstructor();
object = (Item) ctor.newInstance();
if(currentInventoryWeight + object.getWeight() < INVENTORY_CAPACITY){
inventory.add(object);
return true;
}
} catch (Exception e) {
return false;
public boolean addToInventory(Item item){
if(currentInventoryWeight + item.getWeight() < INVENTORY_CAPACITY){
inventory.add(item);
return true;
}
return false;
}
@@ -36,5 +26,9 @@ public class Player extends Entity{
inventory.remove(item);
}
public ArrayList<Item> getInventory() {
return inventory;
}
}