Class Inventory

java.lang.Object
com.bdtripp.hauntedhouse.model.Inventory

public class Inventory extends Object
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 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

      public void addItem(Item item)
      Adds an item to the inventory
      Parameters:
      item - the item add
    • removeItem

      public Item removeItem(Item item)
      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

      public Item findItem(String name)
      Returns an item in the inventory
      Parameters:
      name - the name of the item
      Returns:
      The item
    • hasItem

      public boolean hasItem(Item item)
      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

      public String getItemDetails()
      Produces a formatted description of all items in the inventory.
      Returns:
      a multi-line string listing item names, descriptions, and weights