aboutsummaryrefslogtreecommitdiff
path: root/go/game/map.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/game/map.go')
-rw-r--r--go/game/map.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/go/game/map.go b/go/game/map.go
index c84dc519..5783c9dd 100644
--- a/go/game/map.go
+++ b/go/game/map.go
@@ -29,11 +29,16 @@ type MapYml struct {
Symbols map[string]string `yaml:"symbols"`
}
+func DummyWinCondition(*State) []*Player {
+ return []*Player{}
+}
+
type Map struct {
Tiles [][]Tile
symbols map[string]string
RessourceGain int
StartDeckList string
+ WinCondition func(*State) []*Player
}
func readMap(r io.Reader) (*Map, error) {
@@ -54,7 +59,7 @@ func ParseMap(data []byte) (*Map, error) {
mapYml.Symbols[" "] = "neutral"
- m := &Map{[][]Tile{}, mapYml.Symbols, DEFAULT_RESSOURCE_GAIN, DEFAULT_START_DECK}
+ m := &Map{[][]Tile{}, mapYml.Symbols, DEFAULT_RESSOURCE_GAIN, DEFAULT_START_DECK, DummyWinCondition}
rows := strings.Split(mapYml.Map, "\n")
for y := 0; y < len(rows); y++ {
@@ -187,6 +192,9 @@ func LoadMap(file string) (*Map, error) {
}
func (m *Map) TileAt(p Position) *Tile {
+ if p.Y >= len(m.Tiles) || p.X >= len(m.Tiles[p.Y]) {
+ return nil
+ }
return &m.Tiles[p.Y][p.X]
}
@@ -226,3 +234,16 @@ func (m *Map) RandomTileFromSymbols(symbols []string) (Position, error) {
}
return m.RandomTile(types), nil
}
+
+func (m *Map) FilterTiles(filter func(t *Tile) bool) []*Tile {
+ tiles := []*Tile{}
+ for y := 0; y < len(m.Tiles); y++ {
+ for x := 0; x < len(m.Tiles[y]); x++ {
+ tile := &m.Tiles[y][x]
+ if filter(tile) {
+ tiles = append(tiles, tile)
+ }
+ }
+ }
+ return tiles
+}