fix(command): combined unknown-target message; cover both go-to summary forms
- UX: unknown-target message now reads "don't know any direction or place called '...'" so direction typos (e.g. 'go nroth') make sense - clarity: resolveVisited uses equalsIgnoreCase for id/name matching; add null-world guard comment pointing to CommandTestSupport - Javadoc: note that 'to' filler word is stripped, making go-to forms equivalent - tests: assert 'through the Hallway' in 3-node route; update unknown message assertion; add adjacentWalkUsesShortSummary covering the n==2 short-form path Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,7 +18,8 @@ import java.util.Optional;
|
||||
* Moves the player. {@code go <direction>} steps once to a connected room.
|
||||
* {@code go to <room>} auto-walks the shortest path (BFS) over already-visited
|
||||
* rooms, honouring locked exits and darkness. Usage: {@code go <direction>} or
|
||||
* {@code go to <room>}.
|
||||
* {@code go to <room>}. 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user