In this challenge, you have to build a Class that will store and manipulate the data of a simplified clone of Battleship, the popular strategy game.
The game is played on a square board, 5x5 sized. The rows of the grid are identified by uppercase letters from A to E (from top to bottom), and the columns are identified by numbers from 1 to 5 (from left to right).
Each instance in the Tests tab will be declared with two variable parameters so the constructor has to be initialized with:
scheme is the link to an array containing 9 strings being the coordinates indicating where the ships are placed in the grid.input is the link to an array containing 6 strings being the guesses made by the user.The Tests will verify the existence and the correctness of the data through an instance that will use the Battleship Class created by you, calling its four different methods:
board() will return the final state of the board, based on the placement of the ship and the results of the user guesses, as a matrix of 5x5 size. To represent the graphic of the game, you will use four different characters:
hits() will return the total number of hits made by the user (correct guesses), either on Patrols or on Cruisers.
sunk() will return the total number of sunk Cruisers (two adjacent guesses, in horizontal or vertical).
points() will return the total number of points gained by the user (1 for every hit, 2 for every sunk Cruiser).
// scheme =
["A1", "C1", "B2",
"B3", "D2", "E2",
"E4", "E5", "A5"]
// input = ["A1", "B2", "C3", "D4", "E5", "E4"]
battleship.board() ➞ [
[☀, ○, ○, ○, ●],
[○, ☀, ●, ○, ○],
[●, ○, ☼, ○, ○],
[○, ●, ○, ☼, ○],
[○, ●, ○, ☀, ☀]
]
battleship.hits() ➞ 4
// Total hits.
battleship.sunk() ➞ 1
// Sunk Cruisers, not Patrols.
battleship.points() ➞ 6
// Hits + additional points given by Sunk Cruisers.