v0.10.0

Class: Hand

A hand of Cards.

✅ Attribute Support

This class manages a player’s hand of cards, including their cards and attributes. It provides methods for adding and removing cards, clearing the hand, and managing hand attributes.

Table of contents

Constructors

Methods

Constructors

constructor

new Hand(id?): Hand

Parameters

Name Type Default value
id string 'main'

Returns

Hand

Methods

addCard

addCard(card): void

Adds a card to the hand.

Parameters

Name Type Description
card Object The card to add.
card.card Card -

Returns

void


clear

clear(deck?): void

Clears the hand.

Parameters

Name Type Description
deck Object Optional deck to discard cards to when clearing the hand
deck.deck? Deck -

Returns

void


getAttribute

getAttribute(key): unknown

Gets an attribute from the hand.

Parameters

Name Type Description
key Object The key of the attribute to get.
key.key string -

Returns

unknown

The value of the attribute or null if the attribute does not exist.


getCards

getCards(): Card[]

Gets all cards in the hand.

Returns

Card[]

A copy of the cards in the hand.


getFullState

getFullState(): unknown

Returns a complete representation of the hand, including hidden cards. This should ONLY be sent to the player who owns this hand.

Returns

unknown

A complete representation of the hand.


getHiddenCards

getHiddenCards(): Card[]

Gets all hidden cards in the hand.

Returns

Card[]

A copy of the hidden cards in the hand.


getId

getId(): string

Gets the ID of the hand.

Returns

string

The ID of the hand.


getVisibleCards

getVisibleCards(): Card[]

Gets all visible cards in the hand.

Returns

Card[]

A copy of the visible cards in the hand.


getVisibleState

getVisibleState(): unknown

Returns a representation of the hand that is safe to send to clients. Only includes visible cards and attributes.

Returns

unknown

A representation of the hand that is safe to send to clients.


hasAttribute

hasAttribute(key): boolean

Checks if the hand has an attribute.

Parameters

Name Type Description
key Object The key of the attribute to check.
key.key string -

Returns

boolean

True if the attribute exists, false otherwise.


removeCard

removeCard(index): null | Card

Removes a card from the hand.

Parameters

Name Type Description
index Object The index of the card to remove.
index.index number -

Returns

null | Card

The removed card or null if the index is out of bounds.


setAttribute

setAttribute(«destructured»): void

Sets an attribute on the hand.

Parameters

Name Type
«destructured» Object
› key string
› value unknown

Returns

void