rendered paste bodyimport java.util.Scanner;
public class BattleshipPlayer {
private String name;
protected BattleshipGrid grid;
private int AChits = 0;
private int Bhits = 0;
private int Chits = 0;
private int Dhits = 0;
private int Shits = 0;
private int shots = 0;
BattleshipPlayer(){
name = null;
}
public void startGame(){
if(name == null){
System.out.println("Enter Your Name: ");
Scanner sc = new Scanner(System.in);
name = sc.nextLine();
}
grid = new BattleshipGrid();
}
public String playerName(){
return name;
}
public Position shoot(){
int rowP = 0;
int column = 1;
Scanner input = new Scanner(System.in);
System.out.println("Please Enter Row: ");
do{
String row = input.nextLine();
if(row == "A" || row == "a")
rowP = 0;
else if(row == "B" || row == "b")
rowP = 1;
else if(row == "C" || row == "c")
rowP = 2;
else if(row == "D" || row == "d")
rowP = 3;
else if(row == "E" || row == "e")
rowP = 4;
else if(row == "F" || row == "f")
rowP = 5;
else if(row == "G" || row == "g")
rowP = 6;
else if(row == "H" || row == "h")
rowP = 7;
else if(row == "I" || row == "i")
rowP = 8;
else if(row == "J" || row == "j")
rowP = 9;
else{
rowP = 10;
System.out.println("Please Enter Valid Row: ");
}
}while(rowP > 9);
do{
System.out.println("Please Enter Column: ");
column = input.nextInt();
if(column > 10)
System.out.println("Please Enter Valid Column: ");
}while(column > 10);
shots++;
return new Position(rowP, column);
}
protected void updateGrid(Position pos, boolean hit, char initial){
grid.shotAt(pos, hit, initial);
}
public void updatePlayer(Position pos, boolean hit, char initial,
String boatName, boolean sunk, boolean gameOver,
boolean tooManyTurns, int turns){
//Method Starts Here;
System.out.println("");
}