-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.go
34 lines (28 loc) · 805 Bytes
/
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
package poker
import "time"
// Game manages a game of poker
type Game struct {
alerter BlindAlerter
store PlayerStore
}
// NewGame returns a new game
func NewGame(alerter BlindAlerter, store PlayerStore) *Game {
return &Game{
alerter: alerter,
store: store,
}
}
// Start will schedule blind alerts dependant on the number of players
func (p *Game) Start(numberOfPlayers int) {
blindIncrement := time.Duration(5+numberOfPlayers) * time.Minute
blinds := []int{100, 200, 300, 400, 500, 600, 800, 1000, 2000, 4000, 8000}
blindTime := 0 * time.Second
for _, blind := range blinds {
p.alerter.ScheduleAlertAt(blindTime, blind)
blindTime = blindTime + blindIncrement
}
}
// Finish ends the game, recording the winner
func (p *Game) Finish(winner string) {
p.store.RecordWin(winner)
}