java.lang.Object
model.logic.host.GameManager
- All Implemented Interfaces:
Serializable,GameHandler
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidThe addPlayer function adds a player to the gameData object.The challenge function sends a challenge request to the calculation server.voidThe fillHand function is used to fill the player's hand with 7 tiles.static GameManagerget()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.intThe getCurrentPlayerID function returns the ID of the current player.The getGameData function returns the gameData object.The getTurnManager function returns the turnManager object.voidThe initializeGame function initializes the turnManager object, which is used to keep track of whose turn it is.voidinitializeHostServer(int port) The initializeHostServer function initializes the host server.voidThe initializeTurnManager function is used to initialize the turnManager object.booleanThe isGameRunning function returns a boolean value that indicates whether the game is running.The query function takes in a word and returns the score of that word.voidremovePlayer(int playerId) voidsetCalculationServerIp(String calculationServerIp) The setCalculationServerIp function sets the calculationServerIp variable to the value of its parameter.voidskipTurn()The skipTurn function is called when the player clicks on the "Skip Turn" button.voidThe startGame function is called when the game is ready to begin.voidstopGame()The stopGame function is called when the game has ended.The submit function is called when a player submits a word to the board.voidThe swapTiles function is called when the player clicks on the "Swap Tiles" button.
-
Method Details
-
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
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
The addPlayer function adds a player to the gameData object.- Specified by:
addPlayerin interfaceGameHandler- Parameters:
clientName- clientName Add a new player to the game data
-
submit
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:
submitin interfaceGameHandler- Parameters:
wordData- wordData Get the data from the client- Returns:
- A string, which is then parsed by the front end
-
challenge
The challenge function sends a challenge request to the calculation server. The format of the request is "C,<dictionary>,<word>".- Specified by:
challengein interfaceGameHandler- Parameters:
word- word Send the word to the calculation server- Returns:
- A string in the form of "c,<result>,<error>"
-
query
The query function takes in a word and returns the score of that word.- Specified by:
queryin interfaceGameHandler- 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:
swapTilesin interfaceGameHandler
-
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:
skipTurnin interfaceGameHandler
-
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
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
The setCalculationServerIp function sets the calculationServerIp variable to the value of its parameter.- Parameters:
calculationServerIp- calculationServerIp Set the value of the calculationServerIp variable
-
getCalculationServerIp
The getCalculationServerIp function returns the IP address of the calculation server.- Returns:
- The ip address of the calculation server
-