feat(app): main-menu shell loop wiring; gitignore saves/

Replace App.run with a main-menu shell (New Game / Load / Settings /
Quit) above the game loop, wire SaveCommand + MenuCommand into the
registry with an autosave callback, and remove the now-unused
QuitCommand. Migrate GameTest from QuitCommand to MenuCommand.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-01 15:17:46 +02:00
parent 9632d27b25
commit 1f15bfe330
4 changed files with 84 additions and 70 deletions

View File

@@ -1,17 +1,20 @@
package thb.jeanluc.adventure.game;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import thb.jeanluc.adventure.command.CommandParser;
import thb.jeanluc.adventure.command.CommandRegistry;
import thb.jeanluc.adventure.command.impl.GoCommand;
import thb.jeanluc.adventure.command.impl.LookCommand;
import thb.jeanluc.adventure.command.impl.QuitCommand;
import thb.jeanluc.adventure.command.impl.MenuCommand;
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 thb.jeanluc.adventure.save.SaveService;
import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -19,6 +22,9 @@ import static org.assertj.core.api.Assertions.assertThat;
class GameTest {
@TempDir
Path savesDir;
@Test
void run_dispatchesCommands_andQuitsCleanly() {
Room kitchen = new Room("kitchen", "Kitchen", "kd");
@@ -36,7 +42,7 @@ class GameTest {
CommandRegistry registry = new CommandRegistry();
registry.register(new GoCommand(), "go");
registry.register(new LookCommand(), "look");
QuitCommand quit = new QuitCommand();
MenuCommand quit = new MenuCommand(new SaveService(savesDir));
registry.register(quit, "quit");
Game game = new Game(ctx, registry, new CommandParser());
@@ -44,7 +50,7 @@ class GameTest {
game.run();
assertThat(player.getCurrentRoom()).isEqualTo(hallway);
assertThat(io.allOutput()).contains("Goodbye");
assertThat(io.allOutput()).contains("Returning to the main menu");
}
@Test
@@ -55,7 +61,7 @@ class GameTest {
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();
MenuCommand quit = new MenuCommand(new SaveService(savesDir));
registry.register(quit, "quit");
Game game = new Game(ctx, registry, new CommandParser());
quit.bind(game);