- All Implemented Interfaces:
RuleSetStrategy
public class Swap extends MovementStrategy
This effect alters the workers' walkable cells: workers can swap their position with an opponent worker if it is in an adjacent cell
-
Field Summary
Fields inherited from class it.polimi.ingsw.model.rules.RuleSetBase
buildsAvailable, game, hasMovedUp, movedWorker, movesAvailable, movesUpAvailable, startingCell
-
Constructor Summary
Constructors Constructor Description Swap()
Default constructor -
Method Summary
Modifier and Type Method Description RuleSetStrategy
cloneStrategy(Game game)
Creates a clone of this objectjava.util.List<Cell>
getWalkableCells(Worker worker)
Provides a list of cells on which the worker can walk onboolean
isMoveActionValid(MoveAction action)
Determines if a moveAction is legal and applies itvoid
swapAction(MoveAction action)
Applies the action and eventually swaps the target cell's occupant positionMethods inherited from class it.polimi.ingsw.model.godCardsEffects.movementEffects.MovementStrategy
canGo, isNotSameOwner
Methods inherited from class it.polimi.ingsw.model.rules.RuleSetBase
addBuildableCells, addWalkableCells, canBuild, canEndTurn, canEndTurnAutomatically, checkLoseCondition, checkLoseCondition, checkLoseCondition, checkWinCondition, doEffect, getBlocks, getBuildableCells, getBuildsAvailable, getMovedWorker, getMovesAvailable, getMovesUpAvailable, getPossibleActions, hasMovedUp, initialize, isBuildActionValid, isCorrectBlock, isCorrectDistance, isInsideBuildableCells, isInsideWalkableCells, setGame, setMovesUpAvailable
-
Constructor Details
-
Swap
public Swap()Default constructor- See Also:
RuleSetBase.initialize()
-
-
Method Details
-
swapAction
Applies the action and eventually swaps the target cell's occupant position- Parameters:
action
- the action to be performed
-
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
- 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
-
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) and has no dome built on it; a worker can walk on a cell occupied by another worker (if the opponent worker's cell satisfies the condition above mentioned). If moving in a cell determines an immediate loss, the cell causing this behavior is not considered walkable; if all the cells lead to an immediate loss, the rule above is no longer applied and the player is free to choose which move to make before losing (see canBuildOnAtLeastOneCell(Cell))
- Specified by:
getWalkableCells
in interfaceRuleSetStrategy
- Overrides:
getWalkableCells
in classRuleSetBase
- Parameters:
worker
- the worker to be moved- Returns:
- a list of walkable 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
-