forked from gophergala2016/gopher_typer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
77 lines (64 loc) · 1.47 KB
/
client.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
69
70
71
72
73
74
75
76
77
package gopherTyper
import (
"os"
tl "github.com/JoelOtter/termloop"
)
// GopherTyper handles the local state of the game.
type GopherTyper struct {
g *tl.Game
wordList []string
intro introLevel
game gameLevel
store storeLevel
end endLevel
console tl.Text
level tl.Level
stats stats
items []item
}
// NewGopherTyper gets the game ready to run.
func NewGopherTyper() (*GopherTyper, error) {
wReader, err := os.Open("data/words.txt")
if err != nil {
return nil, err
}
gt := GopherTyper{}
gt.g = tl.NewGame()
gt.g.Screen().SetFps(30)
gt.wordList = newWordLoader(wReader)
gt.intro = newIntroLevel(>, tl.ColorBlack, tl.ColorBlue)
gt.game = newGameLevel(>, tl.ColorBlack, tl.ColorRed)
gt.store = newStoreLevel(>, tl.ColorBlack, tl.ColorCyan)
gt.end = newEndLevel(>, tl.ColorBlack, tl.ColorGreen)
gt.stats = newStats()
return >, nil
}
// Run starts the game, and blocks forever.
func (gt *GopherTyper) Run() {
gt.goToIntro()
gt.g.Start()
}
func (gt *GopherTyper) goToIntro() {
gt.level = >.intro
gt.intro.Activate()
}
func (gt *GopherTyper) goToGame() {
if gt.stats.Lives == 0 {
gt.stats = newStats()
gt.items = []item{}
}
gt.level = >.game
gt.game.Activate()
}
func (gt *GopherTyper) goToStore() {
gt.level = >.store
gt.store.Activate()
}
func (gt *GopherTyper) goToEndWin() {
gt.level = >.end
gt.end.ActivateWin()
}
func (gt *GopherTyper) goToEndFail() {
gt.level = >.end
gt.end.ActivateFail()
}