Skip to main content

Class: Game<G, P>

Base class for the game. Represents the current state of the game and contains all game elements (spaces and pieces). All games contain a single Game class that inherits from this class and on which custom properties and methods for a specific game can be added.

Type parameters

NameType
Gextends BaseGame = BaseGame
Pextends BasePlayer = BasePlayer

Hierarchy

Adjacency

isAdjacentTo

isAdjacentTo(element): boolean

If this element is adjacent to some other element, using the nearest containing space that has an adjacency map.

Parameters

NameType
elementGameElement<BaseGame, BasePlayer>

Returns

boolean

Inherited from

Space.isAdjacentTo

Defined in

boardzilla-core/src/board/element.ts:514


distanceTo

distanceTo(element): number

Finds the shortest distance between two spaces

Parameters

NameTypeDescription
elementGameElement<BaseGame, BasePlayer>element to measure distance to

Returns

number

Inherited from

Space.distanceTo

Defined in

boardzilla-core/src/board/element.ts:526


adjacencies

adjacencies<F>(className, ...finders): ElementCollection<F>

Find all elements adjacent based on row/column placement or based on this element having connections created by Space#connectTo. Uses the same parameters as GameElement#all

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameType
classNameElementClass<F>
...findersElementFinder<F>[]

Returns

ElementCollection<F>

Inherited from

Space.adjacencies

Defined in

boardzilla-core/src/board/element.ts:538


withinDistance

withinDistance<F>(distance, className, ...finders): ElementCollection<F>

Finds all spaces connected to this space by a distance no more than distance

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameType
distancenumber
classNameElementClass<F>
...findersElementFinder<F>[]

Returns

ElementCollection<F>

Inherited from

Space.withinDistance

Defined in

boardzilla-core/src/board/element.ts:552


setShape

setShape(...shape): void

Set an irregular shape for this element. This is only meaningful for the purposes of finding specifically adjacent cells when placed into a PieceGrid. See PieceGrid#adjacenciesByCell. When rendered in a PieceGrid, the element will have a size large enough to fill the appropriate number of spaces in the grid, but it's appearance is otherwise unaffected and will be based on appearance. When not rendered in a PieceGrid, the element will take up a single cell but will be scaled relatively to other elements with a shape in the same layout.

Parameters

NameTypeDescription
...shapestring[]A set of single characters used as labels for each cell. The cell label characters are provided as an array of strings, with each string being one row of cell labels, with spaces used to indicate empty "holes" in the shape. Each row must be the same length. The specific non-space characters used are used for labelling the adjacencies in PieceGrid#adjacenciesByCell but are otherwise unimportant.

Returns

void

Example

domino12.setShape(
'12'
);

tetrisPiece.setShape(
'XX ',
' XX'
);

Inherited from

Space.setShape

Defined in

boardzilla-core/src/board/element.ts:876


setEdges

setEdges(edges): void

Set the edge labels for this element. These are only meaningful for the purposes of finding specifically adjacent edges when placed into a PieceGrid. See PieceGrid#adjacenciesByEdge.

Parameters

NameTypeDescription
edgesPartial<Record<Direction, string>> | Record<string, Partial<Record<Direction, string>>>A set of edge labels for each cell label provided by setShape. For simple 1-celled shapes, the edges can be provided without cell labels.

Returns

void

Example

// a bridge tile with a road leading from left to right and a river leading
// from top to bottom.
simpleTile.setEdge(
up: 'river',
down: 'river',
left: 'road'
right: 'road'
});

// A tetris-shaped tile with sockets coming out either "end"
tetrisPiece.setShape(
'AX ',
' XB'
);
tetrisPiece.setEdge({
A: {
left: 'socket'
},
B: {
right: 'socket'
}
});

Inherited from

Space.setEdges

Defined in

boardzilla-core/src/board/element.ts:921

Definition

players

players: PlayerCollection<P>

The players in this game. See Player

Defined in

boardzilla-core/src/board/game.ts:138


random

random: () => number

Use instead of Math.random to ensure random number seed is consistent when replaying from history.

Type declaration

▸ (): number

Use instead of Math.random to ensure random number seed is consistent when replaying from history.

Returns

number

Defined in

boardzilla-core/src/board/game.ts:147


defineFlow

defineFlow(...flow): void

Define your game's main flow. May contain any of the following:

Parameters

NameType
...flowFlowStep[]

Returns

void

Defined in

boardzilla-core/src/board/game.ts:178


defineActions

defineActions(actions): void

Define your game's actions.

Parameters

NameTypeDescription
actionsRecord<string, (player: P) => Action<Record<string, Argument>>>An object consisting of actions where the key is the name of the action and value is a function that accepts a player taking the action and returns the result of calling action and chaining choices, results and messages onto the result

Returns

void

Defined in

boardzilla-core/src/board/game.ts:204


setting

setting(key): any

Retrieve the selected setting value for a setting defined in render.

Parameters

NameType
keystring

Returns

any

Defined in

boardzilla-core/src/board/game.ts:214


action

action<A>(definition?): Action<A>

Create an Action. An action is a single move that a player can take. Some actions require choices, sometimes several, before they can be executed. Some don't have any choices, like if a player can simply 'pass'. What defines where one action ends and another begins is how much you as a player can decide before you "commit". For example, in chess you select a piece to move and then a place to put it. These are a single move, not separate. (Unless playing touch-move, which is rarely done in digital chess.) In hearts, you pass 3 cards to another players. These are a single move, not 3. You can change your mind as you select the cards, rather than have to commit to each one. Similarly, other players do not see any information about your choices until you actually commit the entire move.

This function is called for each action in the game actions you define in defineActions. These actions are initially declared with an optional prompt and condition. Further information is added to the action by chaining methods that add choices and behaviour. See Action.

If this action accepts prior arguments besides the ones chosen by the player during the execution of this action (especially common for followUp actions) then a generic can be added for these arguments to help Typescript type these parameters, e.g.: player => action<{ cards: number}>(...)

Type parameters

NameType
Aextends Record<string, Argument> = {}

Parameters

NameTypeDescription
definitionObject-
definition.prompt?stringThe prompt that will appear for the player to explain what the action does. Further prompts can be defined for each choice they subsequently make to complete the action.
definition.description?string-
definition.condition?boolean | (args: A) => booleanA boolean or a function returning a boolean that determines whether the action is currently allowed. Note that the choices you define for your action will further determine if the action is allowed. E.g. if you have a play card action and you add a choice for cards in your hand, Boardzilla will automatically disallow this action if there are no cards in your hand based on the face that there are no valid choices to complete the action. You do not need to specify a condition for these types of limitations. If using the function form, the function will receive an object with any arguments passed to this action, e.g. from followUp.

Returns

Action<A>

Example

action({
prompt: 'Flip one of your cards'
}).chooseOnBoard({
choices: game.all(Card, {mine: true})
}).do(
card => card.hideFromAll()
)

Defined in

boardzilla-core/src/board/game.ts:268


flowCommands

flowCommands: Object

The flow commands available for this game. See:

Type declaration

NameType
playerActions(options: { name?: string ; players?: Player<BaseGame, BasePlayer>[] | (args: Record<string, any>) => Player<BaseGame, BasePlayer>[] ; player?: Player<BaseGame, BasePlayer> | (args: Record<string, any>) => Player<BaseGame, BasePlayer> ; actions: (string | { name: string ; prompt?: string | (args: Record<string, any>) => string ; args?: Record<string, Argument> | (args: Record<string, any>) => Record<string, Argument> ; do?: FlowDefinition })[] ; prompt?: string | (args: Record<string, any>) => string ; condition?: (args: Record<string, any>) => boolean ; continueIfImpossible?: boolean ; repeatUntil?: string | (args: Record<string, any>) => string ; description?: string ; optional?: string | (args: Record<string, any>) => string ; skipIf?: "always" | "never" | "only-one" }) => default
loop(...block: FlowStep[]) => default
whileLoop(options: { while: (a: FlowArguments) => boolean ; do: FlowDefinition }) => default
forEach<T>(options: { name: string ; collection: T[] | (a: FlowArguments) => T[] ; do: FlowDefinition }) => default<T>
forLoop<T>(options: { name: string ; initial: T | (a: FlowArguments) => T ; next: (a: T) => T ; while: (a: T) => boolean ; do: FlowDefinition }) => default<T>
eachPlayer(options: { name: string ; startingPlayer?: P | (a: FlowArguments) => P ; nextPlayer?: (p: P) => P ; turns?: number ; continueUntil?: (p: P) => boolean ; do: FlowDefinition }) => default<P>
everyPlayer(options: { players?: P[] ; do: FlowDefinition ; name?: string }) => default<P>
ifElse(options: { name?: string ; if: (r: Record<any, any>) => boolean ; do: FlowDefinition ; else?: FlowDefinition }) => default
switchCase<T>(options: { name?: string ; switch: T | (a: FlowArguments) => T ; cases: SwitchCaseCases<T> ; default?: FlowDefinition }) => default<T>

Defined in

boardzilla-core/src/board/game.ts:327

Game Management

followUp

followUp(action): void

Queue up a follow-up action while processing an action. If called during the processing of a game action, the follow-up action given will be added as a new action immediately following the current one, before the game's flow can resume normally. This is common for card games where the play of a certain card may require more actions be taken.

Parameters

NameTypeDescription
actionActionStubThe action added to the follow-up queue.

Returns

void

Example

defineAction({
...
playCard: player => action()
.chooseOnBoard('card', cards)
.do(
({ card }) => {
if (card.damage) {
// this card allows another action to do damage to another Card
game.followUp({
name: 'doDamage',
args: { amount: card.damage }
});
}
}
)

Defined in

boardzilla-core/src/board/game.ts:303


finish

finish(winner?, announcement?): void

End the game

Parameters

NameTypeDescription
winner?P | P[]a player or players that are the winners of the game. In a solo game if no winner is provided, this is considered a loss.
announcement?stringan optional announcement from render to replace the standard boardzilla announcement.

Returns

void

Defined in

boardzilla-core/src/board/game.ts:348


getWinners

getWinners(): undefined | BasePlayer[]

Return array of game winners, or undefined if game is not yet finished

Returns

undefined | BasePlayer[]

Defined in

boardzilla-core/src/board/game.ts:358


addDelay

addDelay(): void

Add a delay in the animation of the state change at this point for player as they receive game updates.

Returns

void

Defined in

boardzilla-core/src/board/game.ts:369


message

message(text, args?): void

Add a message that will be broadcast in the chat at the next game update, based on the current state of the game.

Parameters

NameTypeDescription
textstringThe text of the message to send. This can contain interpolated strings with double braces, i.e. {{player}} that are defined in args. Of course, strings can be interpolated normally using template literals. However game objects (e.g. players or pieces) passed in as args will be displayed specially by Boardzilla.
args?Record<string, Argument>An object of key-value pairs of strings for interpolation in the message.

Returns

void

Example

game.message(
'{{player}} has a score of {{score}}',
{ player, score: player.score() }
);

Defined in

boardzilla-core/src/board/game.ts:402


messageTo

messageTo(player, text, args?): void

Add a message that will be broadcast to the given player(s) in the chat at the next game update, based on the current state of the game.

Parameters

NameTypeDescription
playernumber | BasePlayer | (number | BasePlayer)[]Player or players to receive the message
textstringThe text of the message to send. This can contain interpolated strings with double braces, i.e. {{player}} that are defined in args. Of course, strings can be interpolated normally using template literals. However game objects (e.g. players or pieces) passed in as args will be displayed specially by Boardzilla.
args?Record<string, Argument>An object of key-value pairs of strings for interpolation in the message.

Returns

void

Example

game.message(
'{{player}} has a score of {{score}}',
{ player, score: player.score() }
);

Defined in

boardzilla-core/src/board/game.ts:429


announce

announce(announcement): void

Broadcast a message to all players that interrupts the game and requires dismissal before actions can be taken.

Parameters

NameTypeDescription
announcementstringThe modal name to announce, as provided in render.

Returns

void

Example

game.message(
'{{player}} has a score of {{score}}',
{ player, score: player.score() }
);

Defined in

boardzilla-core/src/board/game.ts:453

Other

layoutAsDrawer

layoutAsDrawer(applyTo, attributes): void

Creates a collapsible drawer layout for a Space within this Element. This is like GameElement#layout except for one specific Space, with additional parameters that set the behaviour/appearance of the drawer. A tab will be attached the drawer that will allow it be opened/closed.

Parameters

NameTypeDescription
applyTostring | Space<G, P>The Space for the drawer. Either the Space itself or its name.
attributesObject-
attributes.area?Box-
attributes.openDirection"left" | "right" | "up" | "down"-
attributes.tab?ReactNode-
attributes.closedTab?ReactNode-
attributes.openIf?(actions: { name: string ; args: Record<string, Argument> }[]) => boolean-
attributes.closeIf?(actions: { name: string ; args: Record<string, Argument> }[]) => boolean-

Returns

void

Inherited from

Space.layoutAsDrawer

Defined in

boardzilla-core/src/board/element.ts:1131


layoutAsTabs

layoutAsTabs(tabs, attributes): void

Creates a tabbed layout for a set of Space's within this Element. This is like GameElement#layout except for a set of Spaces, with additional parameters that set the behaviour/appearance of the tabs. Each Space will be laid out into the same area, with a set of tabs attached to allow the Player or the game rules to select which tab is shown.

Parameters

NameTypeDescription
tabsRecord<string, string | Space<G, P>>JSX for the appearance of the tabs as a set of key-value pairs
attributesObject-
attributes.area?Box-
attributes.tabDirection"left" | "right" | "up" | "down"-
attributes.tabs?Record<string, ReactNode>-
attributes.setTabTo?(actions: { name: string ; args: Record<string, Argument> }[]) => string-

Returns

void

Inherited from

Space.layoutAsTabs

Defined in

boardzilla-core/src/board/element.ts:1159


layoutAsPopout

layoutAsPopout(applyTo, attributes): void

Hides a Space within this element and replaces it with popout button. Clicking on the button opens this Space in a full-board modal. This is like GameElement#layout except for one Space, with additional parameters that set the behaviour/appearance of the popout modal.

Parameters

NameTypeDescription
applyTostring | Space<G, P>The Space for the popout. Either a Space or the name of a Space.
attributesObject-
attributes.area?Box-
attributes.buttonReactNode-
attributes.popoutMargin?number | { top: number ; bottom: number ; left: number ; right: number }-

Returns

void

Inherited from

Space.layoutAsPopout

Defined in

boardzilla-core/src/board/element.ts:1187


defineSubflow

defineSubflow(name, ...flow): void

Define an addtional flow that the main flow can enter. A subflow has a unique name and can be entered at any point by calling Do|Do.subflow.

Parameters

NameTypeDescription
namestringUnique name of flow
...flowFlowStep[]Steps of the flow

Returns

void

Defined in

boardzilla-core/src/board/game.ts:190

Queries

name

name: string

Element name, used to distinguish elements. Elements with the same name are generally considered indistibuishable. Names are also used for easy searching of elements.

Inherited from

Space.name

Defined in

boardzilla-core/src/board/element.ts:241


all

all<F>(className, ...finders): ElementCollection<F>

Finds all elements within this element recursively that match the arguments provided.

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameTypeDescription
classNameElementClass<F>Optionally provide a class as the first argument as a class filter. This will only match elements which are instances of the provided class
...findersElementFinder<F>[]All other parameters are filters. See ElementFinder for more information.

Returns

ElementCollection<F>

An ElementCollection of as many matching elements as can be found. The collection is typed to ElementCollection<className> if one was provided.

Inherited from

Space.all

Defined in

boardzilla-core/src/board/element.ts:379


first

first<F>(className, ...finders): undefined | F

Finds the first element within this element recursively that matches the arguments provided. See all for parameter details.

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameType
classNameElementClass<F>
...findersElementFinder<F>[]

Returns

undefined | F

A matching element, if found

Inherited from

Space.first

Defined in

boardzilla-core/src/board/element.ts:391


firstN

firstN<F>(n, className, ...finders): ElementCollection<F>

Finds the first n elements within this element recursively that match the arguments provided. See all for parameter details.

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameTypeDescription
nnumbernumber of matches
classNameElementClass<F>-
...findersElementFinder<F>[]-

Returns

ElementCollection<F>

An ElementCollection of as many matching elements as can be found, up to n. The collection is typed to ElementCollection<className> if one was provided.

Inherited from

Space.firstN

Defined in

boardzilla-core/src/board/element.ts:407


last

last<F>(className, ...finders): undefined | F

Finds the last element within this element recursively that matches the arguments provided. See all for parameter details.

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameType
classNameElementClass<F>
...findersElementFinder<F>[]

Returns

undefined | F

A matching element, if found

Inherited from

Space.last

Defined in

boardzilla-core/src/board/element.ts:419


lastN

lastN<F>(n, className, ...finders): ElementCollection<F>

Finds the last n elements within this element recursively that match the arguments provided. See all for parameter details.

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameTypeDescription
nnumbernumber of matches
classNameElementClass<F>-
...findersElementFinder<F>[]-

Returns

ElementCollection<F>

An ElementCollection of as many matching elements as can be found, up to n. The collection is typed to ElementCollection<className> if one was provided.

Inherited from

Space.lastN

Defined in

boardzilla-core/src/board/element.ts:435


top

top<F>(className, ...finders): undefined | F

Alias for first

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameType
classNameElementClass<F>
...findersElementFinder<F>[]

Returns

undefined | F

Inherited from

Space.top

Defined in

boardzilla-core/src/board/element.ts:446


topN

topN<F>(n, className, ...finders): ElementCollection<F>

Alias for firstN

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameType
nnumber
classNameElementClass<F>
...findersElementFinder<F>[]

Returns

ElementCollection<F>

Inherited from

Space.topN

Defined in

boardzilla-core/src/board/element.ts:456


bottom

bottom<F>(className, ...finders): undefined | F

Alias for last

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameType
classNameElementClass<F>
...findersElementFinder<F>[]

Returns

undefined | F

Inherited from

Space.bottom

Defined in

boardzilla-core/src/board/element.ts:466


bottomN

bottomN<F>(n, className, ...finders): ElementCollection<F>

Alias for lastN

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameType
nnumber
classNameElementClass<F>
...findersElementFinder<F>[]

Returns

ElementCollection<F>

Inherited from

Space.bottomN

Defined in

boardzilla-core/src/board/element.ts:476


others

others<F>(className, ...finders): ElementCollection<F>

Finds "sibling" elements (elements that are directly inside the parent of this element) that match the arguments provided. See all for parameter details.

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameType
classNameElementClass<F>
...findersElementFinder<F>[]

Returns

ElementCollection<F>

Inherited from

Space.others

Defined in

boardzilla-core/src/board/element.ts:487


has

has<F>(className, ...finders): boolean

Return whether any element within this element recursively matches the arguments provided. See all for parameter details.

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameType
classNameElementClass<F>
...findersElementFinder<F>[]

Returns

boolean

Inherited from

Space.has

Defined in

boardzilla-core/src/board/element.ts:499


container

container<T>(className?): undefined | T

Returns this elements parent.

Type parameters

NameType
Textends GameElement<BaseGame, BasePlayer>

Parameters

NameTypeDescription
className?ElementClass<T>If provided, searches up the parent tree to find the first matching element. E.g. if a Token is placed on a Card in a players Tableau. calling token.container(Tableau) can be used to find the grandparent.

Returns

undefined | T

Inherited from

Space.container

Defined in

boardzilla-core/src/board/element.ts:585


containerWithProperty

containerWithProperty(property, value?): undefined | GameElement<BaseGame, BasePlayer>

Returns this elements containing element that also has a given property.

Parameters

NameType
propertystring
value?any

Returns

undefined | GameElement<BaseGame, BasePlayer>

Inherited from

Space.containerWithProperty

Defined in

boardzilla-core/src/board/element.ts:596


mine

get mine(): boolean

Whether this element belongs to the player viewing the game. A player is considered to be currently viewing the game if this is called in the context of an action taken by a given player (during an action taken by a player or while the game is viewed by a given player.) It is an error to call this method when not in the context of a player action. When querying for elements using ElementFinder such as all and first, mine is available as a search key that accepts a value of true/false

Returns

boolean

Inherited from

Space.mine

Defined in

boardzilla-core/src/board/element.ts:653

Structure

row

Optional row: number

Row of element within its layout grid if specified directly or by a "sticky" layout.

Inherited from

Space.row

Defined in

boardzilla-core/src/board/element.ts:257


column

Optional column: number

Column of element within its layout grid if specified directly or by a "sticky" layout.

Inherited from

Space.column

Defined in

boardzilla-core/src/board/element.ts:264


game

game: G

The Game to which this element belongs

Inherited from

Space.game

Defined in

boardzilla-core/src/board/element.ts:272


toString

toString(): string

String used for representng this element in game messages when the object is passed directly, e.g. when taking the choice directly from a chooseOnBoard choice.

Returns

string

Inherited from

Space.toString

Defined in

boardzilla-core/src/board/element.ts:351


setOrder

setOrder(order): void

Set this class to use a different ordering style.

Parameters

NameTypeDescription
orderundefined | "normal" | "stacking"ordering style - "normal": Elements placed into this element are put at the end of the list (default) - "stacking": Used primarily for stacks of cards. Elements placed into this element are put at the beginning of the list. E.g. if a stack of cards has order set to stacking the first method will return the last card placed in the stack, rather than the first one placed in the stack. Hidden items in the stack are not tracked or animated while reordered to prevent their identity from being exposed as they move

Returns

void

Inherited from

Space.setOrder

Defined in

boardzilla-core/src/board/element.ts:573


isEmpty

isEmpty(): boolean

Returns whether this element has no elements placed within it.

Returns

boolean

Inherited from

Space.isEmpty

Defined in

boardzilla-core/src/board/element.ts:607


sortBy

sortBy(key, direction?): ElementCollection<GameElement<G, P>>

Sorts the elements directly contained within this element by some Sorter.

Parameters

NameType
keyGenericSorter | GenericSorter[]
direction?"desc" | "asc"

Returns

ElementCollection<GameElement<G, P>>

Inherited from

Space.sortBy

Defined in

boardzilla-core/src/board/element.ts:615


shuffle

shuffle(): void

re-orders the elements directly contained within this element randomly.

Returns

void

Inherited from

Space.shuffle

Defined in

boardzilla-core/src/board/element.ts:623


owner

get owner(): undefined | P

The player that owns this element, or the first element that contains this element searching up through the parent hierarchy. This is related to, but different than player. E.g. if a standard playing card is in a player's hand, typically the hand.player will be assigned to that player but the card itself would not have a player. In this case the card.owner() will equal the player in whose hand the card is placed.

Returns

undefined | P

Inherited from

Space.owner

Defined in

boardzilla-core/src/board/element.ts:638


createMany

createMany<T>(n, className, name, attributes?): ElementCollection<T>

Create n elements inside this element of the same class. This can only be called during the game setup (see createGame. Any game elements that are required must be created before the game starts. Elements that only appear later in the game can be created inside the Game#pile or made invisible.

Type parameters

NameType
Textends GameElement<BaseGame, BasePlayer>

Parameters

NameTypeDescription
nnumberNumber to create
classNameElementClass<T>Class to create. This class must be included in the elementClasses in createGame.
namestringSets name
attributes?Partial<Pick<T, "name" | "player" | "row" | "column" | "rotation" | { [K in string | number | symbol]: K extends keyof GameElement<BaseGame, BasePlayer> ? never : T[K] extends Function ? never : K }[keyof T]>> | (n: number) => Partial<Pick<T, "name" | "player" | "row" | "column" | "rotation" | { [K in string | number | symbol]: K extends keyof GameElement<BaseGame, BasePlayer> ? never : T[K] extends Function ? never : K }[keyof T]>>Sets any attributes of the class that are defined in your own class that extend Space, Piece, or Game. Can also include player. If a function is supplied here, a single number argument will be passed with the number of the added element, starting with 1.

Returns

ElementCollection<T>

Inherited from

Space.createMany

Defined in

boardzilla-core/src/board/element.ts:721


destroy

destroy(): void

Permanently remove an element. This can only be done while defining the game, and is usually only useful when creating groups of elements, such as createMany or createGrid where some of the created elements are not needed.

Returns

void

Inherited from

Space.destroy

Defined in

boardzilla-core/src/board/element.ts:748


rotation

get rotation(): number

Rotation of element if set, normalized to 0-359 degrees

Returns

number

Inherited from

Space.rotation

Defined in

boardzilla-core/src/board/element.ts:758


position

position(): number

Returns the index of this element within its parent, starting at zero

Returns

number

Inherited from

Space.position

Defined in

boardzilla-core/src/board/element.ts:771


isDescendantOf

isDescendantOf(el): boolean

Whether this element has the given element in its parent hierarchy

Parameters

NameType
elGameElement<BaseGame, BasePlayer>

Returns

boolean

Inherited from

Space.isDescendantOf

Defined in

boardzilla-core/src/board/element.ts:937


pile

pile: GameElement<BaseGame, BasePlayer>

An element containing all game elements that are not currently in play. When elements are removed from the game, they go here, and can be retrieved, using e.g. game.pile.first('removed-element').putInto('destination-area').

Defined in

boardzilla-core/src/board/game.ts:132


onEnter

onEnter<T>(type, callback): void

Attach a callback to this space for every element that enters or is created within.

Type parameters

NameType
Textends GameElement<BaseGame, BasePlayer>

Parameters

NameTypeDescription
typeElementClass<T>the class of element that will trigger this callback
callback(el: T) => voidCallback will be called each time an element enters, with the entering element as the only argument.

Returns

void

Example

deck.onEnter(Card, card => card.hideFromAll()) // card placed in the deck are automatically turned face down

Inherited from

Space.onEnter

Defined in

boardzilla-core/src/board/space.ts:109


onExit

onExit<T>(type, callback): void

Attach a callback to this space for every element that is moved out of this space.

Type parameters

NameType
Textends GameElement<BaseGame, BasePlayer>

Parameters

NameTypeDescription
typeElementClass<T>the class of element that will trigger this callback
callback(el: T) => voidCallback will be called each time an element exits, with the exiting element as the only argument.

Returns

void

Example

deck.onExit(Card, card => card.showToAll()) // cards drawn from the deck are automatically turned face up

Inherited from

Space.onExit

Defined in

boardzilla-core/src/board/space.ts:125

UI

layout

layout(applyTo, attributes): void

Apply a layout to some of the elements directly contained within this element. See also ElementCollection#layout

Parameters

NameTypeDescription
applyTostring | GameElement<BaseGame, BasePlayer> | ElementClass<GameElement<BaseGame, BasePlayer>> | ElementCollection<GameElement<BaseGame, BasePlayer>>Which elements this layout applies to. Provided value can be: - A specific GameElement - The name of an element - A specific set of elements (ElementCollection) - A class of elements If multiple layout declarations would apply to the same element, only one will be used. The order of specificity is as above. If a class is used and mutiple apply, the more specific class will be used.
attributesPartial<LayoutAttributes>A list of attributes describing the layout. All units of measurement are percentages of this elements width and height from 0-100, unless otherwise noted (See margin and gap)

Returns

void

Inherited from

Space.layout

Defined in

boardzilla-core/src/board/element.ts:1079


configureLayout

configureLayout(layoutConfiguration): void

Change the layout attributes for this space's layout.

Parameters

NameType
layoutConfigurationPartial<LayoutAttributes>

Returns

void

Inherited from

Space.configureLayout

Defined in

boardzilla-core/src/board/element.ts:1200


appearance

appearance(appearance): void

Define the appearance of this element. Any values provided override previous ones. See also ElementCollection#appearance

Parameters

NameTypeDescription
appearanceObjectPossible values are:
appearance.className?stringA class name to add to the dom element
appearance.render?false | (el: Game<G, P>) => null | ElementA function that takes this element as its only argument and returns JSX for the element. See ../ui/appearance for more on usage.
appearance.aspectRatio?numberThe aspect ratio for this element. This value is a ratio of width over height. All layouts defined in layout will respect this aspect ratio.
appearance.effects?{ trigger: (element: Game<G, P>, oldAttributes: Partial<Pick<Game<G, P>, undefined | "name" | "player" | "row" | "column" | "rotation" | "_eventHandlers" | "_visOnEnter" | "_screen" | "pile" | "players" | "flowCommands">>) => boolean ; name: string }[]Provides a CSS class that will be applied to this element if its attributes change to match the provided ones.
appearance.info?boolean | (el: Game<G, P>) => null | boolean | ElementReturn JSX for more info on this element. If returning true, an info modal will be available for this element but with only the rendered element and no text
appearance.connections?ObjectIf the elements immediately within this element are connected using Space#connectTo, this makes those connections visible as connecting lines. Providing a label will place a label over top of this line by calling the provided function with the distance of the connection specified in Space#connectTo and using the retured JSX. If labelScale is provided, the label is scaled by this amount.
appearance.connections.thickness?number-
appearance.connections.style?"double" | "solid"-
appearance.connections.color?string-
appearance.connections.fill?string-
appearance.connections.label?(__namedParameters: { distance: number ; to: Space<Game<BaseGame, BasePlayer>, BasePlayer> ; from: Space<Game<BaseGame, BasePlayer>, BasePlayer> }) => ReactNode-
appearance.connections.labelScale?number-

Returns

void

Inherited from

Space.appearance

Defined in

boardzilla-core/src/board/element.ts:1241


layoutControls

layoutControls(attributes): void

Apply default layout rules for all the placement of all player prompts and choices, in relation to the playing area

Parameters

NameTypeDescription
attributesActionLayoutsee ActionLayout

Returns

void

Defined in

boardzilla-core/src/board/game.ts:543


layoutStep

layoutStep(step, attributes): void

Apply layout rules to a particular step in the flow, controlling where player prompts and choices appear in relation to the playing area

Parameters

NameTypeDescription
stepstringthe name of the step as defined in playerActions
attributesActionLayoutsee ActionLayout

Returns

void

Defined in

boardzilla-core/src/board/game.ts:556


layoutAction

layoutAction(action, attributes): void

Apply layout rules to a particular action, controlling where player prompts and choices appear in relation to the playing area

Parameters

NameTypeDescription
actionstringthe name of the action as defined in game#defineActions
attributesActionLayoutsee ActionLayout

Returns

void

Defined in

boardzilla-core/src/board/game.ts:570


disableDefaultAppearance

disableDefaultAppearance(): void

Remove all built-in default appearance. If any elements have not been given a custom appearance, this causes them to be hidden.

Returns

void

Defined in

boardzilla-core/src/board/game.ts:580


showLayoutBoundingBoxes

showLayoutBoundingBoxes(): void

Show bounding boxes around every layout

Returns

void

Defined in

boardzilla-core/src/board/game.ts:589

Visibility

contentsWillBeShown

contentsWillBeShown(): void

Show pieces to all players when they enter this space

Returns

void

Inherited from

Space.contentsWillBeShown

Defined in

boardzilla-core/src/board/space.ts:35


contentsWillBeShownToOwner

contentsWillBeShownToOwner(): void

Show pieces when they enter this space to its owner

Returns

void

Inherited from

Space.contentsWillBeShownToOwner

Defined in

boardzilla-core/src/board/space.ts:43


contentsWillBeShownTo

contentsWillBeShownTo(...players): void

Show piece to these players when they enter this space

Parameters

NameType
...playersP[]

Returns

void

Inherited from

Space.contentsWillBeShownTo

Defined in

boardzilla-core/src/board/space.ts:51


contentsWillBeHidden

contentsWillBeHidden(): void

Hide pieces to all players when they enter this space

Returns

void

Inherited from

Space.contentsWillBeHidden

Defined in

boardzilla-core/src/board/space.ts:59


contentsWillBeHiddenFrom

contentsWillBeHiddenFrom(...players): void

Hide piece to these players when they enter this space

Parameters

NameType
...playersP[]

Returns

void

Inherited from

Space.contentsWillBeHiddenFrom

Defined in

boardzilla-core/src/board/space.ts:67


blockViewFor

blockViewFor(players): void

Call this to screen view completely from players. Blocked spaces completely hide their contents, like a physical screen. No information about the number, type or movement of contents inside this Space will be revealed to the specified players

Parameters

NameTypeDescription
players"all" | "none" | Player<BaseGame, BasePlayer>[] | "all-but-owner"= Players for whom the view is blocked

Returns

void

Inherited from

Space.blockViewFor

Defined in

boardzilla-core/src/board/space.ts:80