Package it.polimi.ingsw.model
Class Warehouse
java.lang.Object
it.polimi.ingsw.model.Warehouse
- All Implemented Interfaces:
WarehouseUpdateObservable
public class Warehouse extends java.lang.Object implements WarehouseUpdateObservable
Represents the warehouse of player.
A warehouse can contain a limited amount of resources organized on limited number of level, each of them containing a single type of resource.
The number of resources that each level can contain decrease from maximum in the level zero to one in the last level.
A warehouse can't contain faith.
-
Constructor Summary
Constructors Constructor Description Warehouse() -
Method Summary
Modifier and Type Method Description intaddLeaderCardLevel(ResourceType resourceType)Create a new special level in warehouse for a leader card of type storagevoidaddResource(ResourceType resource)Add one resource of the specified resource type into warehouseintgetNumberOf(ResourceType resource)Returns the total amount of the specified resources contained in the warehouseintmaxLeaderCardsLevels()voidnotifyWarehouseUpdate(WarehouseUpdate msg)Notify the model observers that Warehouse state has changed Along with the notification sends the proper update Object as further explained in project documentationintnumberOfAllLevels()intnumberOfLeaderCardsLevels()intnumberOfNormalLevels()intremoveResources(ResourceType resourceType, int quantity)Remove from warehouse all the possible resources of specified resource type up to a maximum of the specified quantityvoidsetController(ModelObserver controller)inttotalResources()Returns the total amount of resources contained in the warehouseMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Warehouse
public Warehouse()
-
-
Method Details
-
maxLeaderCardsLevels
public int maxLeaderCardsLevels()- Returns:
- the maximum number of leader card's levels that this warehouse can contain
-
numberOfNormalLevels
public int numberOfNormalLevels()- Returns:
- the number of normal levels in this warehouse
-
numberOfLeaderCardsLevels
public int numberOfLeaderCardsLevels()- Returns:
- the current number of leader card's level in this warehouse
-
numberOfAllLevels
public int numberOfAllLevels()- Returns:
- the total number of levels in this warehouse
-
addLeaderCardLevel
public int addLeaderCardLevel(ResourceType resourceType) throws MaxLeaderCardLevelsException, AbuseOfFaithExceptionCreate a new special level in warehouse for a leader card of type storage- Parameters:
resourceType- the resource type of the storage leader card to activate- Returns:
- index of the level created
- Throws:
MaxLeaderCardLevelsException- the maximum number of leader card's levels has already been added. It is not possible to add another one.AbuseOfFaithException- resource type is faith, a warehouse can't contain faith
-
addResource
public void addResource(ResourceType resource) throws AbuseOfFaithException, NotEnoughSpaceExceptionAdd one resource of the specified resource type into warehouse- Parameters:
resource- the resource type to add- Throws:
NotEnoughSpaceException- there isn't enough space for adding this resource, it can't be added.AbuseOfFaithException- resource type is faith, faith can't be added into warehousejava.lang.NullPointerException- the specified resource is null
-
removeResources
public int removeResources(ResourceType resourceType, int quantity) throws NegativeQuantityExceptionRemove from warehouse all the possible resources of specified resource type up to a maximum of the specified quantity- Parameters:
resourceType- the type of the resource to removequantity- the maximum number of resources to remove- Returns:
- the number of resources which couldn't be removed
- Throws:
NegativeQuantityException- quantity is a negative numberjava.lang.NullPointerException- the specified resource is null
-
getNumberOf
Returns the total amount of the specified resources contained in the warehouse- Parameters:
resource- the resource type- Returns:
- the number of contained resources of this type
-
totalResources
public int totalResources()Returns the total amount of resources contained in the warehouse- Returns:
- total amount of resources contained in the warehouse
-
notifyWarehouseUpdate
Description copied from interface:WarehouseUpdateObservableNotify the model observers that Warehouse state has changed Along with the notification sends the proper update Object as further explained in project documentation- Specified by:
notifyWarehouseUpdatein interfaceWarehouseUpdateObservable- Parameters:
msg- the update object representing a warehouse update
-
setController
-