Skip to main content

Class: Player<G, P>

Base player class. Each game must declare a single player class that extends this to be used for players joining the game. Additional properties and methods on this class will be available in game, when e.g. a player argument is passed to an action for the player taking that action.

Type parameters

NameType
Gextends BaseGame = BaseGame
Pextends BasePlayer = BasePlayer

Properties

id

id: string

A player's unique user id

Defined in

boardzilla-core/src/player/player.ts:22


name

name: string

A player's chosen name

Defined in

boardzilla-core/src/player/player.ts:27


color

color: string

String hex code of the player's chosen color

Defined in

boardzilla-core/src/player/player.ts:32


avatar

avatar: string

String URL of the avatar image for this player

Defined in

boardzilla-core/src/player/player.ts:37


host

host: boolean

Whether this player is the gane's host

Defined in

boardzilla-core/src/player/player.ts:42


position

position: number

A player's seating position at the table. This is distinct from turn order, which is the order of game.players. Turn order can be altered during a game, whereas position cannot.

Defined in

boardzilla-core/src/player/player.ts:49

Methods

hide

hide<P>(this, ...attrs): void

Provide list of attributes that are hidden from other players

Type parameters

NameType
Pextends BasePlayer

Parameters

NameType
this() => P
this.hiddenAttributesstring[]
...attrskeyof P[]

Returns

void

Defined in

boardzilla-core/src/player/player.ts:59


setCurrent

setCurrent(this): void

Set this player as the current player

Parameters

NameType
thisP

Returns

void

Defined in

boardzilla-core/src/player/player.ts:72


others

others(): P[]

Returns an array of all other players.

Returns

P[]

Defined in

boardzilla-core/src/player/player.ts:79


other

other(): P

Returns the other player. Only allowed in 2 player games

Returns

P

Defined in

boardzilla-core/src/player/player.ts:86


allMy

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

Finds all elements of a given type that are owned by this player. This is equivalent to calling game.all(...) with {owner: this} as one of the search terms. Also see GameElement#owner.

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

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

Returns

ElementCollection<F>

Defined in

boardzilla-core/src/player/player.ts:96


my

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

Finds the first element of a given type that is owned by this player. This is equivalent to calling game.first(...) with {owner: this} as one of the search terms. Also see GameElement#owner.

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

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

Returns

undefined | F

Defined in

boardzilla-core/src/player/player.ts:107


has

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

Returns true if any element of a given type is owned by this player. This is equivalent to calling game.has(...) with {owner: this} as one of the search terms. Also see GameElement#owner.

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

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

Returns

boolean

Defined in

boardzilla-core/src/player/player.ts:118