java.lang.Object
com.adventure.models.Inventory
Class used to handle an inventory of items.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add item to the inventoryDrop an item and remove it from the inventoryDrop an item and remove it from the inventoryboolean
void
Equip an equipable itemint
Get the value of the current weight in the inventory.Get the equipped attack item.Get the equipped defence item.getItems()
Get a copy of the ArrayList containing all the items.int
Get the value of max weight the inventory can handle.itemsByName
(String name) Method to obtain an item instance from its namevoid
setCurrentWeight
(int currentWeight) Set the current weight in the inventory.void
Set all items in the inventory.void
setMaxWeight
(int maxWeight) Set max weight the inventory can hold.void
Unequip an attack or defense item
-
Constructor Details
-
Inventory
public Inventory(int maxWeight) Default constructor.- currentWeight: 0
- attackItem: hands
- defenceItem: hands
- Parameters:
maxWeight
- Max weight the inventory can have.
-
-
Method Details
-
getEquipedAttackItem
Get the equipped attack item.- Returns:
- AttackItem equipped.
-
getEquipedDefenceItem
Get the equipped defence item.- Returns:
- DefenceItem equipped.
-
getMaxWeight
public int getMaxWeight()Get the value of max weight the inventory can handle.- Returns:
- max weight of the inventory.
-
getCurrentWeight
public int getCurrentWeight()Get the value of the current weight in the inventory.- Returns:
- current weight in the inventory.
-
getItems
Get a copy of the ArrayList containing all the items.- Returns:
- ArrayList with all items of the inventory.
-
setMaxWeight
public void setMaxWeight(int maxWeight) Set max weight the inventory can hold.- Parameters:
maxWeight
- value of max weight.
-
setCurrentWeight
public void setCurrentWeight(int currentWeight) Set the current weight in the inventory.- Parameters:
currentWeight
- value of the current weight.
-
setItems
Set all items in the inventory.- Parameters:
items
- ArrayList containing all the items.- Throws:
TooMuchWeightException
- If the weight is over maxWeight.
-
equipItem
Equip an equipable item- Parameters:
equipable
- Item to equip
-
unequipItem
Unequip an attack or defense item- Parameters:
type
- Type of the item to unequip (ATTACK or DEFENSE)
-
addItem
Add item to the inventory- Parameters:
item
- Item to add- Throws:
TooMuchWeightException
- The item weights too much for the current inventory
-
itemsByName
Method to obtain an item instance from its name- Parameters:
name
- Name of the item to search- Returns:
- ArrayList with all the items with the same name
-
dropItem
Drop an item and remove it from the inventory- Parameters:
item
- Item to be removed
-
dropItem
Drop an item and remove it from the inventory- Parameters:
itemName
- Item to remove.- Returns:
- The removed item.
- Throws:
NoSuchElementException
- If the item is not present.
-
equals
-