Question: You will need to implement the following functions in addition to main: Write the algorithm before writing the code and include a short writeup of

You will need to implement the following functions in addition to main:
Write the algorithm before writing the code and include a short writeup of algorithm in a text file AND code.
A function drawBoard that takes one parameter as input: a 10 x 10 array(or list) of chars that represents the board. The function then displays the contents of the array(or list)- columns to the right, rows down (see my sample output). The numbers 0-9 should be displayed along the top and left sides of the drawing to easily identify each column/row on the board. Each square should display one of four possible characters:
A dot . for any square that does not contain a ship and that has not yet been called out by the user at the keyboardThe letter S to represent one of the 5 ships on the boardThe letter O to represent a row/column that was called out but did not contain a ship (i.e., a miss)The letter X to represent a row/column that was called out and there was a ship there (i.e., a hit)
A function isGameOver that takes one parameter as input: a 10 x 10 array(or list) of chars that represents the board. The function should return true if all the ships on the board have been hit/sunk (i.e., all of the S squares have been replaced by X) and false otherwise.
A function setupBoard. The function should create a two-dimensional array(or list) that represents the board with each square initialized to a dot .. Then there should be an S for each of the number of ships specified by the NUM_SHIPS constant. The ships should be placed on the board randomly using the Random class to pick a random row and column. If the same row/column is picked more than once, the function should continue to loop until all the ships are placed on different squares. So, if NUM_SHIPS ==5, there should be 5 different squares with an S and the rest of the squares should contain a dot . character.
A function checkHitOrMiss that takes three parameters as input: a 10 x 10 array(or list) of chars that represents the board, and the column and row. The column and row represent the column and row entered by the user on the keyboard. The function should check that column and row on the board and do the following:
If the square contains a ship S, that square on the board should be updated to an X to represent a hit and return the String HITIf the square already contains a sunk ship X, simply return the String HITOtherwise, that square on the board should be updated to an O to represent a miss and return the String MISS
Your main function should do the following:
Set up the game board
Draw the board and prompt the user to enter a column (X)
If the column is not a valid column on the board (i.e. less than 0 or greater than or equal to 10), display Invalid column and go back and ask the user to try again without checking the board
Draw the board and prompt the user to enter a row (Y)
If the row is not a valid row on the board (i.e. less than 0 or greater than or equal to 10), display Invalid row and go back and ask the user to try again without checking the board
If the column and row are valid, check if the column/row is a hit or miss and print out the result to the user (MISS or HIT)
Update the board with the appropriate character for the square that was entered (O,X)
If all the ships have been HIT and sunk, draw the board one last time then print GAME OVER! and end the game
Otherwise, loop back to Step 2 and repeat until the game is over.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!