-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple.go
60 lines (54 loc) · 1.13 KB
/
simple.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"fmt"
"log"
"os"
"time"
"github.com/kssilveira/idle-game-engine/data"
"github.com/kssilveira/idle-game-engine/game"
"github.com/kssilveira/idle-game-engine/textui"
"github.com/kssilveira/idle-game-engine/ui"
)
func main() {
g := game.NewGame(game.Config{
NowFn: func() time.Time { return time.Now() },
})
g.AddResources([]data.Resource{{
Name: "catnip", Count: 10, Cap: 100,
Producers: []data.Resource{{
Name: "Catnip Field", Factor: 0.63,
}},
}, {
Name: "Catnip Field", Cap: -1,
}})
g.AddActions([]data.Action{{
Name: "Catnip Field",
CostExponentBase: 1.12,
Costs: []data.Resource{{
Name: "catnip", Count: 10,
}},
Adds: []data.Resource{{
Name: "Catnip Field", Count: 1,
}},
}})
if err := g.Validate(); err != nil {
log.Fatal(err)
}
input := make(chan string)
output := make(chan *ui.Data)
go g.Run(input, output)
go func() {
for {
var got string
fmt.Scanln(&got)
input <- got
}
}()
cfg := textui.Config{
Logger: log.New(os.Stdout, "", 0 /* flags */),
Separator: "\033[H\033[2J",
}
for data := range output {
textui.Show(cfg, data)
}
}