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

public class BuildingCard extends PlayableCard implements Cloneable, BuildingEffect, Serializable
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

    Fields
    Modifier and Type
    Field
    Description
    private boolean
    Indicates whether this building card has already been bought.
    protected int
    The identifier of the effect associated with this building card.
    protected EffectType
    The type of effect associated with this building card.
    private final int
    The prestige value of this building card.
    private final int
    The price of this building card.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    BuildingCard(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.
    protected
    BuildingCard(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 Type
    Method
    Description
    void
    Default implementation of the building effect.
    boolean
    buy(Player player)
    Attempts to buy this building card for the specified player.
    Creates and returns a copy of this building card.
    private static EffectType
    effectTypeFromId(int effectId)
    Maps a building effect identifier to its corresponding EffectType.
    int
    Returns the identifier of the effect associated with this building card.
    Returns the type of effect associated with this building card.
    int
    Returns the prestige value of this building card.
    int
    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

    Methods inherited from class Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • price

      private final int price
      The price of this building card.
    • bought

      private boolean bought
      Indicates whether this building card has already been bought.
    • effectType

      protected EffectType effectType
      The type of effect associated with this building card.
    • effectId

      protected int effectId
      The identifier of the effect associated with this building card.
    • prestigeValue

      private final int prestigeValue
      The prestige value of this building card.
  • Constructor Details

    • BuildingCard

      protected BuildingCard(int era, int price, int prestigeValue) throws IllegalArgumentException
      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 - if price <= 0 or prestigeValue < 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 - if price <= 0 or prestigeValue < 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, if price <= 0, or if prestigeValue < 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, if price <= 0, or if prestigeValue < 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

      public EffectType getEffectType()
      Returns the type of effect associated with this building card.
      Returns:
      the effect type of this building card.
    • effectTypeFromId

      private static EffectType effectTypeFromId(int effectId)
      Maps a building effect identifier to its corresponding EffectType.
      Parameters:
      effectId - the effect identifier to resolve.
      Returns:
      the EffectType for the given identifier.
      Throws:
      IllegalArgumentException - if effectId does not correspond to any known effect type.
    • clone

      public BuildingCard clone()
      Creates and returns a copy of this building card.
      Overrides:
      clone in class Object
      Returns:
      a clone of this building card.
    • buy

      public boolean buy(Player player)
      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:
      true if the building card is successfully bought, false otherwise.
    • applyEffect

      public void applyEffect(Player player)
      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

      public String toStringBoard()
      Description copied from class: PlayableCard
      Returns the representation shown on the board (offer track cards).
      Specified by:
      toStringBoard in class PlayableCard
      Returns:
      the board string representation of this card.
    • toStringPlayer

      public String toStringPlayer()
      Description copied from class: PlayableCard
      Returns the compact representation shown in the player hand panel.
      Specified by:
      toStringPlayer in class PlayableCard
      Returns:
      the player-hand string representation of this card.