This repository has been archived by the owner on Sep 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (58 loc) · 1.43 KB
/
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"github.com/gdamore/tcell"
"github.com/kitaminka/snake-game/game"
"log"
"math/rand"
"os"
"strconv"
"time"
)
const (
DefaultColor = tcell.ColorWhite
SnakeColor = tcell.ColorGreenYellow
AppleColor = tcell.ColorRed
)
const (
StartDelay time.Duration = 100
MinDelay time.Duration = 50
DelayChange time.Duration = 10
MaxApples = 3
NewAppleChance = 5
SnakeLength = 5
FieldWidth = 100
FieldHeight = 12
)
func main() {
rand.Seed(time.Now().UTC().UnixNano())
s, err := tcell.NewScreen()
if err != nil {
log.Fatalf("%+v", err)
}
if err := s.Init(); err != nil {
log.Fatalf("%+v", err)
}
styles := game.Styles{
DefaultStyle: tcell.StyleDefault.Foreground(DefaultColor),
SnakeStyle: tcell.StyleDefault.Foreground(SnakeColor),
AppleStyle: tcell.StyleDefault.Foreground(AppleColor),
}
configuration := game.Configuration{
StartDelay: StartDelay,
MinDelay: MinDelay,
DelayChange: DelayChange,
MaxApples: MaxApples,
NewAppleChance: NewAppleChance,
SnakeLength: SnakeLength,
FieldWidth: FieldWidth,
FieldHeight: FieldHeight,
}
width, height := s.Size()
g := game.NewGame(&s, nil, nil, width, height, styles, configuration)
g.InitGame()
g.StartGame()
s.Fini()
fmt.Printf("Game Over!\nGame result: %v", strconv.Itoa(g.Score.Value))
os.Exit(0)
}