gamesrv

package
v0.0.0-...-4c6e0a9 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 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 ApiGameServer

type ApiGameServer struct {
	GameService GameService
	Router      chi.Router
}

ApiGameServer is a HTTP server that exposes the game service

func NewApiGameServer

func NewApiGameServer(evbus EventBus.Bus) ApiGameServer

NewApiGameServer creates a new HTTP server that exposes the game service

func (*ApiGameServer) CreateGame

func (app *ApiGameServer) CreateGame(w http.ResponseWriter, r *http.Request)

CreateGame creates a new game

func (*ApiGameServer) GetGame

func (app *ApiGameServer) GetGame(w http.ResponseWriter, r *http.Request)

GetGame returns the current position of the game

func (*ApiGameServer) MakeMove

func (app *ApiGameServer) MakeMove(w http.ResponseWriter, r *http.Request)

MakeMove makes a move in the game

type Game

type Game struct {
	ID          string
	Position    string
	PlayerWhite string
	PlayerBlack string
	State       string
}

Game represents a chess game.

func NewGame

func NewGame(playerWhite string, playerBlack string) Game

NewGame creates a new game.

func (*Game) MakeMove

func (g *Game) MakeMove(move string) error

MakeMove makes a move in the game.

type GameRepo

type GameRepo interface {
	Add(Game) error
	Get(string) (Game, error)
	Remove(string) error
	Update(Game) error
}

GameRepo is an interface for a game repository.

func NewGameRepo

func NewGameRepo() GameRepo

NewGameRepo returns a new GameRepoStorage

type GameRepoStorage

type GameRepoStorage struct {
	Storage map[string]Game
}

func (GameRepoStorage) Add

func (grs GameRepoStorage) Add(g Game) error

Add adds a game to the repository.

func (GameRepoStorage) Get

func (grs GameRepoStorage) Get(id string) (Game, error)

Get returns a game from the repository.

func (GameRepoStorage) Remove

func (grs GameRepoStorage) Remove(id string) error

Remove removes a game from the repository.

func (GameRepoStorage) Update

func (grs GameRepoStorage) Update(g Game) error

Update updates a game in the repository.

type GameResponse

type GameResponse struct {
	ID          string `json:"id"`
	Position    string `json:"position"`
	State       string `json:"state"`
	PlayerWhite string `json:"playerWhite"`
	PlayerBlack string `json:"playerBlack"`
}

type GameService

type GameService struct {
	GameRepo GameRepo
	EventBus EventBus.Bus
}

GameService is a service for managing games.

func NewGameService

func NewGameService(gameRepo GameRepo, evbus EventBus.Bus) GameService

NewGameService creates a new GameService.

func (GameService) CreateGame

func (gs GameService) CreateGame(playerWhite string, playerBlack string) (Game, error)

CreateGame creates a new game.

func (GameService) GetGame

func (gs GameService) GetGame(id string) (Game, error)

GetGame gets a game.

func (GameService) MakeMove

func (gs GameService) MakeMove(id string, move string) (Game, error)

MakeMove makes a move in a game.

type MoveRequest

type MoveRequest struct {
	Move string `json:"move"`
}

type MoveResponse

type MoveResponse struct {
	Position string `json:"position"`
	State    string `json:"state"`
}

type StartGameResponse

type StartGameResponse struct {
	ID       string `json:"id"`
	Position string `json:"position"`
}

Jump to

Keyboard shortcuts

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