Class BuildBeforeAfterMovement
- All Implemented Interfaces:
RuleSetStrategy
public class BuildBeforeAfterMovement extends AffectMyTurnStrategy
This effect alters the player's turn order; either, the player can:
- Play the turn as usual, following the
RuleSetBase
- Build a block, move on a level not higher than the current one, then build again
-
Field Summary
Fields inherited from class it.polimi.ingsw.model.rules.RuleSetBase
buildsAvailable, game, hasMovedUp, movedWorker, movesAvailable, movesUpAvailable, startingCell
-
Constructor Summary
Constructors Constructor Description BuildBeforeAfterMovement()
Default constructor -
Method Summary
Modifier and Type Method Description boolean
checkLoseCondition()
Checks if the turn can beginboolean
checkLoseCondition(BuildAction buildAction)
Determines if the lose conditions are satisfied upon a build actionRuleSetStrategy
cloneStrategy(Game game)
Creates a clone of this objectvoid
doEffect()
Applies end turn effectsjava.util.List<Cell>
getBuildableCells(Worker worker)
Provides a list of cells on which the worker can build onjava.util.List<PossibleActions>
getPossibleActions(Worker worker)
Provides a list of possible actions for a player to perform, based on the chosen workerjava.util.List<Cell>
getWalkableCells(Worker worker)
Provides a list of cells on which the worker can walk onvoid
initialize()
Sets the parameters for a new turnboolean
isBuildActionValid(BuildAction action)
Determines if a buildAction is legal and applies itboolean
isMoveActionValid(MoveAction action)
Determines if a moveAction is legal and applies itMethods inherited from class it.polimi.ingsw.model.rules.RuleSetBase
addBuildableCells, addWalkableCells, canBuild, canEndTurn, canEndTurnAutomatically, checkLoseCondition, checkWinCondition, getBlocks, getBuildsAvailable, getMovedWorker, getMovesAvailable, getMovesUpAvailable, hasMovedUp, isCorrectBlock, isCorrectDistance, isInsideBuildableCells, isInsideWalkableCells, setGame, setMovesUpAvailable
-
Constructor Details
-
BuildBeforeAfterMovement
public BuildBeforeAfterMovement()Default constructor- See Also:
initialize()
-
-
Method Details
-
initialize
public void initialize()Sets the parameters for a new turnUsing this ruleSet, a player is granted one movement and two building action, to be performed by the same worker following the rules mentioned in the class documentation.
The attributestuckWorkers
is needed because, using this effect, it is possible to lose after performing a build action; this counter keeps track of the number of the controlled workers that can perform no action during the turn- Overrides:
initialize
in classRuleSetBase
-
doEffect
public void doEffect()Applies end turn effectsUsing this ruleSet, the end turn effects simply resets the attributes changed during the turn
- Specified by:
doEffect
in interfaceRuleSetStrategy
- Overrides:
doEffect
in classRuleSetBase
-
getPossibleActions
Provides a list of possible actions for a player to perform, based on the chosen workerg this ruleSet, the possible actions for a worker are:
- Change Worker/Move/Build, if the worker has not been moved yet
- Move, if the worker built as its first action
- Build, if the worker has been moved
- None, in any other case
- Specified by:
getPossibleActions
in interfaceRuleSetStrategy
- Overrides:
getPossibleActions
in classRuleSetBase
- Parameters:
worker
- the worker to perform an action with- Returns:
- a list of possible performable actions
-
isMoveActionValid
Determines if a moveAction is legal and applies itg this ruleSet, a movement action is considered valid if the following conditions are all true:
- no worker has been moved yet during the turn OR the worker has built but has not been moved
- the target cell is a walkable cell (see getWalkableCells(Worker)) for the worker to be moved
- Specified by:
isMoveActionValid
in interfaceRuleSetStrategy
- Overrides:
isMoveActionValid
in classRuleSetBase
- Parameters:
action
- the movement action to validate- Returns:
- true if the action has been applied, false otherwise
-
isBuildActionValid
Determines if a buildAction is legal and applies itg this ruleSet, a build action is considered valid if the following conditions are all true:
- no worker has been moved yet OR the worker to perform the action has already been moved
- the cell to build on is a buildable cell (see getBuildableCells(Worker)) for the worker
- Specified by:
isBuildActionValid
in interfaceRuleSetStrategy
- Overrides:
isBuildActionValid
in classRuleSetBase
- Parameters:
action
- the build action to validate- Returns:
- true if the action has been applied, false otherwise
-
checkLoseCondition
public boolean checkLoseCondition()Checks if the turn can beginUsing this ruleSet, a player's turn can start if at least one of the player's workers can perform a movement action
- Specified by:
checkLoseCondition
in interfaceRuleSetStrategy
- Overrides:
checkLoseCondition
in classRuleSetBase
- Returns:
- true if there is at least one action to perform, false otherwise
-
checkLoseCondition
Determines if the lose conditions are satisfied upon a build actionUsing this ruleSet, the player can lose after performing a build action: since the worker cannot be moved upwards if the player decides to build first, it can lose if, after placing the building block, all the cells around him become inaccessible
- Specified by:
checkLoseCondition
in interfaceRuleSetStrategy
- Overrides:
checkLoseCondition
in classRuleSetBase
- Parameters:
buildAction
- the action to analyze- Returns:
- true if the action led to a loss, false otherwise
-
getWalkableCells
Provides a list of cells on which the worker can walk onUsing this ruleSet, a worker can walk on the cells adjacent to its starting cell which height difference is at most one compared to the starting cell (domes do not count), is not occupied by another worker and has no dome built on it
- Specified by:
getWalkableCells
in interfaceRuleSetStrategy
- Overrides:
getWalkableCells
in classRuleSetBase
- Parameters:
worker
- the worker to be moved- Returns:
- a list of walkable cells
-
getBuildableCells
Provides a list of cells on which the worker can build onUsing this ruleSet, a worker can build on any cell adjacent to its cell, in both the cases mentioned above
- Specified by:
getBuildableCells
in interfaceRuleSetStrategy
- Overrides:
getBuildableCells
in classRuleSetBase
- Parameters:
worker
- the worker to build with- Returns:
- a list of buildable cells
-
cloneStrategy
Creates a clone of this object- Specified by:
cloneStrategy
in interfaceRuleSetStrategy
- Overrides:
cloneStrategy
in classRuleSetBase
- Parameters:
game
- the current game- Returns:
- a clone of this object
-