@Test public void testAddItem() { TestHelper.load(); Inventory inv = new Inventory(); assertTrue(inv.addItem(5, "tester")); assertTrue(inv.getItemID(generalArray, numItemsGeneral).equals("tester")); assertTrue(inv.getItemQuantity(generalArray, numItemsGeneral) == 5); assertTrue(inv.addItem(5, "tester")); assertTrue(inv.getItemID(generalArray, numItemsGeneral).equals("tester")); assertTrue(inv.getItemQuantity(generalArray, numItemsGeneral) == 10); for (int i = 0; i < inv.sizeOfGeneralArray(); i++) { inv.placeItem(generalArray, i, "potion1", 1); } assertTrue(inv.isFull(generalArray)); assertTrue(!inv.addItem(5, "tester")); inv.clearInvSlot(generalArray, 0); inv.clearInvSlot(generalArray, 1); inv.placeItem(generalArray, 0, "tester", 14); assertTrue(inv.addItem(1, "tester")); assertTrue(inv.getItemID(generalArray, 0).equals("tester")); assertTrue(inv.getItemQuantity(generalArray, 0) == 15); assertTrue(inv.addItem(3, "tester")); assertTrue(inv.getItemID(generalArray, 0).equals("tester")); assertTrue(inv.getItemQuantity(generalArray, 0) == 15); assertTrue(inv.getItemID(generalArray, 1).equals("tester")); assertTrue(inv.getItemQuantity(generalArray, 1) == 3); inv.clearInvSlot(generalArray, 1); inv.placeItem(generalArray, 0, "tester", 16); inv.placeItem(generalArray, 2, "tester", 14); assertTrue(inv.getItemID(generalArray, 0).equals("tester")); assertTrue(inv.getItemID(generalArray, 1).equals("emptyslot")); assertTrue(inv.getItemID(generalArray, 2).equals("tester")); assertTrue(inv.getItemQuantity(generalArray, 2) == 14); assertTrue(inv.addItem(1, "tester")); assertTrue(inv.getItemQuantity(generalArray, 2) == 15); inv.placeItem(generalArray, 1, "Gun1", 1); assertTrue(inv.getItemID(generalArray, 1).equals("Gun1")); inv.addItem(1, "Gun1"); assertTrue(inv.getItemQuantity(generalArray, 1) == 1); }
public boolean addItem(int quantity, String itemID) { InventoryPair emptyPair = new InventoryPair(0, ItemRegistry.getItem(EMPTY_SLOT)); InventoryPair newItemPair = new InventoryPair(quantity, ItemRegistry.getItem(itemID)); for (int i = 0; i < generalInventory.length; i++) { if ((generalInventory[i].getItem().getID().equals(itemID)) && generalInventory[i].getItem().isStackable() && generalInventory[i].addQuantity(quantity)) { return true; } } for (int i = 0; i < generalInventory.length; i++) { if (generalInventory[i].equalPair(emptyPair)) { generalInventory[i] = newItemPair; return true; } } return false; }
Inventory { public boolean addItem(int quantity, String itemID) { InventoryPair emptyPair = new InventoryPair(0, ItemRegistry.getItem(EMPTY_SLOT)); InventoryPair newItemPair = new InventoryPair(quantity, ItemRegistry.getItem(itemID)); for (int i = 0; i < generalInventory.length; i++) { if ((generalInventory[i].getItem().getID().equals(itemID)) && generalInventory[i].getItem().isStackable() && generalInventory[i].addQuantity(quantity)) { return true; } } for (int i = 0; i < generalInventory.length; i++) { if (generalInventory[i].equalPair(emptyPair)) { generalInventory[i] = newItemPair; return true; } } return false; } }
Inventory { public boolean addItem(int quantity, String itemID) { InventoryPair emptyPair = new InventoryPair(0, ItemRegistry.getItem(EMPTY_SLOT)); InventoryPair newItemPair = new InventoryPair(quantity, ItemRegistry.getItem(itemID)); for (int i = 0; i < generalInventory.length; i++) { if ((generalInventory[i].getItem().getID().equals(itemID)) && generalInventory[i].getItem().isStackable() && generalInventory[i].addQuantity(quantity)) { return true; } } for (int i = 0; i < generalInventory.length; i++) { if (generalInventory[i].equalPair(emptyPair)) { generalInventory[i] = newItemPair; return true; } } return false; } Inventory(); }
Inventory { public boolean addItem(int quantity, String itemID) { InventoryPair emptyPair = new InventoryPair(0, ItemRegistry.getItem(EMPTY_SLOT)); InventoryPair newItemPair = new InventoryPair(quantity, ItemRegistry.getItem(itemID)); for (int i = 0; i < generalInventory.length; i++) { if ((generalInventory[i].getItem().getID().equals(itemID)) && generalInventory[i].getItem().isStackable() && generalInventory[i].addQuantity(quantity)) { return true; } } for (int i = 0; i < generalInventory.length; i++) { if (generalInventory[i].equalPair(emptyPair)) { generalInventory[i] = newItemPair; return true; } } return false; } Inventory(); int sizeOfActiveArray(); int sizeOfPassiveArray(); int sizeOfGeneralArray(); boolean isFull(String itemArray); boolean addItem(int quantity, String itemID); boolean placeItem(String itemArray, int slotNumber, String itemID, int quantity); boolean removeItem(int quantity, String itemID); boolean clearInvSlot(String itemArray, int slotNumber); boolean itemExists(String itemID); int getAmount(String itemID); String getItemID(String itemArray, int slotNumber); int getItemQuantity(String itemArray, int slotNumber); static String getItemInfo(String id, String request); static ItemType getItemType(String id); static ArmourType getArmourType(String id); Image getSprite(String id); boolean swapItem(String firstArray, int firstSlot, String secondArray, int secondSlot, boolean stack); boolean checkArrayInBounds(InventoryPair[]  array, int slotToCheck); boolean reduceActiveConsumable(int slotNumber); boolean checkActiveAmount(int playerLevel, boolean equip); static boolean checkLevelRestrictionsActive(int playerLevel, int activeAmount); boolean checkItem(String id); }
Inventory { public boolean addItem(int quantity, String itemID) { InventoryPair emptyPair = new InventoryPair(0, ItemRegistry.getItem(EMPTY_SLOT)); InventoryPair newItemPair = new InventoryPair(quantity, ItemRegistry.getItem(itemID)); for (int i = 0; i < generalInventory.length; i++) { if ((generalInventory[i].getItem().getID().equals(itemID)) && generalInventory[i].getItem().isStackable() && generalInventory[i].addQuantity(quantity)) { return true; } } for (int i = 0; i < generalInventory.length; i++) { if (generalInventory[i].equalPair(emptyPair)) { generalInventory[i] = newItemPair; return true; } } return false; } Inventory(); int sizeOfActiveArray(); int sizeOfPassiveArray(); int sizeOfGeneralArray(); boolean isFull(String itemArray); boolean addItem(int quantity, String itemID); boolean placeItem(String itemArray, int slotNumber, String itemID, int quantity); boolean removeItem(int quantity, String itemID); boolean clearInvSlot(String itemArray, int slotNumber); boolean itemExists(String itemID); int getAmount(String itemID); String getItemID(String itemArray, int slotNumber); int getItemQuantity(String itemArray, int slotNumber); static String getItemInfo(String id, String request); static ItemType getItemType(String id); static ArmourType getArmourType(String id); Image getSprite(String id); boolean swapItem(String firstArray, int firstSlot, String secondArray, int secondSlot, boolean stack); boolean checkArrayInBounds(InventoryPair[]  array, int slotToCheck); boolean reduceActiveConsumable(int slotNumber); boolean checkActiveAmount(int playerLevel, boolean equip); static boolean checkLevelRestrictionsActive(int playerLevel, int activeAmount); boolean checkItem(String id); static final String ACTIVE_ARRAY; static final int ACTIVE_SIZE; static final String PASSIVE_ARRAY; static final int PASSIVE_SIZE; static final String GENERAL_ARRAY; static final int GENERAL_SIZE; }