Class GameStateController
java.lang.Object
it.polimi.ingsw.server.controller.game_state_controller.GameStateController
- All Implemented Interfaces:
GameStateControllerCommonInterface
- Direct Known Subclasses:
ExpertGameStateController
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanprivate voidprivate voidThis method defines the round order comparing the values of the cards played by different playersbooleanThis method performs all the controls before ending the player's turn and starting the next player's turn(package private) int(package private) LightGameStateThis method verifies if there is a schoolBoard that is more influent than all the others on the archipelago on which motherNature is, and returns its schoolBoardIdgetSchoolBoardIDFromTowerColor(TowerColor towerColor) getSchoolBoardTowerColorFromID(Integer schoolBoardID) This method returns the TowerColor of the schoolBoardId provided If there is a problem finding the schoolBoard i.e. the user provided SchoolBoardID > 3, it returns TowerColor.NONEvoidgrabStudentsFromCloud(int cloudIndex) This method performs all the checks required by the rules and then, if all of them are met, modifies the gameState grabbing the students from the chosen cloud.protected GameStateinitializeGameState(int playersNumber) This method initializes the correct gameState with its attributesbooleanmoveMotherNature(int nSteps) This method performs all the checks required by the rules and then, if all of them are met, modifies the gameState moving motherNature.voidmoveStudentFromEntranceToArchipelago(Color student, List<Integer> archipelagoIslandCodes) This method performs all the checks required by the rules and then, if all of them are met, modifies the gameState moving the inputted student to the inputted archipelago.voidmoveStudentFromEntranceToDiningRoom(Color student) This method performs all the checks required by the rules and then, if all of them are met, modifies the gameState moving the inputted student to its corresponding diningRoomLane.protected voidThis method advances the turn during the action phase, after a player ended its turn.private voidThis method advances the turn during the planning phase, after a player played an assistant cardbooleanThis method gets a card in input, verifies if the current phase is PLANNING and then modifies the gameState accordinglyvoidrollback()voidsetCurrentPhaseForTesting(Phase phase) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface it.polimi.ingsw.server.controller.game_state_controller.GameStateControllerCommonInterface
applyEffect, applyEffect, applyEffect, applyEffect, applyEffect
-
Field Details
-
gameState
-
-
Constructor Details
-
GameStateController
-
GameStateController
-
-
Method Details
-
initializeGameState
protected GameState initializeGameState(int playersNumber) throws GameStateInitializationFailureException This method initializes the correct gameState with its attributes- Parameters:
playersNumber- is the number of players- Returns:
- the newly created GameState
- Throws:
GameStateInitializationFailureException- if there was a failure in the initialization procedure
-
playCard
public boolean playCard(Card card) throws CardIsNotInTheDeckException, InvalidCardPlayedException, WrongPhaseException, MoveAlreadyPlayedException This method gets a card in input, verifies if the current phase is PLANNING and then modifies the gameState accordingly- Parameters:
card- is the card that the player chose to play- Throws:
CardIsNotInTheDeckException- if the current player does not actually own the card to be played.InvalidCardPlayedException- if another player already played the same card in this round, and it is not the final round.WrongPhaseException- if the method is executed in the wrong phase.MoveAlreadyPlayedException
-
moveStudentFromEntranceToDiningRoom
public void moveStudentFromEntranceToDiningRoom(Color student) throws StudentNotInTheEntranceException, FullDiningRoomLaneException, WrongPhaseException, TooManyStudentsMovedException This method performs all the checks required by the rules and then, if all of them are met, modifies the gameState moving the inputted student to its corresponding diningRoomLane.- Parameters:
student- indicates the color of the player that has to be moved.- Throws:
StudentNotInTheEntranceException- if the player that has to be moved is not actually in the entrance of the current player's schoolBoard.FullDiningRoomLaneException- if the diningRoomLane corresponding to the student that has to be moved is already full.WrongPhaseException- if the method is executed in the wrong phase.TooManyStudentsMovedException- if the player has already moved the maximum number of students allowed by the rules.
-
moveStudentFromEntranceToArchipelago
public void moveStudentFromEntranceToArchipelago(Color student, List<Integer> archipelagoIslandCodes) throws StudentNotInTheEntranceException, WrongPhaseException, TooManyStudentsMovedException This method performs all the checks required by the rules and then, if all of them are met, modifies the gameState moving the inputted student to the inputted archipelago.- Parameters:
student- indicates the color of the player that has to be moved.archipelagoIslandCodes- indicates the archipelago, identified through its islandCodes, onto which the student has to be moved.- Throws:
StudentNotInTheEntranceException- if the player that has to be moved is not actually in the entrance of the current player's schoolBoard.WrongPhaseException- if the method is executed in the wrong phase.TooManyStudentsMovedException- if the player has already moved the maximum number of students allowed by the rules.
-
moveMotherNature
public boolean moveMotherNature(int nSteps) throws InvalidNumberOfStepsException, WrongPhaseException, MoreStudentsToBeMovedException, MoveAlreadyPlayedException, GameOverException This method performs all the checks required by the rules and then, if all of them are met, modifies the gameState moving motherNature.- Parameters:
nSteps- indicates the number of steps for which the player intends to move motherNature- Throws:
InvalidNumberOfStepsException- if the player provides a number of steps that isn't between 0 and the maximum number of steps that the player chose during the planning phase.WrongPhaseException- if the method is executed in the wrong phase.MoreStudentsToBeMovedExceptionMoveAlreadyPlayedExceptionGameOverException
-
grabStudentsFromCloud
public void grabStudentsFromCloud(int cloudIndex) throws EmptyCloudException, WrongPhaseException, MoveAlreadyPlayedException, MotherNatureToBeMovedException This method performs all the checks required by the rules and then, if all of them are met, modifies the gameState grabbing the students from the chosen cloud.- Parameters:
cloudIndex- indicates the index of the cloud from which the player wants to grab the students.- Throws:
EmptyCloudException- indicates that che chosen cloud is empty.WrongPhaseException- if the method is executed in the wrong phase.MoveAlreadyPlayedExceptionMotherNatureToBeMovedException
-
endActionTurn
public boolean endActionTurn() throws MoreStudentsToBeMovedException, MotherNatureToBeMovedException, StudentsToBeGrabbedFromCloudException, CardNotPlayedException, WrongPhaseException, GameOverExceptionThis method performs all the controls before ending the player's turn and starting the next player's turn- Throws:
MoreStudentsToBeMovedException- if the player didn't move all the students that he has to move before trying to end his turn.MotherNatureToBeMovedException- if the player didn't move motherNature before trying to end his turn.StudentsToBeGrabbedFromCloudException- if the player didn't grab the students from a cloud before trying to end his turn.CardNotPlayedExceptionWrongPhaseExceptionGameOverException
-
rollback
public void rollback() -
cardPlayed
public boolean cardPlayed() -
checkStudentsToBeMoved
private void checkStudentsToBeMoved() -
defineRoundOrder
private void defineRoundOrder()This method defines the round order comparing the values of the cards played by different players -
nextPlanningTurn
private void nextPlanningTurn()This method advances the turn during the planning phase, after a player played an assistant card -
nextActionTurn
This method advances the turn during the action phase, after a player ended its turn.- Throws:
GameOverException- if a gameOver condition has occurred
-
getMostInfluentSchoolBoardIdOnMotherNaturesPosition
This method verifies if there is a schoolBoard that is more influent than all the others on the archipelago on which motherNature is, and returns its schoolBoardId- Returns:
- an integer representing the schoolBoardId of the most influent player on the archipelago on which motherNature is
-
getCurrentPlayerSchoolBoardId
int getCurrentPlayerSchoolBoardId() -
getSchoolBoardIds
-
getSchoolBoardIDFromTowerColor
-
getSchoolBoardTowerColorFromID
This method returns the TowerColor of the schoolBoardId provided If there is a problem finding the schoolBoard i.e. the user provided SchoolBoardID > 3, it returns TowerColor.NONE- Parameters:
schoolBoardID- of the player- Returns:
- the TowerColor of his schoolBoard
-
getLightGameState
LightGameState getLightGameState() -
getGameStateForTesting
-
setCurrentPhaseForTesting
-
getGameUUID
-