aboutsummaryrefslogtreecommitdiff
path: root/internal/game/exit_discovery_test.go
blob: 58177dee32ee72a36e2c7e5605d8e91bb7b039d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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")
	}
}