Class Shelf

All Implemented Interfaces:
ShelfInterface, Serializable, Remote

public class Shelf extends UnicastRemoteObject implements ShelfInterface
Player's Shelf
See Also:
  • Field Details

    • SHELF_DIM_X

      public static final int SHELF_DIM_X
      Maximum X dimension of the shelf
      See Also:
    • SHELF_DIM_Y

      public static final int SHELF_DIM_Y
      Maximum Y dimension of the shelf
      See Also:
    • cards

      @Expose private Optional<ObjectCard>[][] cards
      Shelf implementation of Object Cards
  • Constructor Details

  • Method Details

    • shelfCards

      public List<ObjectCard> shelfCards()
      Returns a list of effectively present cards on the board, based on a functional approach using Optionals.
      Returns:
      list of cards in the shelf
    • getCard

      public Optional<ObjectCard> getCard(int x, int y) throws Exception
      gets Object Card in position (x, y) if valid (else empty)
      Parameters:
      x - coordinate
      y - coordinate
      Returns:
      requested ObjectCard
      Throws:
      Exception - if coordinates are invalid
    • getPlainCard

      public ObjectCard getPlainCard(int x, int y) throws Exception
      gets Object Card in position (x, y) if valid (else null)
      Parameters:
      x - coordinate
      y - coordinate
      Returns:
      requested ObjectCard
      Throws:
      Exception - if coordinates are invalid
    • getCardOrdinal

      public int getCardOrdinal(int x, int y) throws Exception
      Returns Object Card's type ordinal in position (x, y) if valid (else -1)
      Specified by:
      getCardOrdinal in interface ShelfInterface
      Parameters:
      x - coordinate
      y - coordinate
      Returns:
      requested Object Card's type ordinal
      Throws:
      Exception - if coordinates are invalid
    • getCardImage

      public String getCardImage(int x, int y) throws Exception
      Returns Object Card's image path in position (x, y) if valid (else null)
      Specified by:
      getCardImage in interface ShelfInterface
      Parameters:
      x - coordinate
      y - coordinate
      Returns:
      the card's image path
      Throws:
      Exception - if parameters are trying to go out of the board
    • getCoordinate

      public int getCoordinate(ObjectCard oc, boolean X) throws Exception
      Looks for coordinates of a given card (x, y)
      Parameters:
      oc - the Object Card to be found
      X - kind of coordinate: X = true means x coordinate, false y
      Returns:
      coordinate of the given card
      Throws:
      Exception - related to invalid coordinates in getCard method
    • placeCard

      public void placeCard(ObjectCard oc, int y) throws Exception
      Inserts a card into the shelf at the selected column (y)
      Parameters:
      oc - ObjectCard to insert
      y - number of column to use
      Throws:
      Exception - newly defined exception to manage error related to Shelf Insertion
    • evaluatePattern

      public int evaluatePattern(PersonalGoalCard pgCard)
      Evaluates score for a PersonalGoalCard
      Parameters:
      pgCard - Personal Goal Card
      Returns:
      corresponding score
    • finalEvaluation

      public int finalEvaluation() throws Exception
      Implements final evaluation of groups of Object Cards used at the end of the game
      Returns:
      score obtained for current shelf
      Throws:
      Exception - related to invalid coordinates in getCard method
    • isFull

      public boolean isFull()
      Specified by:
      isFull in interface ShelfInterface
      Returns:
      true if the Shelf is full
    • emptySpacesInColumn

      public int emptySpacesInColumn(int column) throws Exception
      Calculates the number of empty spaces in the selected column
      Parameters:
      column - in the Shelf
      Returns:
      number of empty spaces in the column
      Throws:
      Exception - if given column is invalid
    • getCopy

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