Class BuildingCard
java.lang.Object
it.polimi.ingsw.gc14.Model.PlayableCard
it.polimi.ingsw.gc14.Model.Cards.BuildingCard
- All Implemented Interfaces:
BuildingEffect, Serializable, Cloneable
- Direct Known Subclasses:
Building0, Building1, Building10, Building11, Building13, Building4, Building8
Represents a generic building card in the game.
A building card is a playable card with a price and a specific building effect. Concrete building cards extend this class to define their own behavior.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanIndicates whether this building card has already been bought.protected intThe identifier of the effect associated with this building card.protected EffectTypeThe type of effect associated with this building card.private final intThe prestige value of this building card.private final intThe price of this building card. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBuildingCard(int era, int price, int prestigeValue) Creates a building card with the specified era, price, and prestige value.BuildingCard(int effectId, int era, int price, int prestigeValue) Creates a building card with the specified effect identifier, era, price, and prestige value.protectedBuildingCard(String idIMG, int era, int price, int prestigeValue) Creates a building card with the specified image identifier, era, price, and prestige value.BuildingCard(String idIMG, int effectId, int era, int price, int prestigeValue) Creates a building card with the specified image id, effect identifier, era, price, and prestige value. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyEffect(Player player) Default implementation of the building effect.booleanAttempts to buy this building card for the specified player.clone()Creates and returns a copy of this building card.private static EffectTypeeffectTypeFromId(int effectId) Maps a building effect identifier to its correspondingEffectType.intReturns the identifier of the effect associated with this building card.Returns the type of effect associated with this building card.intReturns the prestige value of this building card.intgetPrice()Returns the price of this building card.Returns the representation shown on the board (offer track cards).Returns the compact representation shown in the player hand panel.Methods inherited from class PlayableCard
getEra, getIdIMG
-
Field Details
-
price
private final int priceThe price of this building card. -
bought
private boolean boughtIndicates whether this building card has already been bought. -
effectType
The type of effect associated with this building card. -
effectId
protected int effectIdThe identifier of the effect associated with this building card. -
prestigeValue
private final int prestigeValueThe prestige value of this building card.
-
-
Constructor Details
-
BuildingCard
Creates a building card with the specified era, price, and prestige value.- Parameters:
era- the era of the building card.price- the price of the building card.prestigeValue- the prestige value of the building card.- Throws:
IllegalArgumentException- ifprice <= 0orprestigeValue < 0
-
BuildingCard
protected BuildingCard(String idIMG, int era, int price, int prestigeValue) throws IllegalArgumentException Creates a building card with the specified image identifier, era, price, and prestige value.- Parameters:
idIMG- the image identifier of the building card.era- the era of the building card.price- the price of the building card.prestigeValue- the prestige value of the building card.- Throws:
IllegalArgumentException- ifprice <= 0orprestigeValue < 0
-
BuildingCard
public BuildingCard(int effectId, int era, int price, int prestigeValue) throws IllegalArgumentException Creates a building card with the specified effect identifier, era, price, and prestige value. The effect type is determined from the given effect identifier.- Parameters:
effectId- the identifier of the effect associated with the building card.era- the era of the building card.price- the price of the building card.prestigeValue- the prestige value of the building card.- Throws:
IllegalArgumentException- if the effect identifier is not valid, ifprice <= 0, or ifprestigeValue < 0
-
BuildingCard
public BuildingCard(String idIMG, int effectId, int era, int price, int prestigeValue) throws IllegalArgumentException Creates a building card with the specified image id, effect identifier, era, price, and prestige value.The effect type is determined from the given effect identifier.
- Parameters:
idIMG- the image identifier of the building card.effectId- the identifier of the effect associated with the building card.era- the era of the building card.price- the price of the building card.prestigeValue- the prestige value of the building card.- Throws:
IllegalArgumentException- if the effect identifier is not valid, ifprice <= 0, or ifprestigeValue < 0.
-
-
Method Details
-
getPrice
public int getPrice()Returns the price of this building card.- Returns:
- the price of this building card.
-
getPrestigeValue
public int getPrestigeValue()Returns the prestige value of this building card.- Returns:
- the prestige value of this building card.
-
getEffectId
public int getEffectId()Returns the identifier of the effect associated with this building card.- Returns:
- the effect identifier of this building card.
-
getEffectType
Returns the type of effect associated with this building card.- Returns:
- the effect type of this building card.
-
effectTypeFromId
Maps a building effect identifier to its correspondingEffectType.- Parameters:
effectId- the effect identifier to resolve.- Returns:
- the
EffectTypefor the given identifier. - Throws:
IllegalArgumentException- ifeffectIddoes not correspond to any known effect type.
-
clone
Creates and returns a copy of this building card. -
buy
Attempts to buy this building card for the specified player.The effective cost is reduced by the total reduction value provided by the player's Builder cards, without dropping below zero. The purchase succeeds only if the card has not already been bought and the player can pay the resulting amount of Food. If successful, the card is added to the player's building cards and marked as bought.
- Parameters:
player- the player attempting to buy the building card.- Returns:
trueif the building card is successfully bought,falseotherwise.
-
applyEffect
Default implementation of the building effect.This method does not perform any operation and can be overridden by specific building cards that define an active effect.
- Parameters:
player- the player to whom the effect may be applied.
-
toStringBoard
Description copied from class:PlayableCardReturns the representation shown on the board (offer track cards).- Specified by:
toStringBoardin classPlayableCard- Returns:
- the board string representation of this card.
-
toStringPlayer
Description copied from class:PlayableCardReturns the compact representation shown in the player hand panel.- Specified by:
toStringPlayerin classPlayableCard- Returns:
- the player-hand string representation of this card.
-