Class GameManager

java.lang.Object
model.logic.host.GameManager
All Implemented Interfaces:
Serializable, GameHandler

public class GameManager extends Object implements GameHandler, Serializable
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addPlayer(String clientName)
    The addPlayer function adds a player to the gameData object.
    The challenge function sends a challenge request to the calculation server.
    void
    fillHand(Player player)
    The fillHand function is used to fill the player's hand with 7 tiles.
    get()
    The get function is a static function that returns the singleton instance of GameManager.
    The getCalculationServerIp function returns the IP address of the calculation server.
    int
    The getCurrentPlayerID function returns the ID of the current player.
    The getGameData function returns the gameData object.
    The getTurnManager function returns the turnManager object.
    void
    The initializeGame function initializes the turnManager object, which is used to keep track of whose turn it is.
    void
    The initializeHostServer function initializes the host server.
    void
    The initializeTurnManager function is used to initialize the turnManager object.
    boolean
    The isGameRunning function returns a boolean value that indicates whether the game is running.
    query(Word word)
    The query function takes in a word and returns the score of that word.
    void
    removePlayer(int playerId)
     
    void
    setCalculationServerIp(String calculationServerIp)
    The setCalculationServerIp function sets the calculationServerIp variable to the value of its parameter.
    void
    The skipTurn function is called when the player clicks on the "Skip Turn" button.
    void
    The startGame function is called when the game is ready to begin.
    void
    The stopGame function is called when the game has ended.
    submit(String wordData)
    The submit function is called when a player submits a word to the board.
    void
    The swapTiles function is called when the player clicks on the "Swap Tiles" button.

    Methods inherited from class java.lang.Object

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

    • get

      public static GameManager get()
      The get function is a static function that returns the singleton instance of GameManager. If no instance exists, it creates one and then returns it.
      Returns:
      A singleton instance of the game manager class
    • initializeTurnManager

      public void initializeTurnManager()
      The initializeTurnManager function is used to initialize the turnManager object. It does this by adding all players to the turnManager, and then setting up a list of turns for each player.
    • initializeHostServer

      public void initializeHostServer(int port)
      The initializeHostServer function initializes the host server.
      Parameters:
      port - port Set the port number that the host server will listen on
    • isGameRunning

      public boolean isGameRunning()
      The isGameRunning function returns a boolean value that indicates whether the game is running.
      Returns:
      A boolean value
    • initializeGame

      public void initializeGame()
      The initializeGame function initializes the turnManager object, which is used to keep track of whose turn it is. It also sets up the game board and adds all the pieces to their respective teams.
    • startGame

      public void startGame()
      The startGame function is called when the game is ready to begin. It initializes the turnManager, fills each player's hand with cards, and then calls startGame on the host.
    • fillHand

      public void fillHand(Player player)
      The fillHand function is used to fill the player's hand with 7 tiles.
      Parameters:
      player - player Pass in the player object that will be used to fill their hand
    • addPlayer

      public void addPlayer(String clientName)
      The addPlayer function adds a player to the gameData object.
      Specified by:
      addPlayer in interface GameHandler
      Parameters:
      clientName - clientName Add a new player to the game data
    • submit

      public String submit(String wordData)
      The submit function is called when a player submits a word to the board. It takes in the data of the word, and checks if it can be placed on the board. If it can, then it places that word on the board and updates all necessary information.
      Specified by:
      submit in interface GameHandler
      Parameters:
      wordData - wordData Get the data from the client
      Returns:
      A string, which is then parsed by the front end
    • challenge

      public String challenge(String word)
      The challenge function sends a challenge request to the calculation server. The format of the request is "C,<dictionary>,<word>".
      Specified by:
      challenge in interface GameHandler
      Parameters:
      word - word Send the word to the calculation server
      Returns:
      A string in the form of "c,<result>,<error>"
    • query

      public String query(Word word)
      The query function takes in a word and returns the score of that word.
      Specified by:
      query in interface GameHandler
      Parameters:
      word - word Get the tiles in the word string.
      Returns:
      A string that is a comma separated list of words
    • swapTiles

      public void swapTiles()
      The swapTiles function is called when the player clicks on the "Swap Tiles" button. It removes all the tiles from a player's hand and replaces them with new ones.
      Specified by:
      swapTiles in interface GameHandler
    • skipTurn

      public void skipTurn()
      The skipTurn function is called when the player clicks on the "Skip Turn" button. It resets the timer task, which will cause it to be run again after a certain amount of time has passed.
      Specified by:
      skipTurn in interface GameHandler
    • getGameData

      public GameData getGameData()
      The getGameData function returns the gameData object.
      Returns:
      The game data object
    • getCurrentPlayerID

      public int getCurrentPlayerID()
      The getCurrentPlayerID function returns the ID of the current player.
      Returns:
      The current player id
    • getTurnManager

      public TurnManager getTurnManager()
      The getTurnManager function returns the turnManager object.
      Returns:
      The turn manager object
    • removePlayer

      public void removePlayer(int playerId)
    • stopGame

      public void stopGame()
      The stopGame function is called when the game has ended. It calls the nextTurn function in turnManager, which will end the game. Then it calls stopGame in host, which will close all of its sockets and streams.
    • setCalculationServerIp

      public void setCalculationServerIp(String calculationServerIp)
      The setCalculationServerIp function sets the calculationServerIp variable to the value of its parameter.
      Parameters:
      calculationServerIp - calculationServerIp Set the value of the calculationServerIp variable
    • getCalculationServerIp

      public String getCalculationServerIp()
      The getCalculationServerIp function returns the IP address of the calculation server.
      Returns:
      The ip address of the calculation server