public void shuffle(List<WaterCraft> ships) { this.ships.addAll(ships); Random random = new Random(); int value, index; for (int i = (ships.size() - 1); i >= 0; i = (ships.size() - 1)) { WaterCraft ship = ships.get(i); value = random.nextInt(length); if (ship.getOrientation() == 0 && (index = verifyPositionHorizontal(value, ship.getAmountOfSquares())) != -1) { for (int j = index; j < length && j < (index + ship.getAmountOfSquares()); j++) { board[value][j] = ship; ship.addImage(value, j); } ships.remove(i); } else if (ship.getOrientation() == 1 && (index = verifyPositionVertical(value, ship.getAmountOfSquares())) != -1) { for (int row = index; row < length && row < (index + ship.getAmountOfSquares()); row++) { board[row][value] = ship; ship.addImage(row, value); } ships.remove(i); } } }
public int getWon() { for (WaterCraft s : ships) { if (s.getStatus() != 1) return 0; } return 1; }