Class Building4

All Implemented Interfaces:
BuildingEffect, Serializable, Cloneable

public class Building4 extends BuildingCard
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 Details

    • FOOD_PER_INVENTOR_PAIR

      private static final int FOOD_PER_INVENTOR_PAIR
      Food units granted per newly completed inventor pair.
      See Also:
    • purchased

      private boolean purchased
      Indicates whether the building effect has already been initialized after purchase.
    • numPair

      private int numPair
      Number 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

      public Building4(String idIMG, int era, int price, int prestigeValue)
      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

      public void initialize(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.

      The initialization is performed only once.

      Parameters:
      player - the player who owns the building.
    • buy

      public boolean buy(Player player)
      Attempts to purchase the building and initializes its effect if the purchase succeeds.
      Overrides:
      buy in class BuildingCard
      Parameters:
      player - The player who buys the building.
      Returns:
      true if the building is successfully purchased and initialized, false otherwise.
    • clone

      public BuildingCard 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:
      clone in class BuildingCard
      Returns:
      a new building card with the same base properties.
    • applyEffect

      public void applyEffect(Player player) throws IllegalArgumentException
      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:
      applyEffect in class BuildingCard
      Parameters:
      player - The player who owns the building.
      Throws:
      IllegalArgumentException - Thrown if the specified player does not own this card.