diff options
Diffstat (limited to 'go')
| -rw-r--r-- | go/game/map.go | 17 | ||||
| -rw-r--r-- | go/game/map_test.go | 4 | ||||
| -rw-r--r-- | go/game/permanent.go | 3 | ||||
| -rw-r--r-- | go/game/pos.go | 11 | ||||
| -rw-r--r-- | go/game/state.go | 4 |
5 files changed, 29 insertions, 10 deletions
diff --git a/go/game/map.go b/go/game/map.go index b3203bd4..54071933 100644 --- a/go/game/map.go +++ b/go/game/map.go @@ -28,7 +28,7 @@ type MapYml struct { Map string `yaml:"map"` Symbols map[string]string `yaml:"symbols"` StartDeckList string `yaml:"start_deck_list"` - Kings [][]int `yaml:"omitemptt"` + Kings [][]int `yaml:"kings,omitempty"` } type Map struct { @@ -95,13 +95,16 @@ func ParseMap(data []byte) (*Map, error) { m.selectStreets() - if len(mapYml.Kings) == 0 { + if len(mapYml.Kings) > 0 { m.WinCondition = KingGame m.Prepare = func(s *LocalState) { - k := NewCard("misc/king") for i, kingPos := range mapYml.Kings { - p := s.PlayerById(i + 1) - s.addNewUnit(k, Position{kingPos[0], kingPos[1]}, p) + card := NewCard("misc/king") + owner := s.PlayerById(i + 1) + // TODO: Fix position index base. + pos := Position{kingPos[0] - 1, kingPos[1] - 1} + log.Println(card, pos, owner) + s.addNewUnit(card, pos, owner) } } } @@ -210,9 +213,9 @@ func LoadMap(path string) (*Map, error) { } // TileAt returns the tile at a certain position. -// Id p is an invalid position, nil is returned. +// If p is an invalid position, nil is returned. func (m *Map) TileAt(p Position) *Tile { - if p.Y < 0 || p.Y >= len(m.Tiles) || p.X < 0 || p.X >= len(m.Tiles[p.Y]) { + if !p.Valid() || p.Y >= len(m.Tiles) || p.X >= len(m.Tiles[p.Y]) { return nil } return &m.Tiles[p.Y][p.X] diff --git a/go/game/map_test.go b/go/game/map_test.go index e950747b..15fa05cb 100644 --- a/go/game/map_test.go +++ b/go/game/map_test.go @@ -52,8 +52,8 @@ symbols: 2: spawn player 2 kings: - - (1,9) - - (9,1)` + - [1,9] + - [9,1]` m := parseMapString(t, s) diff --git a/go/game/permanent.go b/go/game/permanent.go index 47166d61..76f2325d 100644 --- a/go/game/permanent.go +++ b/go/game/permanent.go @@ -60,6 +60,9 @@ type permanentBase struct { } func newPermanentBase(card *Card, tile *Tile, owner *Player) permanentBase { + if card == nil || tile == nil || owner == nil { + log.Panicf("invalid argument for newPermanentBase(%p, %p, %p\n)", card, tile, owner) + } if tile != nil && tile.Permanent != nil { log.Panicf("Tile at %v already occupied by %v", tile.Position, tile.Permanent) } diff --git a/go/game/pos.go b/go/game/pos.go index 133f599b..bf35ca3b 100644 --- a/go/game/pos.go +++ b/go/game/pos.go @@ -4,6 +4,12 @@ import ( "fmt" ) +// Position represents a zero-based position on the map. +// TODO: Change to a 1-based coordinate system. +// +// This allows to use the zero value as invalid Position. +// +// The origin is the upper left corner of the map. type Position struct { X int Y int @@ -22,3 +28,8 @@ func (p Position) String() string { func INVALID_POSITION() Position { return Position{-1, -1} } + +// Valid reports if a coordinate is smaller than 0. +func (p Position) Valid() bool { + return p.X >= 0 && p.Y >= 0 +} diff --git a/go/game/state.go b/go/game/state.go index 6c3b237f..e16233a5 100644 --- a/go/game/state.go +++ b/go/game/state.go @@ -137,7 +137,9 @@ func (s *LocalState) IsActivePlayer(p *Player) bool { func (s *LocalState) Loop() []*Player { // Prepare the map - s._map.Prepare(s) + if s._map.Prepare != nil { + s._map.Prepare(s) + } if s._map.HasStores() { poc := NewPileOfCards() |
