game

package
v1.0.0-beta68 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2016 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertCurrents

func AssertCurrents(t *testing.T, state *common.GameState, p, d int)

AssertCurrents assertion on currentPlayer and CurrentDart

func AssertEquals

func AssertEquals(t *testing.T, expected, actual interface{})

AssertEquals classical assertEquals

func AssertError

func AssertError(t *testing.T, err error, expected string)

AssertError assert the error content

func AssertGameState

func AssertGameState(t *testing.T, state *common.GameState, expected common.State)

AssertGameState assert the GameState is as exepcetd

func AssertName

func AssertName(t *testing.T, ps common.PlayerState, name string)

AssertName assert the name is what expected

func AssertRank

func AssertRank(t *testing.T, ps common.PlayerState, target int)

AssertRank assert the ranking is what expected

func AssertScore

func AssertScore(t *testing.T, ps common.PlayerState, target int)

AssertScore assert the score is what expected

Types

type BaseGame

type BaseGame struct {
	DisplayStyle string
	// contains filtered or unexported fields
}

BaseGame common Game struct

func (*BaseGame) BoardHasLeft

func (game *BaseGame) BoardHasLeft(board string) bool

BoardHasLeft is call to notify the game a board has been disconnected. It returns true if the game continues despite this event.

func (*BaseGame) State

func (game *BaseGame) State() *common.GameState

State : get the current GameState

type CountUp

type CountUp struct {
	BaseGame
	// contains filtered or unexported fields
}

CountUp is a highscore Game, winner is the first to obtain a given score or more

func NewGameCountUp

func NewGameCountUp(opt OptionCountUp) *CountUp

NewGameCountUp : GameCountUp constructor using a OptionCountUp

func (*CountUp) AddPlayer

func (game *CountUp) AddPlayer(board string, name string) error

AddPlayer add a new player to the game

func (*CountUp) HandleDart

func (game *CountUp) HandleDart(sector common.Sector) (result *common.GameState, error error)

HandleDart the implementation has to handle the Dart regarding the current player, the rules, and the context. Return a GameState

func (*CountUp) HoldOrNextPlayer

func (game *CountUp) HoldOrNextPlayer()

HoldOrNextPlayer switch game state between ONHOLD and PLAYING

func (*CountUp) Start

func (game *CountUp) Start() error

Start start the game, Darts will be handled

type Cricket

type Cricket struct {
	BaseGame
	// contains filtered or unexported fields
}

Cricket is a cricket series Game (Cricket, Cut-throat)

func NewGameCricket

func NewGameCricket(opt OptionCricket) *Cricket

NewGameCricket : GameCricket constructor using a OptionCricket

func (*Cricket) AddPlayer

func (game *Cricket) AddPlayer(board string, name string) (error error)

AddPlayer add a new player to the game

func (*Cricket) HandleDart

func (game *Cricket) HandleDart(sector common.Sector) (result *common.GameState, error error)

HandleDart the implementation has to handle the Dart regarding the current player, the cricket rules, and the context. Return a GameState

func (*Cricket) HoldOrNextPlayer

func (game *Cricket) HoldOrNextPlayer()

HoldOrNextPlayer switch game state between ONHOLD and PLAYING

func (*Cricket) Start

func (game *Cricket) Start() (error error)

Start start the game, Darts will be handled

type Game

type Game interface {
	// Start start the game, Darts will be handled
	Start() error
	// AddPlayer add a new player to the game
	AddPlayer(board string, name string) error
	// HandleDart the implementation has to handle the Dart regarding the current player, the rules, and the context. Return a GameState
	HandleDart(sector common.Sector) (*common.GameState, error)
	// GetState, get the current GameState
	State() *common.GameState
	// BoardHasLeft is call to notify the game a board has been disconnected. Returns true if the game continues despite this event
	BoardHasLeft(board string) bool
	// HoldOrNextPlayer switch game state between ONHOLD and PLAYING with side effects according to game implementation
	HoldOrNextPlayer()
	// contains filtered or unexported methods
}

Game interface, should be implemented by all game (rules) implems

type Gamex01

type Gamex01 struct {
	BaseGame
	// contains filtered or unexported fields
}

Gamex01 is a x01 series Game (301, 501-Double-Out, ...)

func NewGamex01

func NewGamex01(opt Optionx01) *Gamex01

NewGamex01 : Gamex01 constructor

func (*Gamex01) AddPlayer

func (game *Gamex01) AddPlayer(board string, name string) error

AddPlayer add a new player to the game

func (*Gamex01) HandleDart

func (game *Gamex01) HandleDart(sector common.Sector) (result *common.GameState, error error)

HandleDart the implementation has to handle the Dart regarding the current player, the rules of x01, and the context. Return a GameState

func (*Gamex01) HoldOrNextPlayer

func (game *Gamex01) HoldOrNextPlayer()

HoldOrNextPlayer switch game state between ONHOLD and PLAYING

func (*Gamex01) Start

func (game *Gamex01) Start() (error error)

Start start the game, Darts will be handled

type Highest

type Highest struct {
	BaseGame
	// contains filtered or unexported fields
}

Highest is a highscore Game, within a fixed number of visit, winner is the highest score

func NewGameHighest

func NewGameHighest(opt OptionHighest) *Highest

NewGameHighest : GameHighest constructor using a OptionHighest

func (*Highest) AddPlayer

func (game *Highest) AddPlayer(board string, name string) error

AddPlayer add a new player to the game

func (*Highest) HandleDart

func (game *Highest) HandleDart(sector common.Sector) (result *common.GameState, error error)

HandleDart the implementation has to handle the Dart regarding the current player, the rules, and the context. Return a GameState

func (*Highest) HoldOrNextPlayer

func (game *Highest) HoldOrNextPlayer()

HoldOrNextPlayer switch game state between ONHOLD and PLAYING

func (*Highest) Start

func (game *Highest) Start() error

Start start the game, Darts will be handled

type OptionCountUp

type OptionCountUp struct {
	Target int
}

OptionCountUp is the struct to handle GameCountUp parameters

type OptionCricket

type OptionCricket struct {
	NoScore   bool
	CutThroat bool
}

OptionCricket is the struct to handle GameCricket parameters

type OptionHighest

type OptionHighest struct {
	Rounds int
}

OptionHighest is the struct to handle GameHighest parameters

type Optionx01

type Optionx01 struct {
	Score     int
	DoubleOut bool
}

Optionx01 is the struct to handle Gamex01 parameters

Jump to

Keyboard shortcuts

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