BattleShips is a simple game where there is a 2 dimensional grid of 25 by 25 tiles. Each player is given a ship that consists of 3 tiles, which is then placed onto this grid at a random location. Players can each send one torpedo a turn at chosen coordinates. The game will then tell the player if they hit an enemy ship, or if they missed their shot. A winner is declared when all but one ship have sunk.
This is the server for the BattleShips game. The client can be found at BattleShipsClient.
- Clone this repository or download and extract the zip file.
- Run the Main class.
- Enter the port number, or press enter to use the default port (55555).
- Wait for at least two players to join.
- Start the game and enjoy!
The server can be controlled using the following commands:
START- starts the gameSKIP- skips the current player (only works if the game has started)QUIT- exits the server
Communication between the client and the server uses the following protocol:
MOVE~x~y- to launch a torpedo, where x and y are the coordinates of the moveEXIT- to exit the gamePING- to check if the server is still alivePONG- response to a PING from the server
HELLO~playerNumber- where playerNumber is the playerNumber of the playerHIT~x~y~playerNumber- where x and y are the coordinates of the hit, and playerNumber is the playerNumber of the player that is hitMISS~x~y- where x and y are the coordinates of the missWINNER~playerNumber- where playerNumber is the playerNumber of the winnerLOST~playerNumber- where playerNumber is the playerNumber of the player who lostERROR~message- where message is the error messageEXIT- to exit the gameTURN~playerNumber- where playerNumber is the playerNumber of the player whose turn it isNEWGAME~x~y- where x and y are the width and height of the new gamePOS~x~y- where x and y are the coordinates of a ship partPING- to check if a client is still alivePONG- response to a PING from the client