-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (45 loc) · 806 Bytes
/
main.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
package main
import (
"fmt"
"os"
"github.com/16point7/tiles/game"
"github.com/gdamore/tcell"
)
func main() {
s, err := tcell.NewScreen()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
if err = s.Init(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
defer s.Fini()
s.SetStyle(bgStyle)
g := game.New()
for {
drawState(s, g.Board(), g.Score(), g.GameOver())
s.Show()
switch ev := s.PollEvent().(type) {
case *tcell.EventKey:
switch ev.Key() {
case tcell.KeyLeft:
g.MoveLeft()
case tcell.KeyRight:
g.MoveRight()
case tcell.KeyUp:
g.MoveUp()
case tcell.KeyDown:
g.MoveDown()
case tcell.KeyEscape:
return
case tcell.KeyRune:
if ev.Rune() == 'r' {
g.Reset()
s.Clear()
}
}
}
}
}