/
obstacle.go
42 lines (34 loc) · 931 Bytes
/
obstacle.go
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
package game
import "fmt"
// ObstacleType is an enum.
type ObstacleType int
//go:generate stringer -type=ObstacleType
// ParseObstacleType parses an ObstacleType from a string.
func ParseObstacleType(s string) (ObstacleType, error) {
for i := 0; i < len(_ObstacleType_index)-1; i++ {
if ObstacleType(i).String() == s+"Obstacle" {
return ObstacleType(i), nil
}
}
return NonObstacle, fmt.Errorf("unrecognised obstacle %s", s)
}
// ObstacleTypes represent the thing that is the obstacle. These might be static
// obstacle types, like a Tree or Rock, or another Character could be an Obstacle
// too.
const (
NonObstacle ObstacleType = iota
CharacterObstacle
CrevasseObstacle
TreeObstacle
DeepWaterObstacle
MudObstacle
)
// Obstacle is a Component that blocks a Hex.
type Obstacle struct {
M, N int
ObstacleType ObstacleType
}
// Type of the Component.
func (o *Obstacle) Type() string {
return "Obstacle"
}