@Override protected boolean mouseClicked(int x, int y) { if (winner < 0) { IBattleship battleship = battleships[0]; Boolean hit = battleship.fire(x, y); update(battleship, hit, x, y); runDelayed( 1500, () -> { updateCells(); enemyFire(); }); } return true; }
private void update(IBattleship battleship, Boolean hit, int x, int y) { updateCell(x, y); int notHitShipCount = battleship.countShips(null, false); if (notHitShipCount == 0) { winner = player; updateState("GAME OVER! Player " + (winner + 1) + " won."); } else { String status; if (hit == null) { status = "Player " + (player + 1) + " missed!"; } else { status = "Player " + (player + 1) + (hit ? " sunk your ship!" : " hit!"); } player = (player + 1) % 2; updateState(status + " Player " + (player + 1) + randomResponse()); } }