server

package
v0.0.0-...-6b51b5a Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2017 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateGameReq

type CreateGameReq struct {
	Cols     int
	Rows     int
	NPlayers int
	NWin     int
}

CreateGameReq is the request to create a new game.

type JoinGameReq

type JoinGameReq struct {
	GameID     string
	PlayerName string
}

JoinGameReq is the request to join a game.

type ListGameResp

type ListGameResp struct {
	GameID         string                  `json:"game_id"`
	PlayerCount    int                     `json:"player_count"`
	MaxPlayerCount int                     `json:"max_player_count"`
	GameState      string                  `json:"game_state"`
	Players        map[engine.State]string `json:"players"`
}

ListGameResp is the response

type PlayMoveReq

type PlayMoveReq struct {
	GameID     string
	PlayerName string
	Column     int
}

PlayMoveReq is the request to play a move in a game.

type Runtime

type Runtime struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Runtime is a HTTP server for Connect Four.

func (*Runtime) AttachGame

func (r *Runtime) AttachGame(w http.ResponseWriter, req *http.Request) error

AttachGame is the http endpoint to attach to a game. This endpoint will send one message each time the game changes state until the game is finished.

Method: GET Query String: - game_id: string, game uuid to attach to. Response: - JSON object of engine.Four. One entry per state change.

func (*Runtime) Close

func (r *Runtime) Close() error

Close .

func (*Runtime) CreateGame

func (r *Runtime) CreateGame(w http.ResponseWriter, req *http.Request) error

CreateGame is the http endpoint handling the game creation.

Method: GET Query String: - cols: int, columns count of the grid. - rows: int, rows count of the grid. - nplayers: int, number of players allowed in the game. - nwin: int, number of consecutive field to win. Response: - json formatted UUID of the new game.

func (*Runtime) Init

func (r *Runtime) Init(four *engine.Four) error

Init setup the connect four game. Note: In server mode, we discard the init's given engine.

func (*Runtime) JoinGame

func (r *Runtime) JoinGame(w http.ResponseWriter, req *http.Request) error

JoinGame is the http endpoint to join a game.

Method: GET Query String: - game_id: string, uuid of the game to join. - player_name: string, arbitrary player name.

func (*Runtime) ListGames

func (r *Runtime) ListGames(w http.ResponseWriter, req *http.Request) error

ListGames is the http endpoint returning the list of games.

Method: GET Response: - JSON array of ListGameResp.

func (*Runtime) PlayMove

func (r *Runtime) PlayMove(w http.ResponseWriter, req *http.Request) error

PlayMove is the http endpoint to submit a move.

Method: GET Query String: - game_id: string, uuid of the target game. - player_name: string, name of the player, must have joined the game. - col: int, 0 indexed column number to play.

func (*Runtime) Run

func (r *Runtime) Run() error

Run is the main loop. TODO: Use flags to config the listen address.

Jump to

Keyboard shortcuts

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