aboutsummaryrefslogtreecommitdiff
path: root/go/game/map.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-01-26 22:16:10 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:44 +0100
commit926ca5cdd20a39e3e05aaa3486cb166718dab5ca (patch)
tree3d7bc8a0e1e0be1ce8d92d5503bdede878e718e9 /go/game/map.go
parent8720ebf9c74d9e11001772b5c00c293fa3a8b9e5 (diff)
downloadmuhqs-game-926ca5cdd20a39e3e05aaa3486cb166718dab5ca.tar.gz
muhqs-game-926ca5cdd20a39e3e05aaa3486cb166718dab5ca.zip
intermeditae commit
Diffstat (limited to 'go/game/map.go')
-rw-r--r--go/game/map.go57
1 files changed, 52 insertions, 5 deletions
diff --git a/go/game/map.go b/go/game/map.go
index 72e17ad4..cfabfaf9 100644
--- a/go/game/map.go
+++ b/go/game/map.go
@@ -19,8 +19,8 @@ const (
BASE_URL string = "localhost:8000/"
MAP_URL_PART string = "html/build/maps"
- DEFAULT_RESSOURCE_GAIN int = 5
- DEFAULT_START_DECK string = "3 misc/farmer"
+ DEFAULT_RESOURCE_GAIN int = 5
+ DEFAULT_START_DECK string = "3 misc/farmer"
)
type MapYml struct {
@@ -36,9 +36,10 @@ func DummyWinCondition(*State) []*Player {
type Map struct {
Tiles [][]Tile
symbols map[string]string
- RessourceGain int
+ ResourceGain int
StartDeckList string
WinCondition func(*State) []*Player
+ Stores map[Position]*Store
}
func readMap(r io.Reader) (*Map, error) {
@@ -59,7 +60,14 @@ func ParseMap(data []byte) (*Map, error) {
mapYml.Symbols[" "] = "neutral"
- m := &Map{[][]Tile{}, mapYml.Symbols, DEFAULT_RESSOURCE_GAIN, DEFAULT_START_DECK, DummyWinCondition}
+ m := &Map{
+ Tiles: [][]Tile{},
+ symbols: mapYml.Symbols,
+ ResourceGain: DEFAULT_RESOURCE_GAIN,
+ StartDeckList: DEFAULT_START_DECK,
+ WinCondition: DummyWinCondition,
+ Stores: make(map[Position]*Store),
+ }
if mapYml.StartDeckList != "" {
m.StartDeckList = mapYml.StartDeckList
@@ -70,11 +78,17 @@ func ParseMap(data []byte) (*Map, error) {
row := rows[y]
m.Tiles = append(m.Tiles, []Tile{})
for x := 0; x < len(rows[y]); x++ {
+ pos := Position{x, y}
s := string(row[x])
- tile, err := NewTileFromString(mapYml.Symbols[s], Position{x, y})
+ tile, err := NewTileFromString(mapYml.Symbols[s], pos)
if err != nil {
return nil, err
}
+
+ if tile.Type == TileTypes.Store {
+ m.Stores[pos] = NewStore()
+ }
+
m.Tiles[y] = append(m.Tiles[y], tile)
}
}
@@ -254,3 +268,36 @@ func (m *Map) FilterTiles(filter func(t *Tile) bool) []*Tile {
func (m *Map) AllTiles() []*Tile {
return m.FilterTiles(func(*Tile) bool { return true })
}
+
+func (m *Map) distributeStoreCards(cards PileOfCards, rand *rand.Rand) {
+ nStores := len(m.Stores)
+ stores := make([]*Store, 0, nStores)
+ for _, store := range m.Stores {
+ stores = append(stores, store)
+ }
+
+ d := NewDeckFrom(cards)
+ d.Shuffle(rand)
+ nCards := d.Size()
+
+ for i := 0; i < nCards; i++ {
+ c := d.DrawOne()
+ stores[i%nStores].AddCard(c)
+ }
+}
+
+func (m *Map) redistributeStoreCards(cards PileOfCards, rand *rand.Rand) {
+ poc := NewPileOfCards()
+ for _, store := range m.Stores {
+ store.MoveInto(poc)
+ }
+ m.distributeStoreCards(poc, rand)
+}
+
+func (m *Map) HasStores() bool {
+ return len(m.Stores) > 0
+}
+
+func (m *Map) GetStoreOn(p Position) *Store {
+ return m.Stores[p]
+}