poker

package
v0.0.0-...-0adf08c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const BadPlayerInputErrMsg = "Bad value received for number of players, please try again with a number"

BadPlayerInputErrMsg is the text telling the user they did bad things

View Source
const BadWinnerInputMsg = "invalid winner input, expect format of 'PlayerName wins'"

BadWinnerInputMsg is the text telling the user they declared the winner wrong

View Source
const PlayerPrompt = "Please enter the number of players: "

PlayerPrompt is the text asking the user for the number of players

Variables

This section is empty.

Functions

func AssertPlayerWin

func AssertPlayerWin(t *testing.T, store *StubPlayerStore, winner string)

func StdOutAlerter

func StdOutAlerter(duration time.Duration, amount int)

Types

type BlindAlerter

type BlindAlerter interface {
	ScheduleAlertAt(duration time.Duration, amount int)
}

type BlindAlerterFunc

type BlindAlerterFunc func(duration time.Duration, amount int)

func (BlindAlerterFunc) ScheduleAlertAt

func (a BlindAlerterFunc) ScheduleAlertAt(duration time.Duration, amount int)

type CLI

type CLI struct {
	// contains filtered or unexported fields
}

CLI helps players through a game of poker

func NewCLI

func NewCLI(in io.Reader, out io.Writer, game Game) *CLI

NewCLI creates a CLI for playing poker

func (*CLI) PlayPoker

func (cli *CLI) PlayPoker()

PlayPoker starts the game

type FileSystemPlayerStore

type FileSystemPlayerStore struct {
	// contains filtered or unexported fields
}

FileSystemPlayerStore stores players in the filesystem

func FileSystemPlayerStoreFromFile

func FileSystemPlayerStoreFromFile(path string) (*FileSystemPlayerStore, func(), error)

FileSystemPlayerStoreFromFile creates a PlayerStore from the contents of a JSON file found at path

func NewFileSystemPlayerStore

func NewFileSystemPlayerStore(file *os.File) (*FileSystemPlayerStore, error)

NewFileSystemPlayerStore creates a FileSystemPlayerStore initialising the store if needed

func (*FileSystemPlayerStore) GetLeague

func (f *FileSystemPlayerStore) GetLeague() League

GetLeague returns the Scores of all the players

func (*FileSystemPlayerStore) GetPlayerScore

func (f *FileSystemPlayerStore) GetPlayerScore(name string) int

GetPlayerScore retrieves a player's score

func (*FileSystemPlayerStore) RecordWin

func (f *FileSystemPlayerStore) RecordWin(name string)

RecordWin will store a win for a player, incrementing wins if already known

type Game

type Game interface {
	Start(numberOfPlayers int)
	Finish(winner string)
}

Game manages the state of a game

type InMemoryPlayerStore

type InMemoryPlayerStore struct {
	// contains filtered or unexported fields
}

func NewInMemoryPlayerStore

func NewInMemoryPlayerStore() *InMemoryPlayerStore

func (*InMemoryPlayerStore) GetLeague

func (i *InMemoryPlayerStore) GetLeague() League

func (*InMemoryPlayerStore) GetPlayerScore

func (i *InMemoryPlayerStore) GetPlayerScore(name string) int

func (*InMemoryPlayerStore) RecordWin

func (i *InMemoryPlayerStore) RecordWin(name string)

type League

type League []Player

func NewLeague

func NewLeague(rdr io.Reader) (League, error)

func (League) Find

func (l League) Find(name string) *Player

type Player

type Player struct {
	Name string
	Wins int
}

type PlayerServer

type PlayerServer struct {
	http.Handler
	// contains filtered or unexported fields
}

func NewPlayerServer

func NewPlayerServer(store PlayerStore) *PlayerServer

type PlayerStore

type PlayerStore interface {
	GetPlayerScore(name string) int
	RecordWin(name string)
	GetLeague() League
}

type ScheduledAlert

type ScheduledAlert struct {
	At     time.Duration
	Amount int
}

ScheduledAlert holds information about when an alert is scheduled

func (ScheduledAlert) String

func (s ScheduledAlert) String() string

type SpyBlindAlerter

type SpyBlindAlerter struct {
	Alerts []ScheduledAlert
}

SpyBlindAlerter allows you to spy on ScheduleAlertAt calls

func (*SpyBlindAlerter) ScheduleAlertAt

func (s *SpyBlindAlerter) ScheduleAlertAt(at time.Duration, amount int)

ScheduleAlertAt records alerts that have been scheduled

type StubPlayerStore

type StubPlayerStore struct {
	// contains filtered or unexported fields
}

func (*StubPlayerStore) GetLeague

func (s *StubPlayerStore) GetLeague() League

func (*StubPlayerStore) GetPlayerScore

func (s *StubPlayerStore) GetPlayerScore(name string) int

func (*StubPlayerStore) RecordWin

func (s *StubPlayerStore) RecordWin(name string)

type TexasHoldem

type TexasHoldem struct {
	// contains filtered or unexported fields
}

TexasHoldem manages a game of poker

func NewTexasHoldem

func NewTexasHoldem(alerter BlindAlerter, store PlayerStore) *TexasHoldem

NewTexasHoldem returns a new game

func (*TexasHoldem) Finish

func (p *TexasHoldem) Finish(winner string)

Finish ends the game, recording the winner

func (*TexasHoldem) Start

func (p *TexasHoldem) Start(numberOfPlayers int)

Start will schedule blind alerts dependant on the number of players

Directories

Path Synopsis
cmd
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL