The game of Battleships involves two players. Each player has a stock of ships of different classes. The player arranges these vertically or horizontally on a grid. Each class of ship occupies a different number of grid squares. In the paper-based version of this game the squares are addressed by column (letter) and row (number). Each player has their own grid which does not overlap their opponent’s grid.
Players cannot see their opponent’s ships. Players take it in turns to direct fire at grid coordinates. Different variations of the game allow different numbers of ‘shots’. A common approach is to allow the same number of shots as the player has ships remaining.
After a player has taken his or her turn, the opponent reports on the success of each shot. In the paper-based version of the game this comprises listing the grid coordinates targeted, together with a ‘hit’ or ‘miss’ report. If all of the grid coordinates occupied by a particular ship have been hit then the ‘hit’ message is replaced with a ‘sunk’ message.
The winner is the player who has sunk all of his or her opponent’s ships.
The task is to implement this game using a client-server approach. The server will allow users to request to join a game. When two players have elected to play, they will each be invited to place their ships on a grid. You are urged to focus on the communications protocols to be adopted initially. This is best achieved by implementing a text based version of the game in which everything is achieved though the communication of grid coordinates and damage messages.
The server should be able to support multiple games concurrently.
Having developed and tested such a text-based version, you may proceed to develop appropriate user interfaces. If a graphics interface is chosen you may use a third party library that supports graphics on either the server or the client. Alternatively, it is perfectly feasible to implement the interface using a client-side scripting language to manipulate images within a grid constructed using HTML and CSS. Sound and other appropriate multimedia content may be used.
Better solutions will permit basic configuration of the game. For example by allowing the number and type of ships to be specified or by defining the rule employed to determine the number of shots available at each ‘turn’.
A brief document should accompany with this work. This must document overall design particularly focussing on:
The persistence mechanism used
The communications protocol
The software architecture
The design and implementation of the user interface