Class Inventory

java.lang.Object
com.mg105.entities.Inventory

public class Inventory extends Object
An inventory is a class that manages items
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    addItem(@NotNull Item item)
    Adds an item to the inventory.
    boolean
    has(@NotNull String itemName)
    Returns if there is at LEAST one item in inventory with itemName
    boolean
    Returns if the inventory is full.
    int
    Returns the maximum amount items allowed in the inventory
    int
    Returns the number of items in the inventory currently
    int
    numberOfItems(@NotNull String itemName)
    Returns the total number of items in the inventory that have the itemName as there name
    void
    Removes all the items from the inventory.
    boolean
    removeItem(@NotNull String itemName)
    Removes ONE instance of an item from the inventory that has the same itemName.
    boolean
    useItem(@NotNull GameState state, @NotNull String itemName, @NotNull String characterName)
    Uses the item on the given character

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Inventory

      public Inventory()
  • Method Details

    • limit

      public int limit()
      Returns the maximum amount items allowed in the inventory
      Returns:
      the maximum number of items the inventory can hold
    • numberOfItems

      public int numberOfItems()
      Returns the number of items in the inventory currently
      Returns:
      the number of items in the inventory
    • numberOfItems

      public int numberOfItems(@NotNull @NotNull String itemName)
      Returns the total number of items in the inventory that have the itemName as there name
      Parameters:
      itemName - The name of items that should be counted
      Returns:
      the number of items in inventory with that name
      See Also:
    • isFull

      public boolean isFull()
      Returns if the inventory is full. A full inventory cannot have any items added to ti.
      Returns:
      if the inventory is full.
    • addItem

      public boolean addItem(@NotNull @NotNull Item item)
      Adds an item to the inventory. An item is not added to the inventory iff the inventory is full.
      Parameters:
      item - The item to be added to the inventory
      Returns:
      whether of not the item was added to the inventory
    • removeItem

      public boolean removeItem(@NotNull @NotNull String itemName)
      Removes ONE instance of an item from the inventory that has the same itemName.
      Parameters:
      itemName - The name of item that should be removed
      Returns:
      true iff an item with itemName was removed from the inventory
      See Also:
    • removeAll

      public void removeAll()
      Removes all the items from the inventory.
    • useItem

      public boolean useItem(@NotNull @NotNull GameState state, @NotNull @NotNull String itemName, @NotNull @NotNull String characterName)
      Uses the item on the given character
      Parameters:
      state - The current state of the game
      itemName - The name of the item to use
      characterName - the character to use the item on
      Returns:
      true iff the item with a name of itemName was used
      See Also:
    • has

      public boolean has(@NotNull @NotNull String itemName)
      Returns if there is at LEAST one item in inventory with itemName
      Parameters:
      itemName - the name of item that needs to be searched for
      Returns:
      if there is an item in the inventory with a name that is itemName