aboutsummaryrefslogtreecommitdiff
path: root/go/game/action_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/game/action_test.go')
-rw-r--r--go/game/action_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/go/game/action_test.go b/go/game/action_test.go
index a4cf0752..5fa0b64d 100644
--- a/go/game/action_test.go
+++ b/go/game/action_test.go
@@ -1,6 +1,8 @@
package game
import (
+ "errors"
+ "strings"
"testing"
"muhq.space/muhqs-game/go/utils"
@@ -104,3 +106,45 @@ func TestUnmarshalPickAction(t *testing.T) {
t.Fatalf("expexted archer beeing picked not %s", p.pick.Path())
}
}
+
+func TestAttackAction(t *testing.T) {
+ mapDef := `map: |1-
+ H T
+ SSS
+symbols:
+ T: tower
+ H: house
+ S: street
+`
+ s := NewLocalState()
+ r := strings.NewReader(mapDef)
+ m, _ := readMap(r)
+ s.SetMap(m)
+
+ p := s.AddNewPlayer("player", NewDeck())
+ o := s.AddNewPlayer("opponent", NewDeck())
+
+ t1 := s.addNewUnit(NewCard("base/fighter"), Position{0, 0}, o)
+ t2 := s.addNewUnit(NewCard("base/fighter"), Position{0, 1}, o)
+ a := s.addNewUnit(NewCard("base/archer"), Position{2, 0}, p)
+ ca := s.addNewUnit(NewCard("base/cavalry_archer"), Position{2, 1}, p)
+
+ aa1 := NewAttackAction(a)
+ err := aa1.Target().AddSelection(t1)
+ if !errors.Is(err, ErrTargetRangeProtected) {
+ t.Fatal("protected from range combat not detected")
+ }
+
+ aa2 := NewAttackAction(ca)
+ err = aa2.Target().AddSelection(t2)
+ if err != nil {
+ t.Fatal("unexpected target error:", err)
+ }
+ s.ResolveAction(aa2)
+ if t2.Damage() != 1 {
+ t.Fatal("fighter did not took 1 damage")
+ }
+ if ca.Damage() > 0 {
+ t.Fatal("cavalry archer took damage in range combat from melee unit")
+ }
+}