aboutsummaryrefslogtreecommitdiff
path: root/go/game/attack.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/game/attack.go')
-rw-r--r--go/game/attack.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/go/game/attack.go b/go/game/attack.go
index 3896e142..9be465f2 100644
--- a/go/game/attack.go
+++ b/go/game/attack.go
@@ -7,18 +7,23 @@ import (
"strings"
)
+// Attack contains all damage values for each attackable range.
+// The damage value for range 1 is stored at index 0, the value for range 2 at index 1 and so on.
type Attack struct {
attacks []int
}
+// INVALID_ATTACK reports if there are no attackable ranges.
func INVALID_ATTACK(a Attack) bool {
return len(a.attacks) == 0
}
+// MaxRange returns the biggest attackable range.
func (a Attack) MaxRange() int {
return len(a.attacks)
}
+// DamageInRange returns the damage in a certain range.
func (a Attack) DamageInRange(r int) int {
if r > a.MaxRange() {
return 0
@@ -40,7 +45,7 @@ func (a Attack) String() string {
return fmt.Sprintf("%d range %d", a.DamageInRange(r), r)
}
-func parseAttack(attack interface{}) Attack {
+func parseAttack(attack any) Attack {
if damage, ok := attack.(int); ok {
return Attack{[]int{damage}}
}
@@ -48,6 +53,7 @@ func parseAttack(attack interface{}) Attack {
attackStr := attack.(string)
tokens := strings.Split(attackStr, " ")
a, err := strconv.Atoi(tokens[0])
+ // TODO: think about panicking here
if err != nil {
log.Panicf("Attack %s has no valid Damage value\n", attackStr)
}
@@ -61,7 +67,7 @@ func parseAttack(attack interface{}) Attack {
}
attacks := make([]int, 0, r)
- for i := 0; i < r; i++ {
+ for range r {
attacks = append(attacks, a)
}