diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/GoCommand.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/GoCommand.java index d5b589b..ecea4df 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/GoCommand.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/GoCommand.java @@ -18,7 +18,8 @@ import java.util.Optional; * Moves the player. {@code go } steps once to a connected room. * {@code go to } auto-walks the shortest path (BFS) over already-visited * rooms, honouring locked exits and darkness. Usage: {@code go } or - * {@code go to }. + * {@code go to }. The parser strips the filler word "to", so "go to + * <room>" and "go <room>" are equivalent. */ public class GoCommand implements Command { @@ -63,7 +64,7 @@ public class GoCommand implements Command { String name = String.join(" ", args).toLowerCase(); Room target = resolveVisited(ctx, name); if (target == null) { - ctx.getIo().write("You don't know any place called '" + name + "'."); + ctx.getIo().write("You don't know any direction or place called '" + name + "'."); return; } Room start = ctx.getPlayer().getCurrentRoom(); @@ -90,6 +91,7 @@ public class GoCommand implements Command { /** Finds a visited room whose id or display name matches {@code name}. */ private Room resolveVisited(GameContext ctx, String name) { + // the command test harness (CommandTestSupport) uses a null world; production always has one if (ctx.getWorld() == null) { return null; } @@ -98,7 +100,7 @@ public class GoCommand implements Command { if (r == null) { continue; } - if (id.equals(name) || r.getName().toLowerCase().equals(name)) { + if (id.equalsIgnoreCase(name) || r.getName().equalsIgnoreCase(name)) { return r; } } diff --git a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/command/impl/GoCommandPathTest.java b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/command/impl/GoCommandPathTest.java index 3fafb60..b980b49 100644 --- a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/command/impl/GoCommandPathTest.java +++ b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/command/impl/GoCommandPathTest.java @@ -51,6 +51,7 @@ class GoCommandPathTest { new GoCommand().execute(ctx, List.of("library")); assertThat(ctx.getPlayer().getCurrentRoom().getId()).isEqualTo("library"); assertThat(out(ctx)).contains("make your way"); + assertThat(out(ctx)).contains("through the Hallway"); } @Test @@ -66,7 +67,7 @@ class GoCommandPathTest { GameContext ctx = world(false, "Library"); new GoCommand().execute(ctx, List.of("dungeon")); assertThat(ctx.getPlayer().getCurrentRoom().getId()).isEqualTo("kitchen"); - assertThat(out(ctx)).contains("don't know any place called 'dungeon'"); + assertThat(out(ctx)).contains("don't know any direction or place called 'dungeon'"); } @Test @@ -90,4 +91,13 @@ class GoCommandPathTest { new GoCommand().execute(ctx, List.of("north")); assertThat(ctx.getPlayer().getCurrentRoom().getId()).isEqualTo("hallway"); } + + @Test + void adjacentWalkUsesShortSummary() { + GameContext ctx = world(false, "Library"); + new GoCommand().execute(ctx, List.of("hallway")); + assertThat(ctx.getPlayer().getCurrentRoom().getId()).isEqualTo("hallway"); + assertThat(out(ctx)).contains("make your way from the Kitchen to the Hallway"); + assertThat(out(ctx)).doesNotContain("through"); + } }