-
Notifications
You must be signed in to change notification settings - Fork 0
/
vars.go
67 lines (59 loc) · 1.22 KB
/
vars.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 spin
import "fmt"
const (
PriorityAudioModeCallout = 1
)
type GameVars struct {
BallActive bool
BallsInPlay int
BallsPerGame int
BallSave bool
BallLaunchReady bool
Player int
PlayfieldActive bool
Ball int
MaxPlayers int
NumPlayers int
ExtraBalls int
IsExtraBall bool
}
type PlayerVars struct {
Score int
}
func GetGameVars(store Store) *GameVars {
v, ok := store.GetVars("game")
var vars *GameVars
if ok {
vars = v.(*GameVars)
} else {
vars = &GameVars{}
vars.Player = 1
vars.BallsPerGame = 3
vars.MaxPlayers = 4
store.RegisterVars("game", vars)
}
return vars
}
func GetPlayerVarsFor(store Store, player int) *PlayerVars {
name := fmt.Sprintf("player.%v", player)
v, ok := store.GetVars(name)
var vars *PlayerVars
if ok {
vars = v.(*PlayerVars)
} else {
vars = &PlayerVars{}
store.RegisterVars(name, vars)
}
return vars
}
func ResetPlayerVars(store Store) {
game := GetGameVars(store)
for i := 1; i < game.MaxPlayers; i++ {
name := fmt.Sprintf("player.%v", i)
store.RegisterVars(name, &PlayerVars{})
}
}
func GetPlayerVars(store Store) *PlayerVars {
game := GetGameVars(store)
return GetPlayerVarsFor(store, game.Player)
}