Need help answering a homework question for Java. The game consists of a mainboard grid made of multiple points that could use default values or user-defined dimensions, and the number of ships. The...

1 answer below »

Need help answering a homework question for Java.


The game consists of a mainboard grid made of multiple points that could use default values or user-defined dimensions, and the number of ships. The game consists of setting up the game grid, place random ships, and the player firing shots trying to guess the location of the hidden ships. The game should display the statistics of the game after each shot, such as the number of ships sunk, and the number of shots fired. The game ends once the player has successfully guessed the location of all the ships (sunk). The game must be completely functional and must have the following characteristics. Feel free to develop the logic as is best for you, just respect the methods’ names and structure.



  1. A class named Board will constitute the game-playing board. Include a main() method to call the internal functions (methods).

  2. Two constructors, one default with a board 5 by five and 3 ships. The second constructor will take parameters for the width, and the length of the board, and the number of ships.

  3. A function to initialize the board; name it to initialize(). No parameters or return value.

  4. A function to show the board's current state. Name it show(). No parameters or return value.

  5. A function to randomize the position of the ships; name it randomize(int r, int c) with a int[] return for the values of row and column. With the number of rows and columns as a boundary for the random generation.

  6. A function to place the ships; call it placeShips(int n) with an integer parameter to input the number of ships, and no return value.

  7. A function to return a Boolean value if the ship exists with two input coordinates to place the shot. Name it shipExists()

  8. A function to fire into the enemy with a parameter to determine the number of shots. Name it fire(int s).

  9. A function named scoreBoard() to print the number of kills and the number of shots so far. No parameters or return value.

  10. The main() function will sequence the events for the game to progress. For example:

    Public static void main(String[] args){



    New Board board = new Board(10,10,5);



    board.show();



    board.placeShips();



    board.fire();



    .


    }//end of main



Answered 38 days AfterMay 06, 2021

Answer To: Need help answering a homework question for Java. The game consists of a mainboard grid made of...

Arun Shankar answered on Jun 14 2021
158 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here