Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
AE2: Battleship
There is a FAQ at the end of this document, please read it.
Introduction
Battleship is a popular board game involving 2 players. The aim of the game is for the players
to place their ships on a grid and then guess the positions of their opponents’ ships. Full rules
can be found here. https://www.thesprucecrafts.com/the-basic-rules-of-battleship-411069
In this assessment you are being asked to program a simpler version of this game. Initially,
the battleships will be placed on a 10x10 grid randomly, players will then proceed to guess
where the ships are on the board. If they guess correctly, they ‘hit’ the battleship, otherwise
they ‘miss’. The objective of the game for both players is to find and sink all the battleships
on the board. The player who hits more ships than the other, wins after all ships have been
destroyed.
In this assessment you will create classes and logic necessary to run a game of battleship.
This assessment is split into multiple sections. Partial marks will be awarded in this
assessment, so you do not need to complete the project in full to be awarded marks. A
maximum number of marks that can be awarded for each section is shown to help you manage
your time with this assessment.
The marking scheme is below. Marks will be awarded for:
- Functional correctness
- Sound OO design
- Clean, tidy and commented code
The marks are awarded out of 22. Remember that you do not need to complete the project to
be awarded marks. You do not need to complete a section or task to completion to be awarded
marks. Partial marks will be awarded in the event you can demonstrate an attempt that was
made to address the task.
Part 1: The Players and the Square classes
This following image provides an idea on what the board should look like:
There are 10 rows and 10 columns. Each cell in the board is a Square object. Each square
object must consist of:
- An integer denoting the row position, inclusive of 0.
- An integer denoting the column position, inclusive of 0.
- An attribute to indicate whether the square has a ship in it.
- A reference to a battleship if one is currently on the Square.
- An attribute to indicate whether the player has fired a shot at the square.
You will also require appropriate getters and setters to utilise this class within the assessment.
Each player class should have a reference to a board object they will play the game with. Their
name, and scores. Make these attributes private. The constructor to the Player class should
take in the name of the player, along with a reference to the board that will be associated with
the player object.
Each player will have a method to take turns. This method will be called from the main
controlling logic of the game.
[5 marks]
Part 2 – The board and Battleship classes
You are to specify a Battleship class. This class should specify the following attributes:
- Whether it is sunk.
- The remaining health (how many more hits it can take before sinking)
- The size of the ship.
Each Battleship object will be checked against whenever a player fires into the board on a
particular square. In the event the player hits the ship, it will be necessary for you to decrease
the health of the ship and of course update its state in the event the ship is destroyed. A
battleship should be specified as being 2 units in size, therefore it is to take up 2 squares when
it is placed on the board. The size of the ship will directly correspond to the amount of health
the ship has.