This is a portion of my code for a Battleship game. The looping doesn't stop when I sink all of my ships. I take the input for the shoot array from player and the compshoot array from the random function.
do {
System.out.println();
showBoard(board);
shoot(shoot);
System.out.println();
if (board[shoot[0]][shoot[1]]==1 || board[shoot[0]][shoot[1]]==2) {
if (board[shoot[0]][shoot[1]]==1){
System.out.println("Oh no, you sunk your own ship :( ");
myShip--;
board[shoot[0]][shoot[1]]=3;
}
else if (board[shoot[0]][shoot[1]]==2) {
System.out.println("Boom! You sunk a ship!");
compShip--;
board[shoot[0]][shoot[1]]=4;
}
}
else if (board[shoot[0]][shoot[1]]==0) {
System.out.println("Sorry, you missed");
board[shoot[0]][shoot[1]] = 5;
}
compShoot(compShoot, shoot);
System.out.println();
System.out.println("Computers turn : ");
System.out.println();
if (board[compShoot[0]][compShoot[1]]==1 || board[compShoot[0]]
[compShoot[1]]==2) {
if (board[compShoot[0]][compShoot[1]]==1){
System.out.println("The Computer sunk one of your ships!");
myShip--;
board[compShoot[0]][compShoot[1]]=3;
}
else if (board[compShoot[0]][compShoot[1]]==2) {
System.out.println("The Computer sunk one of its own
ships");
compShip--;
board[compShoot[0]][compShoot[1]]=4;
}
}
else if (board[compShoot[0]][compShoot[1]]==0) {
System.out.println("Computer missed");
board[compShoot[0]][compShoot[1]] = 5;
}
System.out.println();
System.out.println("Your ships : " + myShip + " | Computer ships : "
+ compShip);
}while (myShip != 0 || compShip != 0);