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
    Player getCurrentPlayer()  
    boolean getGameAlive()  
    int getNumberOfPlayers()  
    int getTurnCounter()  
    int handleCyclicalCounter​(int cyclicalCounter)
    Handles cyclical counter when number of Players changes.
    void handleGameChange​(java.lang.String loserNickname)
    Handles the turn flow and resizes the game players dimension when someone loses.
    boolean numberOfPLayersHasChanged()  
    void run()
    Describes and divides the flow of the turns in two phases: the setup of the game and the its strategy gaming phase.
    void setNumberOfPlayers​(java.lang.Integer numberOfPlayers)  
    void setNumberOfPLayersHasChanged​(boolean numberOfPLayersHasChanged)  
    void setUpTurns()
    Executes the preparation of the game.
    void stopTurnFlow()
    Sets the attribute gameAlive to the false value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TurnHandler

      public TurnHandler​(Game game, GameController gameController)
      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:
      run in interface java.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

      public Player 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()