/** * Represents the board . **/ public class Board { // DATA MEMBERS // The game board represents a rectangular array of cells. // Each cell is in one of several possible states. // The following constants represent these states. public static final int NOT_SHOT_AT = 0; public static final int MISSED = 1; public static final int SAME_TARGET = 2; public static final int SHIP_HIT = 3; public static final int SHIP_SUNK = 4; // The following data members represent the board dimensions (size). int sizex, sizey; // The cells are represented as a two-dimensional array of Cell objects. private Cell [][] cells; // The ships present on the board are represented as an object that // stores a collection (list) of ship objects. private ShipList ships; // METHODS /** * This constructor for the Board object should initialize the board, * setting its x and y dimensions to the given values and initializing * the cells and shiplist to their initial states. This method should * use the clearBoard method (specified next, below) to initialize the * cells and ships. * * @param x the x-coordinate. * @param y the y-coordinate. **/ public Board(int x, int y) { // your implementation } /** * This method intializes the cell array and ship list references. When * this method completes, the board should be a in state that is ready * for play to begin. **/ public void clearBoard() { // your implementation } /** * Given a reference to a ship in the ship list, this method returns * the integer index of the given ship in the list. * * @param ship theinstance to be searched. * @return the index. **/ public int getShipNumber (Ship ship) { // your implementation } /** * Given an integer index to a ship in the ship list, this method * returns the ship at the requested index. * * @param index the index requested. * @return the Ship instance **/ public Ship getShip (int index) { // your implementation } /** * Given the x and y coordinates of a cell in the board, this method * returns a reference to the cell at that position (x,y). Indexing is * zero-based. That is, the first cell is at index (0,0) * * @param x the x-coordinate. * @param y the y-coordinate. * @return the Cell object. **/ public Cell getCellAt (int x, int y) { // your implementation } /** * This method takes a ShipList object as a parameter. For each ship in * the list, this method uses the placeShip method (below) to place the * ship on the board. * * @param ships the list of ships. **/ public void placeShips (ShipList ships) { // your implementation } /** * This method returns true if all ships on the board have been sunk, * and it returns false otherwise. This method uses the allShipsSunk * method of the ShipList class to compute the required result. * * @return true if all the ships are sunk, false otherwise. **/ public boolean allShipsSunk() { // your implementation } /** * This method returns true if the board configuration is valid, and * it returns false otherwise. A board is considered valid if and only * if there are no two ships occupying the same cell on the board. This * method uses the getShipCount, getShip, and hasPoint methods of the Ship * and ShipList classes. */ public boolean isValidBoard () { // your implementation } /** * This method resets the board to a new state containing the number of * ships given by the numberOfShips parameter. The method should work by * clearing the board, randomly placing the given number of ships (using * the placeship method, and then testing the board to see if it's in a * valid state. If the board is valid, the method terminates, otherwise it * tries again and keeps trying (in a do/while loop) until a valid board * is obtained. * * @param numberOfShips number of Ships. **/ public void generateRandomBoard(int numberOfShips) { // your implementation } /** * This method places the given ship (aShip) on the board by marking each * cell that the ship occupies (with a call to setShipOnCell) and then by * adding the ship to the shipList. The cells to be marked start with x * and y coordinates of the given ship and include the additional cells * determined by the ship length its orientation (which are obtained by * use of the appropriate methods of the Ship class). * * @param aShip the instance of ship to be placed **/ public void placeShip(Ship aShip) { // your implementation } /** * This method processes a shot fired at cell x,y. It returns the status * of the targeted cell in the form of one of the status constant values * defined above. If the targeted cell has already been hit, then this * method simply returns SAME_TARGET. If the cell has not previously been * hit then the following steps are taken. First the cell is marked as hit * using the setIsHit method of the Cell class. Second, if there is not a * ship on the targeted cell, then the method returns the status MISSED. * Otherwise the ship occupying the targeted cell is marked as hit (by a * call to the ship's hit method); then if the targeted ship is sunk (to * be determined by a call to the ship's isSunk method) then this method * returns SHIP_SUNK status, otherwise it returns SHIP_HIT status. * * @param x the x coordinate of the target. * @param y the y coordinate of the target. **/ public int processShot(int x, int y) { // your implementation } /** * Prints the ship list by calling the print method of the ship list. */ public void printShipList() { // your implementation } }