semesterprojekt: implement full text adventure (phases 1-7)

Walking skeleton through Swing GUI: YAML-driven world (4 rooms,
4 items, 1 NPC), HashMap command dispatch with parser, three-tier
item hierarchy (readable / switchable / plain), and end-to-end
NPC give/receive flow. 67 tests green.
This commit is contained in:
2026-05-25 21:37:59 +02:00
parent 9b6528d800
commit 83643a192f
85 changed files with 4453 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
package thb.jeanluc.adventure.game;
import org.junit.jupiter.api.Test;
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.io.TestIO;
import thb.jeanluc.adventure.model.Direction;
import thb.jeanluc.adventure.model.Player;
import thb.jeanluc.adventure.model.Room;
import static org.assertj.core.api.Assertions.assertThat;
class GameTest {
@Test
void run_dispatchesCommands_andQuitsCleanly() {
Room kitchen = new Room("kitchen", "Kitchen", "kd");
Room hallway = new Room("hallway", "Hallway", "hd");
kitchen.addExit(Direction.NORTH, hallway);
Player player = new Player(kitchen, 0);
TestIO io = new TestIO()
.enqueue("go north")
.enqueue("quit");
GameContext ctx = new GameContext(null, player, io);
CommandRegistry registry = new CommandRegistry();
registry.register(new GoCommand(), "go");
registry.register(new LookCommand(), "look");
QuitCommand quit = new QuitCommand();
registry.register(quit, "quit");
Game game = new Game(ctx, registry, new CommandParser());
quit.bind(game);
game.run();
assertThat(player.getCurrentRoom()).isEqualTo(hallway);
assertThat(io.allOutput()).contains("Goodbye");
}
@Test
void run_unknownVerb_writesHint() {
Player player = new Player(new Room("r", "R", "d"), 0);
TestIO io = new TestIO().enqueue("dance").enqueue("quit");
GameContext ctx = new GameContext(null, player, io);
CommandRegistry registry = new CommandRegistry();
QuitCommand quit = new QuitCommand();
registry.register(quit, "quit");
Game game = new Game(ctx, registry, new CommandParser());
quit.bind(game);
game.run();
assertThat(io.allOutput()).contains("don't understand 'dance'");
}
}