Documentation ¶
Overview ¶
server.go
Index ¶
Constants ¶
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.
const BadWinnerInputMsg = "invalid winner input, expect format of 'PlayerName wins'"
BadWinnerInputMsg is the text telling the user they declared the winner wrong.
const DBFileName = "game.db.json"
const JsonContentType = "application/json"
const PlayerPrompt = "Please enter the number of players: "
PlayerPrompt is the text asking the user for the number of players.
Variables ¶
var IsBuild = utils.GetWorkDir() != "."
Functions ¶
Types ¶
type BlindAlerter ¶
type BlindAlerterFunc ¶
func (BlindAlerterFunc) ScheduleAlertAt ¶
type CLI ¶
type CLI struct {
// contains filtered or unexported fields
}
CLI helps players through a game of poker.
type FileSystemPlayerStore ¶
type FileSystemPlayerStore struct {
// contains filtered or unexported fields
}
FileSystemPlayerStore collects data about players in file.
func FileSystemPlayerStoreFromFile ¶
func FileSystemPlayerStoreFromFile(path string) (*FileSystemPlayerStore, func(), error)
func NewFileSystemPlayerStore ¶
func NewFileSystemPlayerStore(file *os.File) (*FileSystemPlayerStore, error)
NewFileSystemPlayerStore initialises an empty player store.
func (*FileSystemPlayerStore) GetLeague ¶
func (f *FileSystemPlayerStore) GetLeague() League
func (*FileSystemPlayerStore) GetPlayerScore ¶
func (f *FileSystemPlayerStore) GetPlayerScore(name string) int
GetPlayerScore retrieves scores for a given player.
func (*FileSystemPlayerStore) RecordWin ¶
func (f *FileSystemPlayerStore) RecordWin(name string)
RecordWin will record a player's win.
type Game ¶
type Game interface { Start(numberOfPlayers int, alertsDestination io.Writer) Finish(winner string) }
Game manages the state of a game.
type InMemoryPlayerStore ¶
type InMemoryPlayerStore struct {
// contains filtered or unexported fields
}
InMemoryPlayerStore collects data about players in memory.
func NewInMemoryPlayerStore ¶
func NewInMemoryPlayerStore() *InMemoryPlayerStore
NewInMemoryPlayerStore initialises an empty player store.
func (*InMemoryPlayerStore) GetLeague ¶
func (i *InMemoryPlayerStore) GetLeague() League
func (*InMemoryPlayerStore) GetPlayerScore ¶
func (i *InMemoryPlayerStore) GetPlayerScore(name string) int
GetPlayerScore retrieves scores for a given player.
func (*InMemoryPlayerStore) RecordWin ¶
func (i *InMemoryPlayerStore) RecordWin(name string)
RecordWin will record a player's win.
type PlayerServer ¶
PlayerServer is a HTTP interface for player information
func NewPlayerServer ¶
func NewPlayerServer(store PlayerStore, game Game) (*PlayerServer, error)
NewPlayerServer creates a PlayerServer with routing configured
type PlayerStore ¶
type PlayerStore interface { GetPlayerScore(name string) int RecordWin(name string) GetLeague() League }
PlayerStore stores score information about players
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.