Class MoveStudent
java.lang.Object
it.polimi.ingsw.Controller.Actions.PlayerAction
it.polimi.ingsw.Controller.Actions.MoveStudent
- All Implemented Interfaces:
Serializable
This
PlayerAction allows the caller to move a single student from the entrance to the school to an island or a dining room table. This action
is linked to the Action Phase.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final MoveDestinationprivate final intprivate static final long -
Constructor Summary
ConstructorsConstructorDescriptionMoveStudent(int playerBoardId, int selectedEntrancePosition, MoveDestination destination) Create a new instance of this class with the following inputs: -
Method Summary
Modifier and TypeMethodDescriptionprotected OptionalValue<InputValidationException>customValidation(List<PlayerAction> history, Model ctx) This function is used byPlayerAction.validate(List, Model)to check whether or not the declaredPlayerActionis possible.
This function will check for the following requirements:voidunsafeExecute(Model ctx) Every class extendingPlayerActionmust implement the following method, which takes aModelreference and applies the concrete effect of the action.Methods inherited from class it.polimi.ingsw.Controller.Actions.PlayerAction
getPlayerBoardID, validate
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
selectedEntrancePosition
private final int selectedEntrancePosition -
destination
-
-
Constructor Details
-
MoveStudent
Create a new instance of this class with the following inputs:- Parameters:
playerBoardId- the ID of the currentPlayerBoarddestination- aMoveDestinationvalue specifying where the selected student will be movedselectedEntrancePosition- id of the slot in the list returned byPlayerBoard.getEntranceStudents(), selects a student to be moved
-
-
Method Details
-
customValidation
protected OptionalValue<InputValidationException> customValidation(List<PlayerAction> history, Model ctx) This function is used byPlayerAction.validate(List, Model)to check whether or not the declaredPlayerActionis possible.
This function will check for the following requirements:- The
GamePhasemust beGamePhase.ACTION - The previous
PlayerActions must be eitherMoveStudentorPlayCharacterCardor the history must be empty - Only a limited number of actions like this one can be played (3 or 4 depending on the players)
- The student decleared to move must be part of the entrance on the
PlayerBoard - If the destination is
DestinationType.ISLANDthen the island ID must be within bounds (0 to 12 excluded) - If the destination is
DestinationType.DININGROOMthen the dining room must be able to contain the pawn
- Specified by:
customValidationin classPlayerAction- Parameters:
history- the controller stores aListof previousPlayerActions related to the player taking the current turn (at every new turn, the history is cleared). Some actions may use thisListto check for duplicates.ctx- a reference toModel. Some actions may use this reference to check for consistency between what the actions declares and what the Model offers.- Returns:
- An empty
OptionalValuein case of a successful validation. Otherwise the returnedOptionalValuecontains the relatedInputValidationException
- The
-
unsafeExecute
Description copied from class:PlayerActionEvery class extendingPlayerActionmust implement the following method, which takes aModelreference and applies the concrete effect of the action.
Warning: this function, as implied by the name, is unsafe. it should never be called by called outside the scope of the classController, which takes adequate precautions in order to guarantee a coherent execution of the method.- Specified by:
unsafeExecutein classPlayerAction- Parameters:
ctx- theModelreference, once the method finishes running the game state will be altered.- Throws:
Exception- Should an error occur during the execution of the method, such error will be reported through the thrownException. Note that anyPlayerActioninheritor should guarantee the absence of Exceptions for any positive return value yielded byPlayerAction.validate(List, Model)
-