Course Solutions Uncategorized (Solved) : Player Class Battleship Program Ignore Adding Ships Already Five Ships Public Class Player Q34271538 . . . .

(Solved) : Player Class Battleship Program Ignore Adding Ships Already Five Ships Public Class Player Q34271538 . . . .

 

This is Player class for my battleship program. How should IIgnore adding more ships if there are already five ships?

public class Player
{
private static final int[] SHIP_LENGTHS = {2, 3, 3, 4, 5};
private Ship[] ships;
private Grid own = new Grid();
private Grid opp = new Grid();
public Player() {
ships = new Ship[SHIP_LENGTHS.length];
for (int i = 0; i < SHIP_LENGTHS.length; i++){
ships[i] = new Ship(SHIP_LENGTHS[i]);
  
}
}
public void printMyShips() {
own.printShips();
}
public void printOpponentGuesses() {
opp.printStatus();
}
public void printMyGuesses() {
own.printStatus();
}
public void chooseShipLocation(Ship s, int row, int col, intdirection) {
s.setLocation(row, col);
s.setDirection(direction);
own.addShip(s);
}
public void recordOpponentGuess(int row, int col) {
if (own.hasShip(row, col)) {
opp.markHit(row, col);
}
else opp.markMiss(row, col);
}
  
  
}

// The ship class.

public class Ship
{
public static final int UNSET=-1;
public

OR

PayPal Gateway not configured

OR

PayPal Gateway not configured

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post