Class TurnHandler
java.lang.Object
it.polimi.ingsw.server.controller.TurnHandler
- All Implemented Interfaces:
java.lang.Runnable
public class TurnHandler
extends java.lang.Object
implements java.lang.Runnable
Allows to handle the turns of the players, from the beginning, when the game parameters need to be set,
until when one of the players wins the game.
Players are will be playing the game in a cyclical way.
-
Constructor Summary
Constructors Constructor Description TurnHandler(Game game, GameController gameController)Instances the TurnHandler for a specific game. -
Method Summary
Modifier and Type Method Description PlayergetCurrentPlayer()booleangetGameAlive()intgetNumberOfPlayers()intgetTurnCounter()inthandleCyclicalCounter(int cyclicalCounter)Handles cyclical counter when number of Players changes.voidhandleGameChange(java.lang.String loserNickname)Handles the turn flow and resizes the game players dimension when someone loses.booleannumberOfPLayersHasChanged()voidrun()Describes and divides the flow of the turns in two phases: the setup of the game and the its strategy gaming phase.voidsetNumberOfPlayers(java.lang.Integer numberOfPlayers)voidsetNumberOfPLayersHasChanged(boolean numberOfPLayersHasChanged)voidsetUpTurns()Executes the preparation of the game.voidstopTurnFlow()Sets the attribute gameAlive to the false value.
-
Constructor Details
-
TurnHandler
Instances the TurnHandler for a specific game.- Parameters:
game- The game the TurnHandler refers to.gameController- The GameController from which the game has been created.
-
-
Method Details
-
run
public void run()Describes and divides the flow of the turns in two phases: the setup of the game and the its strategy gaming phase. Runs until one of the player wins the game or a disconnection occurs.- Specified by:
runin interfacejava.lang.Runnable
-
setUpTurns
public void setUpTurns()Executes the preparation of the game. -
handleCyclicalCounter
public int handleCyclicalCounter(int cyclicalCounter)Handles cyclical counter when number of Players changes.- Parameters:
cyclicalCounter- value of counter when numOfPlayers decreases.- Returns:
- The new value of cyclicalCounter.
-
handleGameChange
public void handleGameChange(java.lang.String loserNickname)Handles the turn flow and resizes the game players dimension when someone loses. Lets other players know that one of thw players has lost the game and so will be removed from the current game.- Parameters:
loserNickname- The nickname of the loser.
-
stopTurnFlow
public void stopTurnFlow()Sets the attribute gameAlive to the false value. The game is no more playable. -
getGameAlive
public boolean getGameAlive() -
getCurrentPlayer
-
setNumberOfPLayersHasChanged
public void setNumberOfPLayersHasChanged(boolean numberOfPLayersHasChanged) -
numberOfPLayersHasChanged
public boolean numberOfPLayersHasChanged() -
setNumberOfPlayers
public void setNumberOfPlayers(java.lang.Integer numberOfPlayers) -
getNumberOfPlayers
public int getNumberOfPlayers() -
getTurnCounter
public int getTurnCounter()
-