game

package
v0.0.0-...-07f0968 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Eps = []*app.Endpoint{
		{
			Description:  "Get your active game info",
			Path:         (&Active{}).Path(),
			Timeout:      500,
			MaxBodyBytes: app.KB,
			IsPrivate:    false,
			GetDefaultArgs: func() interface{} {
				return nil
			},
			GetExampleArgs: func() interface{} {
				return nil
			},
			GetExampleResponse: func() interface{} {
				return &ActiveInfo{
					Type: "a_game_type",
					ID:   app.ExampleID(),
				}
			},
			Handler: func(tlbx app.Tlbx, _ interface{}) interface{} {
				g, gameType := getUsersActiveGame(tlbx, nil, false, "", &Base{})
				if g == nil {
					return nil
				}
				return &ActiveInfo{
					Type: gameType,
					ID:   g.GetBase().ID,
				}
			},
		},
	}
)

Functions

func Abandon

func Abandon(tlbx app.Tlbx, gameType string, dst Game)

func DeleteOutdated

func DeleteOutdated(exec func(query string, args ...interface{}), delay time.Duration, expire time.Duration)

func New

func New(tlbx app.Tlbx, gameType string, game Game)

Types

type Active

type Active struct{}

func (*Active) Do

func (a *Active) Do(c *app.Client) (*ActiveInfo, error)

func (*Active) MustDo

func (a *Active) MustDo(c *app.Client) *ActiveInfo

func (*Active) Path

func (_ *Active) Path() string

type ActiveInfo

type ActiveInfo struct {
	Type string `json:"type"`
	ID   ID     `json:"id"`
}

type Base

type Base struct {
	ID        ID        `json:"id"`
	UpdatedOn time.Time `json:"updatedOn"`
	State     uint8     `json:"state"` // 0 not started, 1 started, 2 finished, 3 abandoned
	MyID      *ID       `json:"myId,omitempty"`
	Players   IDs       `json:"players"`
	Turn      uint32    `json:"turn"`
}

func (*Base) Abandoned

func (b *Base) Abandoned() bool

func (*Base) Finished

func (b *Base) Finished() bool

func (*Base) GetBase

func (b *Base) GetBase() *Base

func (*Base) IsActive

func (b *Base) IsActive() bool

func (*Base) IsMyTurn

func (b *Base) IsMyTurn() bool

func (*Base) NotStarted

func (b *Base) NotStarted() bool

func (*Base) Started

func (b *Base) Started() bool

type Game

type Game interface {
	GetBase() *Base
	IsMyTurn() bool
}

func Get

func Get(tlbx app.Tlbx, gameType string, game ID, updatedAfter *time.Time, dst Game) Game

func Join

func Join(tlbx app.Tlbx, maxPlayers uint8, gameType string, game ID, dst Game) Game

func Start

func Start(tlbx app.Tlbx, minPlayers uint8, randomizePlayerOrder bool, gameType string, dst Game, customSetup func(game Game)) Game

func TakeTurn

func TakeTurn(tlbx app.Tlbx, gameType string, dst Game, takeTurn func(game Game)) Game

Jump to

Keyboard shortcuts

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