Class Inventory

java.lang.Object
nz.ac.vuw.ecs.swen225.gp6.domain.Inventory

public class Inventory extends Object
The Inventory class represents the space that a player holds items that they have picked up. Each level has a separate inventory.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Inventory(int size)
    constructor for making an inventory with specified size, items are all Null tile type, and the coins are 0.
    Inventory(int size, int coins, List<Tile> items)
    constructor for making an inventory with specified size and items, and the number of coins.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    increments number of coins.
    boolean
    addItem(Tile tile)
    adds a tile to first empty place in inventory.
    int
    gets number of coins.
    int
    counts the number of a certain items tile in the inventory that satisfy the given predicate.
    gets the items (as an umodifiable list).
    boolean
    hasItem(TileType itemName)
    finds out if the inventory has a certain typed item.
    boolean
    if the inventory is full, returns true.
    boolean
    removeItem(TileType itemName)
    finds first instance of a given item type and removes it.
    int
    gets the size of the inventory.
    returns a string representation of the inventory.

    Methods inherited from class java.lang.Object

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

    • Inventory

      public Inventory(int size)
      constructor for making an inventory with specified size, items are all Null tile type, and the coins are 0.
      Parameters:
      size - - size of inventory. The number of items the user can carry at once.
      Throws:
      IllegalArgumentException - - if size is less than 0
    • Inventory

      public Inventory(int size, int coins, List<Tile> items)
      constructor for making an inventory with specified size and items, and the number of coins.
      Parameters:
      size - - size of inventory. The number of items the user can carry at once.
      coins - - the number of coins the inventory
      items - - the items that are in inventory (all empty spots will be filled with Null type tiles)
      Throws:
      IllegalArgumentException - if size is less than 1, or coins are negative, or list of items is null or bigger than size
  • Method Details

    • getItems

      public List<Tile> getItems()
      gets the items (as an umodifiable list).
      Returns:
      list of tiles in inventory (it will not include the Null type tiles)
    • isFull

      public boolean isFull()
      if the inventory is full, returns true.
      Returns:
      true if inventory is full, false otherwise
    • size

      public int size()
      gets the size of the inventory.
      Returns:
      the size of the inventory
    • coins

      public int coins()
      gets number of coins.
      Returns:
      number of coins
    • addCoin

      public void addCoin()
      increments number of coins.
    • addItem

      public boolean addItem(Tile tile)
      adds a tile to first empty place in inventory.
      Returns:
      true if item was added, false if it wasn't (since its full)
    • countItem

      public int countItem(Predicate<Tile> p)
      counts the number of a certain items tile in the inventory that satisfy the given predicate.
      Parameters:
      p - - the predicate
      Returns:
      the number of items in the inventory that satisfy p
    • hasItem

      public boolean hasItem(TileType itemName)
      finds out if the inventory has a certain typed item.
      Returns:
      true if a tile type found in inv, otherwise false
    • removeItem

      public boolean removeItem(TileType itemName)
      finds first instance of a given item type and removes it. Returns true if an item was found and removed otherwise false.
      Parameters:
      itemName - - the item type to remove.
      Returns:
      true if item type was found and removed, otherwise false
    • toString

      public String toString()
      returns a string representation of the inventory. the size, and the tiles contained using their symbol character.
      Overrides:
      toString in class Object
      Returns:
      a string representation of inventory.