game

package
v0.0.0-...-63692ed Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Won indicates the game ended with a win
	Won = iota
	// Lost indicates the game ended with a loss
	Lost
	// Good indicates a correct guess
	Good
	// Bad indicates a bad guess
	Bad
	// Guessed indicates a letter was already guessed
	Guessed
	// Started indicates the game begun
	Started
)

Variables

This section is empty.

Functions

func DecodeGuessRequest

func DecodeGuessRequest(_ context.Context, r *http.Request) (interface{}, error)

DecodeGuessRequest extracts guess and game state from requests

func MakeHandler

func MakeHandler(s Service, l kitlog.Logger) http.Handler

MakeHandler to serve game routes

Types

type Game

type Game struct {
	Letters   string `json:"letters"`
	Status    Status `json:"status"`
	TurnsLeft int    `json:"turnsLeft"`
	Guesses   []rune `json:"guesses"`
}

Game records state for hangman

func NewGame

func NewGame(word string) *Game

NewGame starts a hangman game

func (*Game) AlreadyGuessed

func (g *Game) AlreadyGuessed(l rune) bool

AlreadyGuessed checks if the given letter has been guessed

func (*Game) Guess

func (g *Game) Guess(l rune) *Game

Guess a letter in the selected word

type GuessRequest

type GuessRequest struct {
	Game  Game   `json:"game"`
	Guess string `json:"guess"`
}

GuessRequest proposes a new guess

type Guesser

type Guesser interface {
	Guess(rune) *Game
}

Guesser protocol to guess a letter for hangman

type NewGameRequest

type NewGameRequest struct {
	Word    string         `json:"word"`
	Cookies []*http.Cookie `json:"cookies"`
}

NewGameRequest requests a new game given a word

type Response

type Response struct {
	Game Game `json:"game"`
}

Response replies with the current game

type Service

type Service interface {
	NewGame(string) Game
	Guess(Game, rune) Game
}

Service represents the game service

func NewLoggingService

func NewLoggingService(s Service, l log.Logger) Service

NewLoggingService returns a new instance to the logging service

func NewService

func NewService() Service

NewService creates a game service

type Status

type Status int

Status of game

Jump to

Keyboard shortcuts

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