Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help intializing the multi-dimensional array below (I've commented the code that I have so far, but not sure what to do). I also

I need help intializing the multi-dimensional array below (I've commented the code that I have so far, but not sure what to do). I also need help printing the board and help with another method below that. Encoding is UTF-8. Thanks.

import java.util.Scanner;

import java.util.Random;

public class Battleship {

/**

* Initializes a game board so that all the entries are Config.WATER_CHAR

(WATER_CHAR is '~')

*

* @param board The game board to initialize.

*/

public static void initBoard(char board[][]) {

// for ( int i = 0; i < board.length; i++)

// for ( int j = 0; j < board[ i ].length; j++)

// board[ i ][ j ] = Config.WATER_CHAR;

}

/**

* Prints the game boards as viewed by the user. This method is used to print the game boards as

* the user is placing their ships and during the game play.

*

* Some notes on the display: - Each column printed will have a width of Config.MAX_COL_WIDTH. -

* Each row is followed by an empty line. - The values in the headers and cells are to be right

* justified.

*

* @param board The board to print.

* @param caption The board caption.

*/

public static void printBoard(char board[][], String caption) {

// FIXME

}

/**

* Determines if a sequence of cells of length len in a game board is clear or not. This is used

* to determine if a ship will fit on a given game board. The x and y coordinates passed in as

* parameters represent the top-left cell of the ship when considering the grid.

*

* @param board The game board to search.

* @param xcoord The x-coordinate of the top-left cell of the ship.

* @param ycoord The y-coordinate of the top-left cell of the ship.

* @param len The length of the ship.

* @param dir true if the ship will be vertical, otherwise horizontal

* @return 1 if the cells to be occupied by the ship are all Config.WATER_CHAR, -1 if the cells

* to be occupied are not Config.WATER_CHAR, and -2 if the ship would go out-of-bounds

* of the board.

*/

public static int checkWater(char board[][], int xcoord, int ycoord, int len, boolean dir) {

// FIXME

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions