The objective of this assessment is to test your understanding of all the topics covered in this component. It covers the following learning outcomes:

  • Ability to understand the basic features of C++.
  • Ability to understand and use conditional statements, loops, arrays, functions, pointers, references, strings and dynamic memory allocation in C++.
  • Ability to develop a simple text-based game using a disciplined approach.

Battleship:

Battleship, designed by Clifford Von Wickler but patented by Milton Bradley Company in 1943, is a classic board game that has been adapted into multiple formats over the years, including video games. In this summative, you will design and implement a program that replicates the Battleship game in C++.

Game-play and Rules:

The game is played on a set of four 10x10 grids, two for each player. On one of the grids, the player arranges the position of their ships and records shots made by the opponent. On the other grid, the player records their own shots that they have taken at the opponent. Each player has five ships of varying lengths, as follows:

Type of Ship Size (Length)
Aircraft Carrier 5
Battleship 4
Destroyer 3
Submarine 3
Patrol Boat 2

Figure 1: Ship types and lengths.

Before the game starts, each player arranges their ships on their grid, ensuring that the opponent does not know the position of the ships. No parts of any ships may overlap each other.

The game-play proceeds in a turn-based manner. In each turn, the player announces a grid position, identified by a letter and a number coordinate, that they will fire upon. If an opponent ship occupies the identified grid position, then the ship takes a hit in that square. The opponent then announces to the player if the player has scored a hit or not. A ship sinks when the ship is hit in all squares that it is occupying. When a player sinks all of the opponent's ships, the game ends and the player wins. This version of the game must have a graphical representation of both game boards of a player (a board representing the players ships and a board representing the players misses and hits at the opponent).

Required Game Features:

The game-play must be implemented as per the description under the Game-play and Rules section. Game-play must be bug free.

The game setup phase must allow the player to set up the ships' positions via one of two options:

  • Computer randomly generates positions and orientations for the player's ships.
  • Player specifies the position and orientation of each ship individually.

Both of the above options must be implemented.

There is to be only one game mode, single player, which allows one human player to play head- to-head with the computer AI. The AI does not need to be complex, but must be functional to allow an interactive game of Battleship.

A summary of the game must be displayed when a game is over, clearly identifying the winner.

The game must provide a Debug mode that displays the positions of the Computer's ships on the grid in game. The debug mode must be accessible from the main menu screen.

Build Quality:

The source code is required to display the following features:

  • Free of:
    • Build warnings at Warning Level 3 for all build targets.
    • Build errors at Warning Level 3 for all build targets.

Runtime Quality:

The source code is required to display the following features:

  • Free of:
    • Memory leaks.
    • Bugs (Bugs that are not game-play related).
    • Crashes.

Interface Features:

The executable is required to provide an intuitive interface with the following features:

  • Provide clear instructions.
  • Controls are clearly identifiable and intuitive while playing.
  • Design and layout of the game's interface make effective use of screen space.
  • All game state information, such as current game layout, ships hit and shots taken at the opponent must be clearly represented in a graphical manner.
  • A new game can be started without exiting the executable.

Optional Extra Features:

Extra features may be included in the implementation if desired, as long as the base game-play is still Battleship as specified above. Ensure the extra features enhance the quality of the game, rather than detracting from the submission.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.