Package nz.ac.vuw.ecs.swen225.gp6.domain
Class Inventory
java.lang.Object
nz.ac.vuw.ecs.swen225.gp6.domain.Inventory
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCoin()increments number of coins.booleanadds a tile to first empty place in inventory.intcoins()gets number of coins.intcounts the number of a certain items tile in the inventory that satisfy the given predicate.getItems()gets the items (as an umodifiable list).booleanfinds out if the inventory has a certain typed item.booleanisFull()if the inventory is full, returns true.booleanremoveItem(TileType itemName) finds first instance of a given item type and removes it.intsize()gets the size of the inventory.toString()returns a string representation of the inventory.
-
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
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 inventoryitems- - 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
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
adds a tile to first empty place in inventory.- Returns:
- true if item was added, false if it wasn't (since its full)
-
countItem
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
finds out if the inventory has a certain typed item.- Returns:
- true if a tile type found in inv, otherwise false
-
removeItem
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
returns a string representation of the inventory. the size, and the tiles contained using their symbol character.
-