Class Chest

java.lang.Object
it.polimi.ingsw.model.Chest
All Implemented Interfaces:
ChestMergeObservable, ChestUpdateObservable, TempChestObservable

public class Chest
extends java.lang.Object
implements ChestUpdateObservable, TempChestObservable, ChestMergeObservable
Represents the chest of player. A chest can contain an unlimited amount of resources, but can't contain faith.
  • Constructor Summary

    Constructors
    Constructor Description
    Chest()  
  • Method Summary

    Modifier and Type Method Description
    void addResources​(ResourceType resource, int quantity)
    Adds resources to the chest NOTE: the newly added resources will be available to remove only after calling endOfTurnMapsMerge()
    void endOfTurnMapsMerge()
    makes newly added resources available for removal
    int getNumberOf​(ResourceType resource)
    get the number of resources of the specified type contained in the chest NOTE: to make this method include newly added resources you need to call endOfTurnMapsMerge()
    void notifyChestMerge()
    Notify the model observers that the chest has been merged
    void notifyChestUpdate​(ChestUpdate msg)
    Notify the model observers that an element has been removed from the chest Along with the notification sends the proper update Object as further explained in project documentation
    void notifyTempChestChange​(ChestUpdate msg)
    Notify the model observers that an element has been added to the temporary chest Along with the notification sends the proper update Object as further explained in project documentation
    void removeResources​(ResourceType resource, int quantity)
    removes resources from the chest
    void setController​(ModelObserver controller)  
    int totalNumberOfResources()
    the number of total resources contained (no distinction by type)

    Methods inherited from class java.lang.Object

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

    • Chest

      public Chest()
  • Method Details

    • addResources

      public void addResources​(ResourceType resource, int quantity) throws AbuseOfFaithException, NegativeQuantityException
      Adds resources to the chest NOTE: the newly added resources will be available to remove only after calling endOfTurnMapsMerge()
      Parameters:
      resource - the resource to be added
      quantity - how many resource to add
      Throws:
      AbuseOfFaithException - when trying to add ResourceType.FAITH
      NegativeQuantityException
    • removeResources

      public void removeResources​(ResourceType resource, int quantity) throws NotEnoughResourcesException, NegativeQuantityException
      removes resources from the chest
      Parameters:
      resource - the resource to be removed
      quantity - how many resource to remove
      Throws:
      NotEnoughResourcesException - if you try to remove more resources than you have
      NegativeQuantityException
    • totalNumberOfResources

      public int totalNumberOfResources()
      the number of total resources contained (no distinction by type)
      Returns:
      the number of total resources as an int
    • getNumberOf

      public int getNumberOf​(ResourceType resource)
      get the number of resources of the specified type contained in the chest NOTE: to make this method include newly added resources you need to call endOfTurnMapsMerge()
      Parameters:
      resource - the Resource type of which you want to know how many there are in the chest
      Returns:
      the number of resources of the specified type
    • endOfTurnMapsMerge

      public void endOfTurnMapsMerge()
      makes newly added resources available for removal
    • setController

      public void setController​(ModelObserver controller)
    • notifyChestUpdate

      public void notifyChestUpdate​(ChestUpdate msg)
      Description copied from interface: ChestUpdateObservable
      Notify the model observers that an element has been removed from the chest Along with the notification sends the proper update Object as further explained in project documentation
      Specified by:
      notifyChestUpdate in interface ChestUpdateObservable
      Parameters:
      msg - the update object representing a chest update
    • notifyTempChestChange

      public void notifyTempChestChange​(ChestUpdate msg)
      Description copied from interface: TempChestObservable
      Notify the model observers that an element has been added to the temporary chest Along with the notification sends the proper update Object as further explained in project documentation
      Specified by:
      notifyTempChestChange in interface TempChestObservable
      Parameters:
      msg - the update object representing a chest update
    • notifyChestMerge

      public void notifyChestMerge()
      Description copied from interface: ChestMergeObservable
      Notify the model observers that the chest has been merged
      Specified by:
      notifyChestMerge in interface ChestMergeObservable