game

package
v0.0.0-...-2379a7f Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Disconnect requests that the Client disconnects unblocking any current
	// reads and writes. Disconnect should not block. After the first call,
	// Disconnect is a no-op.
	Disconnect()
	// DisconnectCh returns a channel that is closed when the Client
	// is disconnected.
	DisconnectCh() <-chan struct{}
	// WritePlayerEvent writes a PlayerEvent to the Client. Blocks until the
	// event has been sucessfully written, an error occurs, or the context is
	// canceled.
	WritePlayerEvent(ctx context.Context, evt model.PlayerEvent) error
	// ReadPlayerAction reads a PlayerAction from the Client.
	ReadPlayerAction(ctx context.Context) (model.PlayerAction, error)
}

A Client represents a (remote) player connection that can be written to and read from.

type Coordinator

type Coordinator struct {
	// contains filtered or unexported fields
}

The Coordinator is responsible for connecting players to a game. Once enough players has been found so that a game can be created, the game coordinator creates and starts a new game with the given players.

The lifetime of the game coordinator is not tied to a single game but rather the entire lifetime of the game server.

func NewCoordinator

func NewCoordinator(log *logrus.Logger) (*Coordinator, error)

NewCoordinator creates a new Coordinator, using the given logger.

func (*Coordinator) AddClient

func (c *Coordinator) AddClient(ctx context.Context, client Client) error

AddClient takes a Client and adds it to the coordinator. This method blocks until the Client can be added, or the context is cancelled.

func (*Coordinator) Run

func (c *Coordinator) Run(ctx context.Context) error

Run starts and runs the Coordinator. This method blocks until the context is cancelled or an error occurs, and always returns a non-nil error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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