Added bonusses when flower is adjacent to more flowers

This commit is contained in:
Sander Schobers 2020-05-14 08:39:42 +02:00
parent 013fe4bdb6
commit c926ae2ef9
2 changed files with 26 additions and 1 deletions

10
game.go
View File

@ -114,7 +114,15 @@ func (g *Game) Dig(tile Point) {
if !ok { if !ok {
return 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() { func (g *Game) New() {

17
map.go
View File

@ -15,6 +15,23 @@ func (m *Map) AddFlower(pos Point, id string, traits FlowerTraits) {
m.Flowers[pos] = m.NewFlower(pos, id, traits) 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 { func (m *Map) DigFlower(pos Point) string {
flower, ok := m.Flowers[pos] flower, ok := m.Flowers[pos]
if !ok { if !ok {