java.lang.Object
com.deco2800.game.components.player.entity.Backpack
All Implemented Interfaces:
Inventory

public class Backpack extends Object implements Inventory
  • Field Details

  • Constructor Details

    • Backpack

      public Backpack()
  • Method Details

    • contains

      public boolean contains(int id)
      Description copied from interface: Inventory
      Check if a specific item is present in the backpack
      Specified by:
      contains in interface Inventory
      Parameters:
      id - item id
      Returns:
      true if the quantity of the item in stock is greater than zero
    • contains

      public boolean contains(String itemName)
      Description copied from interface: Inventory
      Check if a specific item is present in the backpack
      Specified by:
      contains in interface Inventory
      Parameters:
      itemName - item name
      Returns:
      true if the quantity of the item in stock is greater than zero
    • count

      public int count(int id)
      Description copied from interface: Inventory
      Quantity of a specific item
      Specified by:
      count in interface Inventory
      Parameters:
      id - item id
      Returns:
      the quantity of the item or -1 if the item id is not exist.
    • count

      public int count(String itemName)
      Description copied from interface: Inventory
      Quantity of a specific item
      Specified by:
      count in interface Inventory
      Parameters:
      itemName - item name
      Returns:
      the quantity of the item or -1 if the item name is not exist.
    • add

      public boolean add(int id)
      Description copied from interface: Inventory
      Add an item with a specified id
      Specified by:
      add in interface Inventory
      Parameters:
      id - item id
      Returns:
      true if add successfully
    • add

      public boolean add(int id, int num)
      Description copied from interface: Inventory
      Add several of this item
      Specified by:
      add in interface Inventory
      Parameters:
      id - item id
      num - the number of the added item
      Returns:
    • remove

      public boolean remove(int id)
      Remove an item with this id
      Specified by:
      remove in interface Inventory
      Parameters:
      id - item id
      Returns:
      true if remove an item of this id successfully
    • add

      public boolean add(String itemName)
      Description copied from interface: Inventory
      Add an item with a specified id
      Specified by:
      add in interface Inventory
      Parameters:
      itemName - item name
      Returns:
      true if add successfully
    • add

      public boolean add(String itemName, int num)
      Description copied from interface: Inventory
      Add several of this item
      Specified by:
      add in interface Inventory
      Parameters:
      itemName - item name
      num - the number of the added item
      Returns:
    • remove

      public boolean remove(String itemName)
      Description copied from interface: Inventory
      remove a specified item
      Specified by:
      remove in interface Inventory
      Parameters:
      itemName - item name
      Returns:
      true if remove successfully
    • remove

      public boolean remove(int id, int num)
      Specified by:
      remove in interface Inventory
    • remove

      public boolean remove(String itemName, int num)
      Specified by:
      remove in interface Inventory
    • getInStockItemIds

      public List<Integer> getInStockItemIds()
      Specified by:
      getInStockItemIds in interface Inventory
    • toString

      public String toString()
      Overrides:
      toString in class Object