-
Notifications
You must be signed in to change notification settings - Fork 1
/
idle.go
67 lines (63 loc) · 1.21 KB
/
idle.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
61
62
63
64
65
66
67
package main
import (
"time"
"fmt"
// "fmt"
// "time"
"github.com/nsf/termbox-go"
keyboard "github.com/julienroland/keyboard-termbox"
)
var num int
var inc int
var nextIncFee int
var nextInc int
func main(){
//Init termbox
err := termbox.Init()
if err != nil {
panic(err)
}
defer termbox.Close()
setUpKey() //using type assertion
setUpGlobalGameVar()
fmt.Printf("\r\t%10v\t%10v\t\t%10v\t\t%10v\t\t\n","num","inc","nextInc","nextIncFee")
for {
num += inc
time.Sleep(400*time.Millisecond)
fmt.Printf("\r\t%10v\t%10v\t\t%10v\t\t%10v\t\t",num,inc,nextInc,nextIncFee)
}
}
func setUpGlobalGameVar() {
num = 0
inc = 1
nextIncFee = 10
nextInc = 1
}
func setUpKey() {
kb := keyboard.New()
kb.Bind(func() { panic("Exiting!!!!!!!!!!!!!!!!!!!!!!") }, "escape", "q")
kb.Bind(func() {
inccount := 0
if(num > nextIncFee){
num -= inc*10
inc += nextInc
inccount++
nextIncFee = inc*10+inccount
nextInc = inc/(8+inccount) + 1
}
}, "up", "k")
kb.Bind(func() {
fmt.Println("down")
}, "down", "j")
kb.Bind(func() {
fmt.Println("left")
}, "left", "h")
kb.Bind(func() {
fmt.Println("right")
}, "right", "l")
go func() {
for{
kb.Poll(termbox.PollEvent())
}
}()
}