game

package
v0.0.0-...-7a9ebb2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2022 License: GPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MixManager

func MixManager(ctx context.Context, m *Manager) context.Context

MixManager mix manager into ctx and return the child ctx

Types

type Game

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

func NewGame

func NewGame(createdBy string) *Game

func (*Game) AddPlayer

func (g *Game) AddPlayer(p *player.Player) error

func (*Game) ApplyAction

func (g *Game) ApplyAction() error

func (*Game) Dump

func (g *Game) Dump(addition ...string) *GameJSON

Dump game to GameJSON

normally, the "password" were filter out from ret-val include it in addition to add it into ret-val

func (*Game) GetMaxPlayers

func (g *Game) GetMaxPlayers() uint32

func (*Game) ID

func (g *Game) ID() string

func (*Game) IsPrivate

func (g *Game) IsPrivate() bool

func (*Game) ListPlayers

func (g *Game) ListPlayers() []*player.Player

func (*Game) Load

func (g *Game) Load(src *GameJSON) error

Load settings from `src`

func (*Game) Owner

func (g *Game) Owner() string

func (*Game) Password

func (g *Game) Password() string

func (*Game) RemovePlayer

func (g *Game) RemovePlayer(p *player.Player)

func (*Game) SetMaxPlayers

func (g *Game) SetMaxPlayers(max *uint32) error

SetMaxPlayers when max==nil, 12 is used when max not in (6,12], error returned

func (*Game) Start

func (g *Game) Start() error

func (*Game) Status

func (g *Game) Status() Status

type GameJSON

type GameJSON struct {
	// meta data
	ID        string `json:"ID,omitempty"`
	CreatedAt uint64 `json:"created_at,omitempty"`
	Owner     string `json:"owner,omitempty"`

	// settings
	MaxPlayers *uint32 `json:"max_players,omitempty"`
	IsPrivate  bool    `json:"is_private,omitempty"`
	Password   string  `json:"password,omitempty"`

	// contained data
	Players []*player.PlayerJSON `json:"players,omitempty"`
}

GameJSON represents the JSON format of a game, used to communicate

type Manager

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

func NewManager

func NewManager() *Manager

func PickManager

func PickManager(ctx context.Context) *Manager

PickManager pick manager from ctx

func (*Manager) Delete

func (m *Manager) Delete(id string)

func (*Manager) List

func (m *Manager) List() []*Game

func (*Manager) Load

func (m *Manager) Load(id string) (*Game, bool)

func (*Manager) LoadOrStore

func (m *Manager) LoadOrStore(game *Game) (actual *Game, loaded bool)

func (*Manager) Store

func (m *Manager) Store(game *Game)

type Status

type Status int
const (
	WAITING Status = iota
	STARTED
	ENDED
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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