Package com.bdtripp.hauntedhouse.model
Class Inventory
java.lang.Object
com.bdtripp.hauntedhouse.model.Inventory
Represents a collection of items carried by the player.
The inventory stores items, enforces carry‑weight limits, and provides operations for adding,
removing, and querying items.
- Author:
- Brian Tripp
-
Constructor Summary
ConstructorsConstructorDescriptionInventory(int maxCarryWeight) Creates a new inventory with the specified maximum carry weight. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an item to the inventoryReturns an item in the inventoryintCalculates the total weight of all items currently in the inventory.Produces a formatted description of all items in the inventory.intReturns the maximum weight that the player can carrybooleanChecks if a particular item is in the inventoryremoveItem(Item item) Removes an item from the inventoryvoidsetMaxCarryWeight(int max) Updates the maximum weight the player is allowed to carry.
-
Constructor Details
-
Inventory
public Inventory(int maxCarryWeight) Creates a new inventory with the specified maximum carry weight.- Parameters:
maxCarryWeight- the maximum weight the player can carry
-
-
Method Details
-
setMaxCarryWeight
public void setMaxCarryWeight(int max) Updates the maximum weight the player is allowed to carry.- Parameters:
max- the new maximum carry weight
-
getMaxCarryWeight
public int getMaxCarryWeight()Returns the maximum weight that the player can carry- Returns:
- the maximum weight
-
addItem
Adds an item to the inventory- Parameters:
item- the item add
-
removeItem
Removes an item from the inventory- Parameters:
item- the item to remove- Returns:
- the item that was removed
-
getCurrentCarryWeight
public int getCurrentCarryWeight()Calculates the total weight of all items currently in the inventory.- Returns:
- the combined weight of all carried items
-
findItem
Returns an item in the inventory- Parameters:
name- the name of the item- Returns:
- The item
-
hasItem
Checks if a particular item is in the inventory- Parameters:
item- the item to check- Returns:
- true if the item is in the inventory
-
getItemDetails
Produces a formatted description of all items in the inventory.- Returns:
- a multi-line string listing item names, descriptions, and weights
-