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 void
addBuildableCellsListener(BuildableCellsListener buildableCellsListener)
Adds a new listenervoid
addBuildingBlocksListener(BuildingBlocksListener buildingBlocksListener)
Adds a new listenervoid
addSelectWorkerListener(SelectWorkerListener selectWorkerListener)
Adds a new listenervoid
addWalkableCellsListener(WalkableCellsListener walkableCellsListener)
Adds a new listenervoid
addWorker(Cell cell)
Adds a worker to the boardvoid
addWorkerListener(AddWorkerListener addWorkerListener)
Adds a new listenerboolean
allWorkersArePlaced()
Checks if the player has placed all of its workersvoid
askPassTurn()
Ends the player's turnPlayerData
buildDataClass()
Creates a PlayerData object based on this playerPlayer
clonePlayer(Game game)
Creates a clone of this objectboolean
equals(java.lang.Object o)
Compares the argument to the receiver, and answers true if their names are equalsColor
getColor()
color getterGod
getGod()
god getterjava.lang.String
getName()
name getterWorker
getSelectedWorker()
selectedWorker getterjava.util.List<Worker>
getWorkers()
Gets all Player's workersint
hashCode()
void
obtainBuildableCells()
Provides a list of cells on which the selected player can build onvoid
obtainBuildingBlocks(Cell selectedCell)
Provides a list of blocks which the selected worker can build on the given cellvoid
obtainWalkableCells()
Provides a list of cells on which the selected player can walk tovoid
resetSelectedWorker()
Resets the worker to perform the next action to nullvoid
setGame(Game game)
Sets whatgame
the Player is playingvoid
setSelectedWorker(Worker selectedWorker)
Sets the worker to perform the next actionvoid
useAction(Action action)
Applies the given action
-
Constructor Details
-
Player
Creates a new Player, assigning itsname
, thegod
it chose and thecolor
assigned to its workers.Since some Gods allow the player to have more than two workers, the constructor initializes the
workers
as 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 theGame
is 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 whatgame
the 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:
addWorker
in 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:
allWorkersArePlaced
in interfacePlayerInterface
- Returns:
- true if all the player's workers have been placed, false otherwise
-
useAction
Applies the given action- Specified by:
useAction
in interfacePlayerInterface
- Parameters:
action
- the action to be applied- Throws:
IllegalActionException
- if the action cannot be performed
-
askPassTurn
Ends the player's turn- Specified by:
askPassTurn
in 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:
setSelectedWorker
in 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:
obtainBuildingBlocks
in 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:
obtainWalkableCells
in 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:
obtainBuildableCells
in 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:
addWorkerListener
in interfacePlayerInterface
- Parameters:
addWorkerListener
- the listener to add to the list
-
addBuildableCellsListener
Adds a new listener- Specified by:
addBuildableCellsListener
in interfacePlayerInterface
- Parameters:
buildableCellsListener
- the listener to add to the list
-
addWalkableCellsListener
Adds a new listener- Specified by:
addWalkableCellsListener
in interfacePlayerInterface
- Parameters:
walkableCellsListener
- the listener to add to the list
-
addSelectWorkerListener
Adds a new listener- Specified by:
addSelectWorkerListener
in interfacePlayerInterface
- Parameters:
selectWorkerListener
- the listener to add to the list
-
addBuildingBlocksListener
Adds a new listener- Specified by:
addBuildingBlocksListener
in 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:
equals
in 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:
hashCode
in classjava.lang.Object
-