diff options
| author | historia <[not public]> | 2026-07-06 23:05:04 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-07-06 23:05:04 -0400 |
| commit | 9292634f2f8d71a53879ff07e1330c671b207d51 (patch) | |
| tree | dcffadf7f697e8ad0705d787d8f599bdeeedb812 /internal/game/exit_discovery_test.go | |
| parent | 911aae15f4e869c93239ef7c630c61e1d9d4ef3f (diff) | |
| download | thehouseoficarus-9292634f2f8d71a53879ff07e1330c671b207d51.tar.gz | |
feat: split the concept of hidden and impassable exits. add player_flag for discovered hidden exits.
Diffstat (limited to 'internal/game/exit_discovery_test.go')
| -rw-r--r-- | internal/game/exit_discovery_test.go | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/internal/game/exit_discovery_test.go b/internal/game/exit_discovery_test.go new file mode 100644 index 0000000..58177de --- /dev/null +++ b/internal/game/exit_discovery_test.go @@ -0,0 +1,81 @@ +package game + +import ( + "testing" + + "thehouseoficarus/internal/player" + "thehouseoficarus/internal/world" +) + +func TestDiscoveredExitFlagKey(t *testing.T) { + key := discoveredExitFlag(2001, world.North) + if key != "hidden_exit_2001_north" { + t.Errorf("unexpected flag key: %q", key) + } + key = discoveredExitFlag(100, world.Down) + if key != "hidden_exit_100_down" { + t.Errorf("unexpected flag key: %q", key) + } +} + +func TestExitDiscoveredUndiscovered(t *testing.T) { + p := &player.Player{} + if g := (&Game{}).exitDiscovered(p, 42, world.East); g { + t.Error("expected undiscovered to be false") + } +} + +func TestExitDiscoveredAfterMark(t *testing.T) { + g := &Game{Flags: NewFlagStore()} + p := &player.Player{} + roomID := 42 + dir := world.East + flagKey := discoveredExitFlag(roomID, dir) + + if g.exitDiscovered(p, roomID, dir) { + t.Error("should not be discovered before marking") + } + g.markExitDiscovered(p, roomID, dir) + if !g.exitDiscovered(p, roomID, dir) { + t.Error("should be discovered after marking") + } + if getPlayerFlagInt(p, flagKey) == 0 { + t.Error("flag should be set after marking") + } +} + +func TestExitDiscoveredGodMode(t *testing.T) { + p := &player.Player{GodMode: true} + if !(&Game{}).exitDiscovered(p, 99, world.South) { + t.Error("god mode should always see exits as discovered") + } +} + +func TestExitHiddenFiltered(t *testing.T) { + g := &Game{Flags: NewFlagStore()} + p := &player.Player{} + + if !g.exitHiddenFiltered(p, 1, world.North, false) { + t.Error("non-hidden exit should pass filter") + } + if g.exitHiddenFiltered(p, 1, world.North, true) { + t.Error("hidden undiscovered exit should be filtered") + } + g.markExitDiscovered(p, 1, world.North) + if !g.exitHiddenFiltered(p, 1, world.North, true) { + t.Error("hidden discovered exit should pass filter") + } +} + +func TestExitDiscoveredDifferentRoom(t *testing.T) { + g := &Game{Flags: NewFlagStore()} + p := &player.Player{} + + g.markExitDiscovered(p, 10, world.North) + if g.exitDiscovered(p, 10, world.East) { + t.Error("discovering north should not mark east as discovered") + } + if g.exitDiscovered(p, 20, world.North) { + t.Error("discovering room 10 north should not mark room 20 north") + } +} |
