-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.go
43 lines (36 loc) · 894 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
35
36
37
38
39
40
41
42
43
package poker
import (
"io"
"log"
"time"
)
type TexasHoldem struct {
alerter BlindAlerter
store PokerStorage
}
type Game interface {
Start(numberOfPlayers int, alertDest io.Writer)
Finish(winner string)
}
func NewTexasHoldem(alerter BlindAlerter, store PokerStorage) TexasHoldem {
return TexasHoldem{
alerter: alerter,
store: store,
}
}
func (g TexasHoldem) Start(numberOfPlayers int, alertDest io.Writer) {
if g.alerter != nil {
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 {
g.alerter.ScheduleAlertAfter(blindTime, blind, alertDest)
blindTime = blindTime + blindIncrement
}
} else {
log.Println("No alerter passed")
}
}
func (g TexasHoldem) Finish(winner string) {
g.store.RecordWin(winner)
}