game

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Rendered for js/wasm

Overview

Package game has the ui game logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Canvas added in v1.2.0

type Canvas interface {
	StartSwap()
	Redraw()
	SetGameStatus(s game.Status)
	TileLength() int
	SetTileLength(tileLength int)
	ParentDivOffsetWidth() int
	DesiredWidth() int
	UpdateSize(width int)
	NumRows() int
	NumCols() int
}

Canvas is the element the game is drawn on

type CanvasCreator added in v1.2.0

type CanvasCreator interface {
	Create(board *board.Board, canvasParentDivQuery string) Canvas
}

CanvasCreator creates canvases to draw other player's final boards.

type DOM added in v1.2.0

type DOM interface {
	QuerySelector(query string) js.Value
	QuerySelectorAll(document js.Value, query string) []js.Value
	Checked(query string) bool
	SetChecked(query string, checked bool)
	Value(query string) string
	SetValue(query, value string)
	SetButtonDisabled(query string, disabled bool)
	CloneElement(query string) js.Value
	Confirm(message string) bool
	Color(element js.Value) string
	RegisterFuncs(ctx context.Context, wg *sync.WaitGroup, parentName string, jsFuncs map[string]js.Func)
	NewJsFunc(fn func()) js.Func
	NewJsEventFunc(fn func(event js.Value)) js.Func
	ReleaseJsFuncsOnDone(ctx context.Context, wg *sync.WaitGroup, jsFuncs map[string]js.Func)
}

DOM interacts with the page.

type Game

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

Game handles managing the state of the board and drawing it on the canvas.

func New added in v1.2.0

func New(dom DOM, log Log, board *board.Board, canvas Canvas, createCanvas CanvasCreator) *Game

New creates a new game controller with references to the board and canvas.

func (Game) ID

func (g Game) ID() game.ID

ID gets the ID of the game.

func (*Game) InitDom

func (g *Game) InitDom(ctx context.Context, wg *sync.WaitGroup)

InitDom registers game dom functions.

func (*Game) Leave

func (g *Game) Leave()

Leave changes the view for game by hiding it.

func (*Game) Start

func (g *Game) Start()

Start triggers the game to start for everyone.

func (*Game) UpdateInfo

func (g *Game) UpdateInfo(m message.Message)

UpdateInfo updates the game for the specified message.

type Log added in v1.2.0

type Log interface {
	Error(text string)
	Info(text string)
}

Log is notify users about changes to the game.

type Socket

type Socket interface {
	Send(m message.Message)
}

Socket sends messages to the server.

Directories

Path Synopsis
Package canvas contains the logic to draw the game.
Package canvas contains the logic to draw the game.
Package lobby contains code to view available games and to close the websocket.
Package lobby contains code to view available games and to close the websocket.
Package socket contains the logic to communicate with the server for the game via websocket communication
Package socket contains the logic to communicate with the server for the game via websocket communication

Jump to

Keyboard shortcuts

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