Skip to content

Commit bc0ca54

Browse files
author
Lewis Jones
committed
Inject blind alert destination to Game
CLI injects in Stdout. Next we will implement destination for webserver
1 parent c8f8c1b commit bc0ca54

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

CLI.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (cli *CLI) PlayPoker() {
3737
return
3838
}
3939

40-
cli.game.Start(numberOfPlayers)
40+
cli.game.Start(numberOfPlayers, cli.out)
4141

4242
winnerInput := cli.readLine()
4343
winner, err := extractWinner(winnerInput)

CLI_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package poker_test
22

33
import (
44
"bytes"
5+
"io"
56
"strings"
67
"testing"
78

@@ -20,7 +21,7 @@ type GameSpy struct {
2021
FinishCalled bool
2122
}
2223

23-
func (g *GameSpy) Start(numberOfPlayers int) {
24+
func (g *GameSpy) Start(numberOfPlayers int, alertsDestination io.Writer) {
2425
g.StartedWith = numberOfPlayers
2526
g.StartCalled = true
2627
}

game.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package poker
22

3+
import "io"
4+
35
type Game interface {
4-
Start(numberOfPlayers int)
6+
Start(numberOfPlayers int, alertsDestination io.Writer)
57
Finish(winner string)
68
}

texas_holdem.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package poker
22

33
import (
4-
"os"
4+
"io"
55
"time"
66
)
77

@@ -17,13 +17,13 @@ func NewGame(alerter BlindAlerter, store PlayerStore) Game {
1717
}
1818
}
1919

20-
func (p *TexasHoldem) Start(numberOfPlayers int) {
20+
func (p *TexasHoldem) Start(numberOfPlayers int, alertsDestination io.Writer) {
2121
blindIncrement := time.Duration(5+numberOfPlayers) * time.Minute
2222

2323
blinds := []int{100, 200, 300, 400, 500, 600, 800, 1000, 2000, 4000, 8000}
2424
blindTime := 0 * time.Second
2525
for _, blind := range blinds {
26-
p.alerter.ScheduleAlertAt(blindTime, blind, os.Stdout)
26+
p.alerter.ScheduleAlertAt(blindTime, blind, alertsDestination)
2727
blindTime = blindTime + blindIncrement
2828
}
2929
}

texas_holdem_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package poker_test
22

33
import (
44
"fmt"
5+
"io/ioutil"
56
"testing"
67
"time"
78

@@ -14,7 +15,7 @@ func TestGame_Start(t *testing.T) {
1415
blindAlerter := &poker.SpyBlindAlerter{}
1516
game := poker.NewGame(blindAlerter, dummyPlayerStore)
1617

17-
game.Start(5)
18+
game.Start(5, ioutil.Discard)
1819

1920
cases := []poker.ScheduledAlert{
2021
{At: 0 * time.Second, Amount: 100},
@@ -37,7 +38,7 @@ func TestGame_Start(t *testing.T) {
3738
blindAlerter := &poker.SpyBlindAlerter{}
3839
game := poker.NewGame(blindAlerter, dummyPlayerStore)
3940

40-
game.Start(7)
41+
game.Start(7, ioutil.Discard)
4142

4243
cases := []poker.ScheduledAlert{
4344
{At: 0 * time.Second, Amount: 100},

0 commit comments

Comments
 (0)