Documentation ¶
Overview ¶
Package domain provides the domain logic for games (e.g. Hangman).
Index ¶
- Variables
- func DefaultNewID() string
- func LoadAllHangman(s store.Store) (map[store.ID]*Hangman, error)
- func SaveHangman(s store.Store, id store.ID, g *Hangman) (store.ID, error)
- type Dictionary
- type ErrAlreadyUsed
- type ErrGameOver
- type ErrInvalidLetter
- type ErrInvalidTurns
- type ErrInvalidWord
- type Hangman
- type HangmanResult
- func CreateHangman(stg store.Store, word string, turns int) (*HangmanResult, error)
- func JoinHangman(stg store.Store, id store.ID) (*HangmanResult, error)
- func PlayLetter(stg store.Store, id store.ID, letter rune) (*HangmanResult, error)
- func PlayWord(stg store.Store, id store.ID, word string) (*HangmanResult, error)
- type HangmanResults
- type State
Constants ¶
This section is empty.
Variables ¶
var NewID = DefaultNewID
NewID generates a new unique id for an object in the domain
Functions ¶
func DefaultNewID ¶
func DefaultNewID() string
DefaultNewID is the default implementation of NewID, and creates an id string similar to MongoDB.
func LoadAllHangman ¶
LoadAllHangman loads all hangman games from the store
Types ¶
type Dictionary ¶
type Dictionary struct {
// contains filtered or unexported fields
}
Dictionary is an unsorted immutable ring of words
func NewDictionary ¶
func NewDictionary(words []string) *Dictionary
NewDictionary creates a new dictionary object from a slice of words
func (*Dictionary) GetAt ¶
func (d *Dictionary) GetAt(pos int) string
GetAt returns a word form the Dictionary based on the value of a given position in the ring
type ErrAlreadyUsed ¶
type ErrAlreadyUsed struct {
// contains filtered or unexported fields
}
ErrAlreadyUsed indicates that the letter choice has previously been used.
type ErrGameOver ¶
type ErrGameOver struct {
// contains filtered or unexported fields
}
ErrGameOver indicates that the game has finished and no more play can take place.
type ErrInvalidLetter ¶
type ErrInvalidLetter struct {
// contains filtered or unexported fields
}
ErrInvalidLetter indicates that a letter is not valid choice for the game
type ErrInvalidTurns ¶
type ErrInvalidTurns struct {
// contains filtered or unexported fields
}
ErrInvalidTurns indicates that the specified number of turns is not acceptable.
type ErrInvalidWord ¶
type ErrInvalidWord struct {
// contains filtered or unexported fields
}
ErrInvalidWord indicates that a word is not valid choice for the game
type Hangman ¶
type Hangman struct {
// contains filtered or unexported fields
}
Hangman represents a single game of hangman.
func LoadHangman ¶
LoadHangman loads a specific game from the store
func NewHangman ¶
NewHangman creates a new instance of Hangman.
func (*Hangman) Current ¶
Current returns the current state of the players knowledge about the word.
func (*Hangman) PlayLetter ¶
PlayLetter allows the client to guess a letter in the word.
type HangmanResult ¶
type HangmanResult struct { ID store.ID `json:"id,omitempty"` Current string `json:"current,omitempty"` Word *string `json:"word,omitempty"` Turns int `json:"turns,omitempty"` State State `json:"state,omitempty"` Success *bool `json:"success,omitempty"` }
HangmanResult is the result of the last action in a game of hangman.
func CreateHangman ¶
CreateHangman creates a new game instance and stores it.
func JoinHangman ¶
JoinHangman loads an existing game instance.
func PlayLetter ¶
PlayLetter submits a letter guess to a specified game
type HangmanResults ¶
type HangmanResults []*HangmanResult
HangmanResults is a slice of HangmanResult
func ListHangman ¶
func ListHangman(stg store.Store) (HangmanResults, error)
ListHangman returns details of all current games of hangman in the store
type State ¶
type State int
State is an enum representing the state of a game.
func (*State) MarshalJSON ¶
MarshalJSON marshals an instance of State enum into JSON.
func (*State) UnmarshalJSON ¶
UnmarshalJSON unmarshals JSON into an instance of the State enum.