From af221ad69310359bf53ff72886b8de9d832da271 Mon Sep 17 00:00:00 2001 From: Cedric Beck Date: Wed, 2 Oct 2024 20:48:16 +0200 Subject: [PATCH] Added documentation to ServerGameLogic.checkMap --- .../battleship/game/server/ServerGameLogic.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Projekte/battleship/model/src/main/java/pp/battleship/game/server/ServerGameLogic.java b/Projekte/battleship/model/src/main/java/pp/battleship/game/server/ServerGameLogic.java index 06e6f724..dd8f578d 100644 --- a/Projekte/battleship/model/src/main/java/pp/battleship/game/server/ServerGameLogic.java +++ b/Projekte/battleship/model/src/main/java/pp/battleship/game/server/ServerGameLogic.java @@ -153,14 +153,25 @@ public void received(MapMessage msg, int from) { } } + /** + * Validates the placement of battleships on the map. + * + * Ensures that: + * + * + * @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 ships){ - //Anzahl int numShips = config.getShipNums().values().stream().mapToInt(Integer::intValue).sum(); if (numShips != ships.size()) return false; List occupied = new ArrayList<>(); - //Every Ship Position Is in Map Height/Width - //Überlappen + for (Battleship battleship: ships){ int x = battleship.getX(); int y = battleship.getY();