-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame_log.go
58 lines (46 loc) · 973 Bytes
/
game_log.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
package main
import (
"fmt"
"github.com/daviddengcn/go-colortext"
)
type LogEvent struct {
Message string
Xp int
Life int
Speed int
Power int
Ancestry int
}
var gameLogMem = make([]string, 0)
type GameLog struct {
recvEvents <-chan LogEvent
}
func (s *GameLog) InitLogEventStream(logEvents <-chan LogEvent) {
s.recvEvents = logEvents
go func() {
for logEvent := range logEvents {
s.storeLogEvent(logEvent)
}
}()
}
func NewGameLog() (*GameLog, error) {
gameLog := &GameLog{
recvEvents: make(chan LogEvent),
}
return gameLog, nil
}
func (s *GameLog) storeLogEvent(logEvent LogEvent) {
var logString = fmt.Sprintf("%+v", logEvent)
gameLogMem = append(gameLogMem, logString)
}
func (*GameLog) PrintGameLog() {
ct.ChangeColor(ct.Yellow, true, ct.None, false)
fmt.Println()
fmt.Println("Game Log")
fmt.Println("--------")
for _, gameLog := range gameLogMem {
fmt.Println(gameLog)
}
fmt.Println()
ct.ResetColor()
}