From 1b39eac90ef6b7d62096b05072ed37e0308cffd0 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Tue, 14 Jul 2026 12:39:15 +0200 Subject: [PATCH] refactor: move MapLayout into the game package The 'map' package held a single class, which breaks the project's own rule in docs/conventions.md: a subpackage only pays for itself once a class family reaches three classes and forms its own abstraction. MapLayout is BFS grid-layout logic and belongs next to Pathfinder in 'game'. --- .../adventure/command/impl/GoCommand.java | 2 +- .../adventure/command/impl/MapCommand.java | 2 +- .../adventure/{map => game}/MapLayout.java | 19 ++++++++++++++++++- .../{map => game}/MapLayoutTest.java | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) rename Semesterprojekt/src/main/java/thb/jeanluc/adventure/{map => game}/MapLayout.java (86%) rename Semesterprojekt/src/test/java/thb/jeanluc/adventure/{map => game}/MapLayoutTest.java (98%) diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/GoCommand.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/GoCommand.java index ecea4df..234303c 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/GoCommand.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/GoCommand.java @@ -3,9 +3,9 @@ package thb.jeanluc.adventure.command.impl; import thb.jeanluc.adventure.command.Command; import thb.jeanluc.adventure.game.Conditions; import thb.jeanluc.adventure.game.GameContext; +import thb.jeanluc.adventure.game.MapLayout; import thb.jeanluc.adventure.game.Light; import thb.jeanluc.adventure.game.Pathfinder; -import thb.jeanluc.adventure.map.MapLayout; import thb.jeanluc.adventure.model.Direction; import thb.jeanluc.adventure.model.ExitLock; import thb.jeanluc.adventure.model.Room; diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/MapCommand.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/MapCommand.java index d73be6a..805e47b 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/MapCommand.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/MapCommand.java @@ -2,8 +2,8 @@ package thb.jeanluc.adventure.command.impl; import thb.jeanluc.adventure.command.Command; import thb.jeanluc.adventure.game.GameContext; +import thb.jeanluc.adventure.game.MapLayout; import thb.jeanluc.adventure.io.text.MapView; -import thb.jeanluc.adventure.map.MapLayout; import java.util.List; diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/map/MapLayout.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/game/MapLayout.java similarity index 86% rename from Semesterprojekt/src/main/java/thb/jeanluc/adventure/map/MapLayout.java rename to Semesterprojekt/src/main/java/thb/jeanluc/adventure/game/MapLayout.java index 454b6b0..8b21930 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/map/MapLayout.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/game/MapLayout.java @@ -1,4 +1,4 @@ -package thb.jeanluc.adventure.map; +package thb.jeanluc.adventure.game; import lombok.extern.slf4j.Slf4j; import thb.jeanluc.adventure.io.text.CellState; @@ -30,6 +30,16 @@ public final class MapLayout { private MapLayout() { } + /** + * Builds the map view for the current fog-of-war state. Visited rooms are + * shown by name, their unentered neighbours as unknown cells; rooms beyond + * those are omitted. + * + * @param world the loaded world + * @param visited ids of the rooms the player has entered + * @param current the room the player stands in + * @return the map view; empty if nothing has been visited yet + */ public static MapView compute(World world, Set visited, Room current) { if (visited.isEmpty()) { return new MapView(List.of(), List.of()); @@ -101,6 +111,12 @@ public final class MapLayout { return new MapView(List.copyOf(cells.values()), connections); } + /** + * Assigns grid coordinates to every room reachable from the anchor, which + * sits at the origin. A room reached twice at conflicting coordinates keeps + * its first placement; the world geometry is then not planar and the + * collision is logged. + */ private static Map bfs(Room anchor) { Map coords = new HashMap<>(); Deque queue = new ArrayDeque<>(); @@ -126,6 +142,7 @@ public final class MapLayout { return coords; } + /** Grid step for a direction as {@code {dx, dy}}; y grows southwards. */ private static int[] delta(Direction d) { return switch (d) { case NORTH -> new int[]{0, -1}; diff --git a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/map/MapLayoutTest.java b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/game/MapLayoutTest.java similarity index 98% rename from Semesterprojekt/src/test/java/thb/jeanluc/adventure/map/MapLayoutTest.java rename to Semesterprojekt/src/test/java/thb/jeanluc/adventure/game/MapLayoutTest.java index a13489f..617593e 100644 --- a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/map/MapLayoutTest.java +++ b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/game/MapLayoutTest.java @@ -1,4 +1,4 @@ -package thb.jeanluc.adventure.map; +package thb.jeanluc.adventure.game; import org.junit.jupiter.api.Test; import thb.jeanluc.adventure.io.text.CellState;