spacetea/simulator/plant.go

49 lines
725 B
Go
Raw Normal View History

2022-05-17 23:29:59 -04:00
package simulator
import (
2022-05-19 15:18:03 -04:00
"fmt"
2022-05-17 23:29:59 -04:00
"strconv"
)
//Plant is a plant that grows per tick
type Plant struct {
2022-05-19 12:58:37 -04:00
kind int
value int
growth int
}
func newPlant(k int) *Plant {
return &Plant{
kind: k,
value: 0,
growth: 0,
}
2022-05-17 23:29:59 -04:00
}
//Tick one iteration
func (p *Plant) Tick() {
2022-05-19 12:58:37 -04:00
p.growth++
if p.growth > 10 {
p.value++
p.growth = 0
}
2022-05-17 23:29:59 -04:00
}
//Get produced plant
func (p *Plant) Get() Produce {
var pro Produce
pro.Value = p.value
pro.Kind = p.kind
p.value = 0
return pro
}
func (p *Plant) String() string {
return strconv.Itoa(p.kind)
}
2022-05-19 15:18:03 -04:00
//Describe returns a human useful string
func (p *Plant) Describe() string {
return fmt.Sprintf("A %v plant with %v value", strconv.Itoa(p.kind), strconv.Itoa(p.value))
}