poker

package module
v0.0.0-...-57dfa3e Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: MIT Imports: 16 Imported by: 0

README

go-app-via-tests

Learn Go with Tests - Build an application

Documentation

Overview

server.go

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 DBFileName = "game.db.json"
View Source
const JsonContentType = "application/json"
View Source
const PlayerPrompt = "Please enter the number of players: "

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

Variables

View Source
var IsBuild = utils.GetWorkDir() != "."

Functions

func Alerter

func Alerter(duration time.Duration, amount int, to io.Writer)

Types

type BlindAlerter

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

type BlindAlerterFunc

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

func (BlindAlerterFunc) ScheduleAlertAt

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

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 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 League

type League []Player

func NewLeague

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

func (League) Find

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

type Player

type Player struct {
	Name string
	Wins int
}

Player stores a name with a number of wins

type PlayerServer

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

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 Tape

type Tape struct {
	File *os.File
}

func (*Tape) Write

func (t *Tape) Write(p []byte) (n int, err error)

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, to io.Writer)

Start will schedule blind alerts dependant on the number of players.

Directories

Path Synopsis
cmd
cli
internal

Jump to

Keyboard shortcuts

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