Class Board

All Implemented Interfaces:
BoardInterface, Serializable, Remote

public class Board extends UnicastRemoteObject implements BoardInterface
Game's Board
See Also:
  • Field Details

    • BOARD_DIM_X

      public static final int BOARD_DIM_X
      Maximum X dimension of the board
      See Also:
    • BOARD_DIM_Y

      public static final int BOARD_DIM_Y
      Maximum Y dimension of the board
      See Also:
    • MINPLAYERS

      private final int MINPLAYERS
      Game's minimum number of players
      See Also:
    • MAXPLAYERS

      private final int MAXPLAYERS
      Game's maximum number of players
      See Also:
    • spaces

      @Expose private BoardSpace[][] spaces
      Board Spaces implementation
    • objectCards

      @Expose(serialize=false, deserialize=true) private List<ObjectCard> objectCards
      Object Cards extracted in the related game
    • lastTaken

      @Expose(serialize=false, deserialize=true) private Map<ObjectCard,BoardSpace> lastTaken
      List of the most recent Object Cards taken
  • Constructor Details

    • Board

      public Board(int playerCount, List<ObjectCard> objectCards) throws Exception
      Manages board creation and initialization, based on pre-built files indicating usable spaces and restrictions related to the number of players.
      Parameters:
      playerCount - number of players in the game
      objectCards - List of extracted Object Cards
      Throws:
      FileNotFoundException - related to file management. In the default environment, necessary files are found in the "/res/model/" folder of the project.
      Exception
    • Board

      private Board(BoardSpace[][] spaces, List<ObjectCard> objectCards, Map<ObjectCard,BoardSpace> lastTaken) throws RemoteException
      Related to Game's refresh strategy
      Throws:
      RemoteException
  • Method Details

    • spacesDeclaration

      private void spacesDeclaration(int playerCount) throws URISyntaxException, IOException
      Takes care of creating the Board Spaces using JSON declaration files
      Parameters:
      playerCount - number of players in the game
      Throws:
      URISyntaxException - related to resources locators
      IOException - related to file management
    • getSpaces

      public BoardSpace[][] getSpaces()
      Returns a copy of the spaces array via functional approach.
      Returns:
      copy of spaces
    • isSpaceUsable

      public boolean isSpaceUsable(int x, int y) throws Exception
      Checks if a space is usable given coordinates
      Specified by:
      isSpaceUsable in interface BoardInterface
      Parameters:
      x - coordinate
      y - coordinate
      Returns:
      usability of that space
      Throws:
      Exception - if parameters are trying to go out of the board
    • getPlainCardFromSpace

      public ObjectCard getPlainCardFromSpace(int x, int y) throws Exception
      Returns Object Card as an instance (not as Optional.of(card))
      Parameters:
      x - coordinate
      y - coordinate
      Returns:
      the card
      Throws:
      Exception - if parameters are trying to go out of the board
    • getCardOrdinalFromSpace

      public int getCardOrdinalFromSpace(int x, int y) throws Exception
      Returns Object Card's type ordinal, given a Board Space
      Specified by:
      getCardOrdinalFromSpace in interface BoardInterface
      Parameters:
      x - coordinate
      y - coordinate
      Returns:
      the card's ordinal
      Throws:
      Exception - if parameters are trying to go out of the board
    • getCardImageFromSpace

      public String getCardImageFromSpace(int x, int y) throws Exception
      Returns Object Card's image path, given a Board Space
      Specified by:
      getCardImageFromSpace in interface BoardInterface
      Parameters:
      x - coordinate
      y - coordinate
      Returns:
      the card's image path
      Throws:
      Exception - if parameters are trying to go out of the board
    • boardCards

      public List<ObjectCard> boardCards()
      Returns a list of usable and effectively present cards on the board, based on a functional approach using Optionals.
      Returns:
      list of cards on the board
    • resetNeeded

      boolean resetNeeded()
      Checks if a reset of the board is needed, watching at usable and effectively present spaces
      Returns:
      boolean: reset of the board is compulsory to continue the game
    • resetEnabled

      private boolean resetEnabled()
      Checks the condition for enabling reset on the board (even if not all cards are put on it)
      Returns:
      condition for reset enabling
    • reset

      private void reset()
      Implements reset logic. The same approach is used in the construction of the board.
    • valid

      public boolean valid(List<ObjectCard> list)
      Checks if, given a list of sequentially ordered cards, every card has a "free side". VERSION 2: checks for every card rather than the group
      Parameters:
      list - of sequentially ordered cards (indexes on the board can be disordered)
      Returns:
      whether if a move is permitted
    • validFromCoordinate

      public boolean validFromCoordinate(List<Integer> x, List<Integer> y) throws Exception
      Checks if a group of couples of coordinates is a valid move on the board
      Parameters:
      x - list ofcoordinates
      y - list of coordinates
      Returns:
      move validation
      Throws:
      Exception - to manage board dimension limits
    • getCardsFromCoordinate

      public List<ObjectCard> getCardsFromCoordinate(List<Integer> x, List<Integer> y) throws Exception
      Returns a list of cards contained in a group of coordinates
      Parameters:
      x - list of coordinates
      y - list of coordinates
      Returns:
      the list of cards
      Throws:
      Exception - to manage board dimension limits
    • takeFromBoard

      public void takeFromBoard(List<ObjectCard> orderedCards) throws Exception
      Removes from board a list of ordered cards (only valid moves are accepted)
      Parameters:
      orderedCards - list of ordered cards (also if not internally)
      Throws:
      Exception - if an invalid deletion is tried
    • takeFromBoardFromCoordinate

      public List<ObjectCard> takeFromBoardFromCoordinate(List<Integer> x, List<Integer> y) throws Exception
      Removes from board a group of cards based on their coordinates (only valid moves are accepted)
      Parameters:
      x - list of coordinates
      y - list of coordinates
      Returns:
      action validity
      Throws:
      Exception - if an invalid deletion is tried
    • restoreLastTaken

      public void restoreLastTaken() throws Exception
      Restores the last move (group of cards taken from board)
      Throws:
      Exception - if a restore is tried before any take has happened
    • getCopy

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

      public List<ObjectCard> getObjectCards()
      Returns:
      extracted Object Cards list