Class CommonGoalCard

All Implemented Interfaces:
CommonGoalCardInterface, Serializable, Remote

public class CommonGoalCard extends UnicastRemoteObject implements CommonGoalCardInterface
This class represents the Common Goal cards, thanks to which players may grant points, achieving a specific pattern
See Also:
  • Field Details

    • LIMIT

      public static final int LIMIT
      Limit of Common Goal Cards.
      See Also:
    • type

      @Expose private final int type
      This attribute stands for the id of the Common Goal Card, which permits to identify the different Common Goal Cards.
    • description

      @Expose private String description
      This attribute stands for a textual description of the pattern that the player has to achieve, in order to gain points.
    • increments

      @Expose private Stack<ScoreCard> increments
      This attribute stands for the deck of ScoreCards on each Common Goal Card, put there from the lowest to the highest value. The size of the Stack varies according to the number of players.
  • Constructor Details

    • CommonGoalCard

      public CommonGoalCard(int type, int playerCount) throws Exception
      CommonGoalCard's constructor. New ScoreCards with a value of 2,4,6 or 8 points are pushed into the Stack increments according to the playerCount, from the lowest to the highest score value.
      Parameters:
      type - it indicates the id of the Common Goal Card, in order to identify the pattern
      playerCount - (2nd parameter) it represents the number of players, according to which a different number of ScoreCards are pushed into the Stack
      Throws:
      Exception - if parameters are invalid
    • CommonGoalCard

      private CommonGoalCard(int type, String description, Stack<ScoreCard> increments) throws RemoteException
      Related to Game's refresh strategy
      Throws:
      RemoteException - related to RMI
  • Method Details

    • getDescription

      public String getDescription()
      This method returns the textual description of the pattern that the player has to achieve, in order to gain points.
      Specified by:
      getDescription in interface CommonGoalCardInterface
      Returns:
      String: textual description of the pattern
    • getIncrements

      public Stack<ScoreCardInterface> getIncrements()
      Specified by:
      getIncrements in interface CommonGoalCardInterface
      Returns:
      Score Increments stack
    • attribute

      public ScoreCard attribute(Shelf shelf) throws Exception
      This method calculates how many points the player has scored, by achieving the pattern which is displayed in the Common Goal Card.
      Parameters:
      shelf - player's shelf
      Returns:
      score granted by the player, if the pattern displayed by the card has been achieved
      Throws:
      Exception - if coordinates are invalid
    • findTypesInColumns

      private boolean findTypesInColumns(int diffTypesMax, int diffTypesMin, int numOfPattern, Shelf shelf) throws Exception
      This method is a support method to attribute() for cards 2 and 5.
      Parameters:
      diffTypesMax - max number of different types in a column
      diffTypesMin - min number of different types in a column
      numOfPattern - num of pattern
      shelf - player's shelf
      Returns:
      true if the pattern has been found, false otherwise
      Throws:
      Exception - invalid coordinates
    • findTypesInRows

      private boolean findTypesInRows(int diffTypesMax, int diffTypesMin, int numOfPattern, Shelf shelf) throws Exception
      This method is a support method to attribute() for cards 6 and 7.
      Parameters:
      diffTypesMax - max number of different types in a line
      diffTypesMin - min number of different types in a column
      numOfPattern - num of pattern
      shelf - player's shelf
      Returns:
      true if the pattern has been found, false otherwise
      Throws:
      Exception - invalid coordinates
    • sameTypeGroupFirstCheck

      private boolean sameTypeGroupFirstCheck(int dimOfGroup, int numPattern, Shelf shelf) throws Exception
      This method is a support method to attribute() for cards 3 and 4. It checks the presence of groups in lines and then in columns.
      Parameters:
      dimOfGroup - dimension of each group
      numPattern - number of pattern
      shelf - player's shelf
      Returns:
      true if the pattern has been found, false otherwise
      Throws:
      Exception - invalid coordinates
    • sameTypeGroupSecondCheck

      private boolean sameTypeGroupSecondCheck(int dimOfGroup, int numPattern, Shelf shelf) throws Exception
      This method is a support method to attribute() for cards 3 and 4. It checks the presence of groups in columns and then in lines.
      Parameters:
      dimOfGroup - dimension of each group
      numPattern - number of patterns
      shelf - player's shelf
      Returns:
      true if the pattern has been found, false otherwise
      Throws:
      Exception - invalid coordinates
    • getCopy

      public CommonGoalCard getCopy() throws RemoteException
      Refreshed copy, after server reload from file
      Returns:
      new copy of the object
      Throws:
      RemoteException - related to RMI
    • getType

      public int getType() throws RemoteException
      Common Goal Card's type (ordinal)
      Specified by:
      getType in interface CommonGoalCardInterface
      Returns:
      type
      Throws:
      RemoteException - related to RMI