Package it.polimi.ingsw.Server.Model
Class Board
java.lang.Object
java.rmi.server.RemoteObject
java.rmi.server.RemoteServer
java.rmi.server.UnicastRemoteObject
it.polimi.ingsw.Server.Model.Board
- All Implemented Interfaces:
BoardInterface
,Serializable
,Remote
Game's Board
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Maximum X dimension of the boardstatic final int
Maximum Y dimension of the boardprivate Map<ObjectCard,
BoardSpace> List of the most recent Object Cards takenprivate final int
Game's maximum number of playersprivate final int
Game's minimum number of playersprivate List<ObjectCard>
Object Cards extracted in the related gameprivate BoardSpace[][]
Board Spaces implementationFields inherited from class java.rmi.server.RemoteObject
ref
-
Constructor Summary
ModifierConstructorDescriptionBoard
(int playerCount, List<ObjectCard> objectCards) Manages board creation and initialization, based on pre-built files indicating usable spaces and restrictions related to the number of players.private
Board
(BoardSpace[][] spaces, List<ObjectCard> objectCards, Map<ObjectCard, BoardSpace> lastTaken) Related to Game's refresh strategy -
Method Summary
Modifier and TypeMethodDescriptionReturns a list of usable and effectively present cards on the board, based on a functional approach using Optionals.getCardImageFromSpace
(int x, int y) Returns Object Card's image path, given a Board Spaceint
getCardOrdinalFromSpace
(int x, int y) Returns Object Card's type ordinal, given a Board SpacegetCardsFromCoordinate
(List<Integer> x, List<Integer> y) Returns a list of cards contained in a group of coordinatesgetCopy()
Refreshed copy, after server reload from filegetPlainCardFromSpace
(int x, int y) Returns Object Card as an instance (not as Optional.of(card))BoardSpace[][]
Returns a copy of the spaces array via functional approach.boolean
isSpaceUsable
(int x, int y) Checks if a space is usable given coordinatesprivate void
reset()
Implements reset logic.private boolean
Checks the condition for enabling reset on the board (even if not all cards are put on it)(package private) boolean
Checks if a reset of the board is needed, watching at usable and effectively present spacesvoid
Restores the last move (group of cards taken from board)private void
spacesDeclaration
(int playerCount) Takes care of creating the Board Spaces using JSON declaration filesvoid
takeFromBoard
(List<ObjectCard> orderedCards) Removes from board a list of ordered cards (only valid moves are accepted)Removes from board a group of cards based on their coordinates (only valid moves are accepted)boolean
valid
(List<ObjectCard> list) Checks if, given a list of sequentially ordered cards, every card has a "free side".boolean
validFromCoordinate
(List<Integer> x, List<Integer> y) Checks if a group of couples of coordinates is a valid move on the boardMethods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, exportObject, exportObject, unexportObject
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
-
Field Details
-
BOARD_DIM_X
public static final int BOARD_DIM_XMaximum X dimension of the board- See Also:
-
BOARD_DIM_Y
public static final int BOARD_DIM_YMaximum Y dimension of the board- See Also:
-
MINPLAYERS
private final int MINPLAYERSGame's minimum number of players- See Also:
-
MAXPLAYERS
private final int MAXPLAYERSGame's maximum number of players- See Also:
-
spaces
Board Spaces implementation -
objectCards
Object Cards extracted in the related game -
lastTaken
List of the most recent Object Cards taken
-
-
Constructor Details
-
Board
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 gameobjectCards
- 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 RemoteExceptionRelated to Game's refresh strategy- Throws:
RemoteException
-
-
Method Details
-
spacesDeclaration
Takes care of creating the Board Spaces using JSON declaration files- Parameters:
playerCount
- number of players in the game- Throws:
URISyntaxException
- related to resources locatorsIOException
- related to file management
-
getSpaces
Returns a copy of the spaces array via functional approach.- Returns:
- copy of spaces
-
isSpaceUsable
Checks if a space is usable given coordinates- Specified by:
isSpaceUsable
in interfaceBoardInterface
- Parameters:
x
- coordinatey
- coordinate- Returns:
- usability of that space
- Throws:
Exception
- if parameters are trying to go out of the board
-
getPlainCardFromSpace
Returns Object Card as an instance (not as Optional.of(card))- Parameters:
x
- coordinatey
- coordinate- Returns:
- the card
- Throws:
Exception
- if parameters are trying to go out of the board
-
getCardOrdinalFromSpace
Returns Object Card's type ordinal, given a Board Space- Specified by:
getCardOrdinalFromSpace
in interfaceBoardInterface
- Parameters:
x
- coordinatey
- coordinate- Returns:
- the card's ordinal
- Throws:
Exception
- if parameters are trying to go out of the board
-
getCardImageFromSpace
Returns Object Card's image path, given a Board Space- Specified by:
getCardImageFromSpace
in interfaceBoardInterface
- Parameters:
x
- coordinatey
- coordinate- Returns:
- the card's image path
- Throws:
Exception
- if parameters are trying to go out of the board
-
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
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
Checks if a group of couples of coordinates is a valid move on the board- Parameters:
x
- list ofcoordinatesy
- list of coordinates- Returns:
- move validation
- Throws:
Exception
- to manage board dimension limits
-
getCardsFromCoordinate
Returns a list of cards contained in a group of coordinates- Parameters:
x
- list of coordinatesy
- list of coordinates- Returns:
- the list of cards
- Throws:
Exception
- to manage board dimension limits
-
takeFromBoard
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 coordinatesy
- list of coordinates- Returns:
- action validity
- Throws:
Exception
- if an invalid deletion is tried
-
restoreLastTaken
Restores the last move (group of cards taken from board)- Throws:
Exception
- if a restore is tried before any take has happened
-
getCopy
Refreshed copy, after server reload from file- Returns:
- new copy of the object
- Throws:
RemoteException
- related to RMI
-
getObjectCards
- Returns:
- extracted Object Cards list
-