public void placeShip(Ship ship) { if (!shipIsPlaceable(ship)) { throw GameException.CreateShipNotPlaceable(); } for (Position position : ship.getShipPositions()) { setShipAtPosition(ship, position); } ships.add(ship); }
public boolean shipIsPlaceable(Ship ship) { for (Position position : ship.getShipPositions()) { if (!positionIsOnBoard(position) || positionIsTakenByShip(position)) { return false; } } for (Position position : ship.getBoarderPositions()) { if (positionIsOnBoard(position) && positionIsTakenByShip(position)) { return false; } } return true; }