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) <noreply@anthropic.com>
This commit is contained in:
2026-05-31 21:02:48 +02:00
parent fcf8083b7c
commit a0560a6ec5
2 changed files with 18 additions and 3 deletions

View File

@@ -6,6 +6,8 @@ import thb.jeanluc.adventure.command.CommandParser;
import thb.jeanluc.adventure.command.CommandRegistry; import thb.jeanluc.adventure.command.CommandRegistry;
import thb.jeanluc.adventure.command.ParsedCommand; import thb.jeanluc.adventure.command.ParsedCommand;
import thb.jeanluc.adventure.io.text.Hud; import thb.jeanluc.adventure.io.text.Hud;
import thb.jeanluc.adventure.io.text.MapView;
import thb.jeanluc.adventure.map.MapLayout;
import java.util.Optional; import java.util.Optional;
@@ -63,6 +65,11 @@ public class Game {
ctx.getPlayer().getGold(), ctx.getPlayer().getGold(),
turn, turn,
false)); false));
MapView map = MapLayout.compute(
ctx.getWorld(),
ctx.getPlayer().getVisitedRoomIds(),
ctx.getPlayer().getCurrentRoom());
ctx.getIo().setMap(map);
} }
/** /**

View File

@@ -10,6 +10,10 @@ import thb.jeanluc.adventure.io.TestIO;
import thb.jeanluc.adventure.model.Direction; import thb.jeanluc.adventure.model.Direction;
import thb.jeanluc.adventure.model.Player; import thb.jeanluc.adventure.model.Player;
import thb.jeanluc.adventure.model.Room; 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; import static org.assertj.core.api.Assertions.assertThat;
@@ -24,7 +28,10 @@ class GameTest {
TestIO io = new TestIO() TestIO io = new TestIO()
.enqueue("go north") .enqueue("go north")
.enqueue("quit"); .enqueue("quit");
GameContext ctx = new GameContext(null, player, io); Map<String, Room> 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(); CommandRegistry registry = new CommandRegistry();
registry.register(new GoCommand(), "go"); registry.register(new GoCommand(), "go");
@@ -42,9 +49,10 @@ class GameTest {
@Test @Test
void run_unknownVerb_writesHint() { 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"); 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(); CommandRegistry registry = new CommandRegistry();
QuitCommand quit = new QuitCommand(); QuitCommand quit = new QuitCommand();