aboutsummaryrefslogtreecommitdiff
path: root/go/game/unit_test.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-04 14:37:15 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2023-02-04 14:40:01 +0100
commit9b262342f5d6b9fcfdf15d9bea2ce062dc388a89 (patch)
treeb384d499be14c34f5a7e8320d8963149a2a759b6 /go/game/unit_test.go
parent94425ed14a8c280351b61473e3d79276dfdfa657 (diff)
downloadmuhqs-game-9b262342f5d6b9fcfdf15d9bea2ce062dc388a89.tar.gz
muhqs-game-9b262342f5d6b9fcfdf15d9bea2ce062dc388a89.zip
support crewing
* Introduce new callback for leaving a pile without beeing dropped * Fix equipment contrsuctor * Implement attack inheritance
Diffstat (limited to 'go/game/unit_test.go')
-rw-r--r--go/game/unit_test.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/go/game/unit_test.go b/go/game/unit_test.go
new file mode 100644
index 00000000..341fb350
--- /dev/null
+++ b/go/game/unit_test.go
@@ -0,0 +1,60 @@
+package game
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestCrew(t *testing.T) {
+ mapDef := `map: |1-
+ HST
+ HSF
+ TSW
+symbols:
+ T: tower
+ H: house
+ F: farm
+ S: street
+ W: deep water
+`
+ s := NewState()
+ r := strings.NewReader(mapDef)
+ s.Map, _ = readMap(r)
+ f := NewUnit(NewCard("nautics/fisher"), s.Map.TileAt(Position{2, 2}), nil)
+ a := NewUnit(NewCard("base/archer"), s.Map.TileAt(Position{1, 1}), nil)
+ sword := newEquipment(NewCard("base/sword"), s.Map.TileAt(Position{0, 1}), nil)
+
+ a.move(s, f.Tile())
+ if len(f.Pile()) != 1 {
+ t.Fatalf("fisher's pile size is not 1")
+ }
+
+ if f.Pile()[0] != a {
+ t.Fatalf("fisher's pile does not contain the archer")
+ }
+
+ if a.Tile() != nil {
+ t.Fatalf("piled archer has still a tile %v", a.Tile())
+ }
+
+ for r, d := range f.Attack.attacks {
+ if d != a.Attack.attacks[r] {
+ t.Fatalf("fisher's attack %d is not equal to the archer's attack %d at range %d",
+ d, a.Attack.attacks[r], r)
+ }
+ }
+
+ a.move(s, s.Map.TileAt(Position{1, 1}))
+ if len(f.Pile()) != 0 {
+ t.Fatalf("fisher's pile is not empty")
+ }
+
+ if !INVALID_ATTACK(f.Attack) {
+ t.Fatalf("fisher has still a valid atack")
+ }
+
+ AddPermanentToPile(a, sword)
+ if a.Attack.attacks[0] != 2 {
+ t.Fatalf("archer's mele attack is not 2")
+ }
+}