feat: condition-locked exits (+ room/dialogue state plumbing)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package thb.jeanluc.adventure.command.impl;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import thb.jeanluc.adventure.game.GameContext;
|
||||
import thb.jeanluc.adventure.io.TestIO;
|
||||
import thb.jeanluc.adventure.model.Condition;
|
||||
import thb.jeanluc.adventure.model.Direction;
|
||||
import thb.jeanluc.adventure.model.ExitLock;
|
||||
import thb.jeanluc.adventure.model.Player;
|
||||
import thb.jeanluc.adventure.model.Room;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class LockedExitTest {
|
||||
@Test
|
||||
void lockedExitBlocksUntilFlagSet() {
|
||||
Room kitchen = new Room("kitchen", "Kitchen", "d");
|
||||
Room cellar = new Room("cellar", "Cellar", "d");
|
||||
kitchen.addExit(Direction.EAST, cellar);
|
||||
kitchen.addExitLock(Direction.EAST, new ExitLock(
|
||||
List.of(new Condition(Condition.Type.FLAG, "power_on")),
|
||||
"The cellar door is sealed."));
|
||||
Player player = new Player(kitchen, 0);
|
||||
TestIO io = new TestIO();
|
||||
GameContext ctx = new GameContext(null, player, io);
|
||||
|
||||
new GoCommand().execute(ctx, List.of("east"));
|
||||
assertThat(player.getCurrentRoom()).isEqualTo(kitchen);
|
||||
assertThat(io.allOutput()).contains("sealed");
|
||||
|
||||
ctx.getState().set("power_on");
|
||||
new GoCommand().execute(ctx, List.of("east"));
|
||||
assertThat(player.getCurrentRoom()).isEqualTo(cellar);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user