java.lang.Object
it.polimi.ingsw.model.Player
- All Implemented Interfaces:
PlayerInterface
public class Player extends java.lang.Object implements PlayerInterface
Representation of a Player during a game
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description voidaddBuildableCellsListener(BuildableCellsListener buildableCellsListener)Adds a new listenervoidaddBuildingBlocksListener(BuildingBlocksListener buildingBlocksListener)Adds a new listenervoidaddSelectWorkerListener(SelectWorkerListener selectWorkerListener)Adds a new listenervoidaddWalkableCellsListener(WalkableCellsListener walkableCellsListener)Adds a new listenervoidaddWorker(Cell cell)Adds a worker to the boardvoidaddWorkerListener(AddWorkerListener addWorkerListener)Adds a new listenerbooleanallWorkersArePlaced()Checks if the player has placed all of its workersvoidaskPassTurn()Ends the player's turnPlayerDatabuildDataClass()Creates a PlayerData object based on this playerPlayerclonePlayer(Game game)Creates a clone of this objectbooleanequals(java.lang.Object o)Compares the argument to the receiver, and answers true if their names are equalsColorgetColor()color getterGodgetGod()god getterjava.lang.StringgetName()name getterWorkergetSelectedWorker()selectedWorker getterjava.util.List<Worker>getWorkers()Gets all Player's workersinthashCode()voidobtainBuildableCells()Provides a list of cells on which the selected player can build onvoidobtainBuildingBlocks(Cell selectedCell)Provides a list of blocks which the selected worker can build on the given cellvoidobtainWalkableCells()Provides a list of cells on which the selected player can walk tovoidresetSelectedWorker()Resets the worker to perform the next action to nullvoidsetGame(Game game)Sets whatgamethe Player is playingvoidsetSelectedWorker(Worker selectedWorker)Sets the worker to perform the next actionvoiduseAction(Action action)Applies the given action
-
Constructor Details
-
Player
Creates a new Player, assigning itsname, thegodit chose and thecolorassigned to its workers.Since some Gods allow the player to have more than two workers, the constructor initializes the
workersas an empty list; the workers will then be created and assigned to the player with theaddWorker(Cell)method.
Regarding the game attribute, it is not assigned in the constructor, since theGameis created after the creation of the players.- Parameters:
name- the player's usernamegod- the player's God card, chosen before the game is createdcolor- the player's workers color, automatically determined before the game is created
-
-
Method Details
-
setGame
Sets whatgamethe Player is playing- Parameters:
game-game- See Also:
Game(GameBoard, List)
-
getWorkers
Gets all Player's workers- Returns:
- a list containing all the player's workers
workers
-
addWorker
Adds a worker to the board- Specified by:
addWorkerin interfacePlayerInterface- Parameters:
cell- the cell to place the worker to- Throws:
AddingFailedException- if the target cell is already occupied or all the workers are already placed
-
allWorkersArePlaced
public boolean allWorkersArePlaced()Checks if the player has placed all of its workers- Specified by:
allWorkersArePlacedin interfacePlayerInterface- Returns:
- true if all the player's workers have been placed, false otherwise
-
useAction
Applies the given action- Specified by:
useActionin interfacePlayerInterface- Parameters:
action- the action to be applied- Throws:
IllegalActionException- if the action cannot be performed
-
askPassTurn
Ends the player's turn- Specified by:
askPassTurnin interfacePlayerInterface- Throws:
IllegalEndingTurnException- if the turn cannot be ended
-
getGod
god getter- Returns:
- the player's god
-
getColor
color getter- Returns:
- the player's workers color
-
getName
public java.lang.String getName()name getter- Returns:
- the player's username
-
getSelectedWorker
selectedWorker getter- Returns:
- the worker selected to perform the next action
-
setSelectedWorker
Sets the worker to perform the next action- Specified by:
setSelectedWorkerin interfacePlayerInterface- Parameters:
selectedWorker- the worker to select- Throws:
NotYourWorkerException- if the worker is not owned by the player
-
resetSelectedWorker
public void resetSelectedWorker()Resets the worker to perform the next action to null -
obtainBuildingBlocks
Provides a list of blocks which the selected worker can build on the given cell- Specified by:
obtainBuildingBlocksin interfacePlayerInterface- Parameters:
selectedCell- the cell to perform the build action on- Throws:
IllegalActionException- if the build action cannot be performed
-
obtainWalkableCells
Provides a list of cells on which the selected player can walk to- Specified by:
obtainWalkableCellsin interfacePlayerInterface- Throws:
WrongSelectionException- if no worker has been selected
-
obtainBuildableCells
Provides a list of cells on which the selected player can build on- Specified by:
obtainBuildableCellsin interfacePlayerInterface- Throws:
WrongSelectionException- if no worker has been selected
-
clonePlayer
Creates a clone of this object- Parameters:
game- the current game- Returns:
- a clone of this object
-
buildDataClass
Creates a PlayerData object based on this player- Returns:
- this object's data class
-
addWorkerListener
Adds a new listener- Specified by:
addWorkerListenerin interfacePlayerInterface- Parameters:
addWorkerListener- the listener to add to the list
-
addBuildableCellsListener
Adds a new listener- Specified by:
addBuildableCellsListenerin interfacePlayerInterface- Parameters:
buildableCellsListener- the listener to add to the list
-
addWalkableCellsListener
Adds a new listener- Specified by:
addWalkableCellsListenerin interfacePlayerInterface- Parameters:
walkableCellsListener- the listener to add to the list
-
addSelectWorkerListener
Adds a new listener- Specified by:
addSelectWorkerListenerin interfacePlayerInterface- Parameters:
selectWorkerListener- the listener to add to the list
-
addBuildingBlocksListener
Adds a new listener- Specified by:
addBuildingBlocksListenerin interfacePlayerInterface- Parameters:
buildingBlocksListener- the listener to add to the list
-
equals
public boolean equals(java.lang.Object o)Compares the argument to the receiver, and answers true if their names are equals- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the object to be- Returns:
- true if the object is the same as the cell, false otherwise
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-