-
Notifications
You must be signed in to change notification settings - Fork 0
/
gamedata.go
80 lines (66 loc) · 1.84 KB
/
gamedata.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
78
79
80
package isledef
import "time"
//GameMode represents the difficulty/mode of the game
type GameMode int
//Currently available game modes
const (
GameModeNormalTimed GameMode = iota
GameModeHardcoreTimed
GameModeNormalBattle
GameModeOnlineHost
GameModeOnlineJoin
GameModeOnlineRoom
)
//GameData contains data for the game
type GameData struct {
time int
shotMax int
timed bool
currentScale int
startTime time.Time
gameMode GameMode
server, port string
playerCharacter, opponentCharacter string
youStart bool
joinedRoom string
}
//NewGameData creates a new GameData to keep track of the game
func NewGameData(gameMode GameMode) *GameData {
g := &GameData{
currentScale: 1,
startTime: time.Now(),
server: "127.0.0.1",
port: "5555",
}
switch gameMode {
case GameModeNormalTimed:
g.shotMax = 24
case GameModeHardcoreTimed:
g.shotMax = 15
}
return g
}
//SetGameMode sets the game mode chosen by the character. In this case used for Timed mode to set number of bombs
func (g *GameData) SetGameMode(gameMode GameMode) {
switch gameMode {
case GameModeNormalTimed:
g.shotMax = 24
case GameModeHardcoreTimed:
g.shotMax = 15
}
g.gameMode = gameMode
}
//Update the game time
func (g *GameData) Update() {
g.time++
}
//TimeInSecond returns the current time in seconds
func (g *GameData) TimeInSecond() int {
return int(time.Now().Sub(g.startTime).Seconds())
//return g.time / 60
}
//TimeInMilliseconds returns the current time in seconds
func (g *GameData) TimeInMilliseconds() int64 {
return time.Now().Sub(g.startTime).Nanoseconds() / int64(time.Millisecond)
//return g.time / 60
}