diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/GameIO.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/GameIO.java index 9ca91b1..ccbdf88 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/GameIO.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/GameIO.java @@ -44,6 +44,17 @@ public interface GameIO { // no-op } + /** + * One frame of an auto-walk (the {@code go to} command), as the player moves + * through a room en route. Default is a no-op: text mode travels silently. + * The GUI overrides this to repaint the map and pace the animation. + * + * @param view the map snapshot at this step + */ + default void travelStep(MapView view) { + // no animation in text mode + } + /** On-demand map (the 'map' command). Default renders ASCII (Unicode frames). */ default void showMap(MapView view) { print(AsciiMap.render(view, true)); diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/SwingIO.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/SwingIO.java index 8123357..8501488 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/SwingIO.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/SwingIO.java @@ -66,6 +66,9 @@ public class SwingIO implements GameIO { /** Unscaled size for the HUD and side-panel font, in points. */ private static final float SMALL_SIZE = 12.5f; + /** Delay between rooms while animating a go-to auto-walk, in milliseconds. */ + private static final long TRAVEL_STEP_MS = 300L; + /** Side-panel width as a fraction of the window width, clamped by the bounds below. */ private static final double SIDE_RATIO = 0.28; private static final int SIDE_MIN = 180; @@ -335,6 +338,16 @@ public class SwingIO implements GameIO { map.show(view); } + @Override + public void travelStep(MapView view) { + setMap(view); + try { + Thread.sleep(TRAVEL_STEP_MS); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + @Override public void setQuests(QuestView view) { quests.show(view); diff --git a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/io/TravelStepDefaultTest.java b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/io/TravelStepDefaultTest.java new file mode 100644 index 0000000..e3cb414 --- /dev/null +++ b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/io/TravelStepDefaultTest.java @@ -0,0 +1,19 @@ +package thb.jeanluc.adventure.io; + +import org.junit.jupiter.api.Test; +import thb.jeanluc.adventure.io.text.MapView; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class TravelStepDefaultTest { + + @Test + void defaultTravelStepIsSilentNoOp() { + TestIO io = new TestIO(); + // An empty map view is fine; the default must not print or throw. + io.travelStep(new MapView(List.of(), List.of())); + assertThat(io.outputs()).isEmpty(); + } +}