Class Building4
java.lang.Object
it.polimi.ingsw.gc14.Model.PlayableCard
it.polimi.ingsw.gc14.Model.Cards.BuildingCard
it.polimi.ingsw.gc14.Model.Cards.Building.Effects.Building4
- All Implemented Interfaces:
BuildingEffect, Serializable, Cloneable
Building effect that grants 3 food for each new pair of identical inventors
obtained after purchasing this building.
Pairs of identical inventors already owned at the moment of purchase are stored during initialization and do not provide food.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intFood units granted per newly completed inventor pair.private intNumber of inventor pairs already counted by this building effect.private booleanIndicates whether the building effect has already been initialized after purchase.Fields inherited from class BuildingCard
effectId, effectType -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyEffect(Player player) Applies the building effect to the specified player.booleanAttempts to purchase the building and initializes its effect if the purchase succeeds.clone()Creates a new building instance with the same configuration values as this card.voidinitialize(Player player) Initializes the building effect by storing the number of pairs of identical inventors already owned by the player at the moment of purchase.Methods inherited from class BuildingCard
getEffectId, getEffectType, getPrestigeValue, getPrice, toStringBoard, toStringPlayerMethods inherited from class PlayableCard
getEra, getIdIMG
-
Field Details
-
FOOD_PER_INVENTOR_PAIR
private static final int FOOD_PER_INVENTOR_PAIRFood units granted per newly completed inventor pair.- See Also:
-
purchased
private boolean purchasedIndicates whether the building effect has already been initialized after purchase. -
numPair
private int numPairNumber of inventor pairs already counted by this building effect.
-
-
Constructor Details
-
Building4
public Building4(int era, int price, int prestigeValue) Creates a building with the specified era, price and prestige value.- Parameters:
era- The game era of the building.price- The price (in food) of the building.prestigeValue- The number of Prestige Points gained from this building at the end of the game.
-
Building4
Creates a building with the specified image identifier, era, price and prestige value.- Parameters:
idIMG- the image identifier of the building.era- the game era of the building.price- the price in food of the building.prestigeValue- the number of Prestige Points gained from this building at the end of the game.
-
-
Method Details
-
initialize
Initializes the building effect by storing the number of pairs of identical inventors already owned by the player at the moment of purchase.The initialization is performed only once.
- Parameters:
player- the player who owns the building.
-
buy
Attempts to purchase the building and initializes its effect if the purchase succeeds.- Overrides:
buyin classBuildingCard- Parameters:
player- The player who buys the building.- Returns:
trueif the building is successfully purchased and initialized,falseotherwise.
-
clone
Creates a new building instance with the same configuration values as this card.The runtime state of the effect, such as initialization status and counted inventor pairs, is not copied.
- Overrides:
clonein classBuildingCard- Returns:
- a new building card with the same base properties.
-
applyEffect
Applies the building effect to the specified player.The method counts the current number of pairs of identical inventors and grants 3 food for each pair obtained since the last stored value.
- Overrides:
applyEffectin classBuildingCard- Parameters:
player- The player who owns the building.- Throws:
IllegalArgumentException- Thrown if the specified player does not own this card.
-