From a0560a6ec58fe9945c10522805f8f4da1c8cf8ee Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Sun, 31 May 2026 21:02:48 +0200 Subject: [PATCH] feat(game): push map to the IO each turn (GUI live update) Game now derives the MapView from the world each turn; GameTest gains a real World (the per-turn map push needs it). Co-Authored-By: Claude Opus 4.8 (1M context) --- .../main/java/thb/jeanluc/adventure/game/Game.java | 7 +++++++ .../java/thb/jeanluc/adventure/game/GameTest.java | 14 +++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/game/Game.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/game/Game.java index fa5c3bf..24210e3 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/game/Game.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/game/Game.java @@ -6,6 +6,8 @@ import thb.jeanluc.adventure.command.CommandParser; import thb.jeanluc.adventure.command.CommandRegistry; import thb.jeanluc.adventure.command.ParsedCommand; import thb.jeanluc.adventure.io.text.Hud; +import thb.jeanluc.adventure.io.text.MapView; +import thb.jeanluc.adventure.map.MapLayout; import java.util.Optional; @@ -63,6 +65,11 @@ public class Game { ctx.getPlayer().getGold(), turn, false)); + MapView map = MapLayout.compute( + ctx.getWorld(), + ctx.getPlayer().getVisitedRoomIds(), + ctx.getPlayer().getCurrentRoom()); + ctx.getIo().setMap(map); } /** diff --git a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/game/GameTest.java b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/game/GameTest.java index 2cd53a5..4b85ced 100644 --- a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/game/GameTest.java +++ b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/game/GameTest.java @@ -10,6 +10,10 @@ import thb.jeanluc.adventure.io.TestIO; import thb.jeanluc.adventure.model.Direction; import thb.jeanluc.adventure.model.Player; import thb.jeanluc.adventure.model.Room; +import thb.jeanluc.adventure.model.World; + +import java.util.LinkedHashMap; +import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; @@ -24,7 +28,10 @@ class GameTest { TestIO io = new TestIO() .enqueue("go north") .enqueue("quit"); - GameContext ctx = new GameContext(null, player, io); + Map rooms = new LinkedHashMap<>(); + rooms.put("kitchen", kitchen); + rooms.put("hallway", hallway); + GameContext ctx = new GameContext(new World(rooms, Map.of(), Map.of(), "t", "w"), player, io); CommandRegistry registry = new CommandRegistry(); registry.register(new GoCommand(), "go"); @@ -42,9 +49,10 @@ class GameTest { @Test void run_unknownVerb_writesHint() { - Player player = new Player(new Room("r", "R", "d"), 0); + Room r = new Room("r", "R", "d"); + Player player = new Player(r, 0); TestIO io = new TestIO().enqueue("dance").enqueue("quit"); - GameContext ctx = new GameContext(null, player, io); + GameContext ctx = new GameContext(new World(Map.of("r", r), Map.of(), Map.of(), "t", "w"), player, io); CommandRegistry registry = new CommandRegistry(); QuitCommand quit = new QuitCommand();