Game API Reference (Client) - djungowski/node-battleship GitHub Wiki
Game Methods
Game::noConnection()
Shows a modal window with a specific error message when the connection was lost or no connection can be made
Game::serverFull()
Shows a modal window with a specific error message when the server is full
Game::init()
Initializes the game. Requires a successful connection
Game::setPlayerName(player, name)
Sets your or the opponents player name
Argument | type | description | possible values |
---|---|---|---|
player |
String |
For which player the name is set. | "you", "opponent" |
name |
String |
The player's name |
Game::start()
Starts the game
Game::setActivePlayer(player)
Sets the the active player
Argument | type | description | possible values |
---|---|---|---|
player |
String |
Who is the active player. | "you", "opponent" |
Game::setFieldStatus(player, shootData)
Sets the field status for a field. This can be a miss or a hit.
Argument | type | description | possible values |
---|---|---|---|
player |
String |
The player whose field shall be updated. | "you", "opponent" |
shootData |
Object |
The data from the hit/miss event from the server |
Game::end(status)
Ends the game.
Argument | type | description | possible values |
---|---|---|---|
status |
String |
Whether you won or lost the game. | "win", "lost" |
Game::setShips(ships)
Set the ships for your field. Takes the return from the socket call "getPlacements" as argument.
Argument | type | description | possible values |
---|---|---|---|
ships |
Array |
The array of ships |