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 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, AbuseOfFaithException
      Create 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, NotEnoughSpaceException
      Add 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 warehouse
      java.lang.NullPointerException - the specified resource is null
    • removeResources

      public int removeResources​(ResourceType resourceType, int quantity) throws NegativeQuantityException
      Remove 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 remove
      quantity - the maximum number of resources to remove
      Returns:
      the number of resources which couldn't be removed
      Throws:
      NegativeQuantityException - quantity is a negative number
      java.lang.NullPointerException - the specified resource is null
    • getNumberOf

      public int getNumberOf​(ResourceType resource)
      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

      public void notifyWarehouseUpdate​(WarehouseUpdate msg)
      Description copied from interface: WarehouseUpdateObservable
      Notify 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:
      notifyWarehouseUpdate in interface WarehouseUpdateObservable
      Parameters:
      msg - the update object representing a warehouse update
    • setController

      public void setController​(ModelObserver controller)