From c926ae2ef93e6a0dba1ab884f772c022922158ce Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Thu, 14 May 2020 08:39:42 +0200 Subject: [PATCH] Added bonusses when flower is adjacent to more flowers --- game.go | 10 +++++++++- map.go | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/game.go b/game.go index ada276e..12149d9 100644 --- a/game.go +++ b/game.go @@ -114,7 +114,15 @@ func (g *Game) Dig(tile Point) { if !ok { return } - g.Balance += desc.SellPrice + adjacent := g.Terrain.FlowersOnAdjacentTiles(tile) + switch adjacent { + case 3: + g.Balance += (desc.SellPrice * 3 / 2) // 50% bonus + case 4: + g.Balance += (desc.SellPrice * 2) // 100% bonus + default: + g.Balance += desc.SellPrice + } } func (g *Game) New() { diff --git a/map.go b/map.go index 3d9dcd5..d585564 100644 --- a/map.go +++ b/map.go @@ -15,6 +15,23 @@ func (m *Map) AddFlower(pos Point, id string, traits FlowerTraits) { m.Flowers[pos] = m.NewFlower(pos, id, traits) } +func (m *Map) FlowersOnAdjacentTiles(pos Point) int { + var count int + if _, ok := m.Flowers[Pt(pos.X+1, pos.Y)]; ok { + count++ + } + if _, ok := m.Flowers[Pt(pos.X-1, pos.Y)]; ok { + count++ + } + if _, ok := m.Flowers[Pt(pos.X, pos.Y+1)]; ok { + count++ + } + if _, ok := m.Flowers[Pt(pos.X, pos.Y-1)]; ok { + count++ + } + return count +} + func (m *Map) DigFlower(pos Point) string { flower, ok := m.Flowers[pos] if !ok {