Package it.polimi.ingsw.model
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 voidaddResources(ResourceType resource, int quantity)Adds resources to the chest NOTE: the newly added resources will be available to remove only after callingendOfTurnMapsMerge()voidendOfTurnMapsMerge()makes newly added resources available for removalintgetNumberOf(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 callendOfTurnMapsMerge()voidnotifyChestMerge()Notify the model observers that the chest has been mergedvoidnotifyChestUpdate(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 documentationvoidnotifyTempChestChange(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 documentationvoidremoveResources(ResourceType resource, int quantity)removes resources from the chestvoidsetController(ModelObserver controller)inttotalNumberOfResources()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, NegativeQuantityExceptionAdds resources to the chest NOTE: the newly added resources will be available to remove only after callingendOfTurnMapsMerge()- Parameters:
resource- the resource to be addedquantity- how many resource to add- Throws:
AbuseOfFaithException- when trying to add ResourceType.FAITHNegativeQuantityException
-
removeResources
public void removeResources(ResourceType resource, int quantity) throws NotEnoughResourcesException, NegativeQuantityExceptionremoves resources from the chest- Parameters:
resource- the resource to be removedquantity- how many resource to remove- Throws:
NotEnoughResourcesException- if you try to remove more resources than you haveNegativeQuantityException
-
totalNumberOfResources
public int totalNumberOfResources()the number of total resources contained (no distinction by type)- Returns:
- the number of total resources as an int
-
getNumberOf
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 callendOfTurnMapsMerge()- 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
-
notifyChestUpdate
Description copied from interface:ChestUpdateObservableNotify 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:
notifyChestUpdatein interfaceChestUpdateObservable- Parameters:
msg- the update object representing a chest update
-
notifyTempChestChange
Description copied from interface:TempChestObservableNotify 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:
notifyTempChestChangein interfaceTempChestObservable- Parameters:
msg- the update object representing a chest update
-
notifyChestMerge
public void notifyChestMerge()Description copied from interface:ChestMergeObservableNotify the model observers that the chest has been merged- Specified by:
notifyChestMergein interfaceChestMergeObservable
-