-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.go
50 lines (36 loc) · 1.01 KB
/
game.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
package battleword
import (
"math/rand"
"time"
"github.com/google/uuid"
)
type Game struct {
ID string `json:"game_id,omitempty"`
Answer string `json:"answer,omitempty"`
// Summary *GameSummary `json:"summary,omitempty"`
numLetters int
numRounds int
}
// type GameSummary struct {
// Start time.Time `json:"start,omitempty"`
// End time.Time `json:"end,omitempty"`
// Fastest Fastest `json:"fastest,omitempty"`
// MostAccurate MostAccurate `json:"most_accurate,omitempty"`
// Loudest Loudest `json:"loudest,omitempty"`
// }
func InitGame(commonWords []string, numLetters, numRounds int) Game {
id := uuid.New()
game := Game{
ID: id.String(),
// TODO:make this adjust to numletters
Answer: GetRandomWord(commonWords),
numLetters: numLetters,
numRounds: numRounds,
}
return game
}
func GetRandomWord(words []string) string {
// don't need to do this any more legit than this i don't think
rand.Seed(time.Now().UnixNano())
return words[rand.Intn(len(words))]
}