Added documentation to ServerGameLogic.checkMap

This commit is contained in:
Cedric Beck
2024-10-02 20:48:16 +02:00
parent ae61e8061c
commit af221ad693

View File

@@ -153,14 +153,25 @@ public void received(MapMessage msg, int from) {
}
}
/**
* Validates the placement of battleships on the map.
*
* Ensures that:
* <ul>
* <li>The number of ships matches the configuration.</li>
* <li>Ships are within the map's boundaries.</li>
* <li>Ships do not overlap.</li>
* </ul>
*
* @param ships the list of {@link Battleship} objects to validate
* @return {@code true} if all ships are placed correctly; {@code false} otherwise
*/
private boolean checkMap(List<Battleship> ships){
//Anzahl
int numShips = config.getShipNums().values().stream().mapToInt(Integer::intValue).sum();
if (numShips != ships.size()) return false;
List<IntPoint> occupied = new ArrayList<>();
//Every Ship Position Is in Map Height/Width
//Überlappen
for (Battleship battleship: ships){
int x = battleship.getX();
int y = battleship.getY();