v0.8.2

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 Card The card to add.

Returns

void


clear

▸ clear(deck?): void

Clears the hand.

Parameters

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

Returns

void


getAttribute

▸ getAttribute(key): any

Gets an attribute from the hand.

Parameters

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

Returns

any

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.


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(): any

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

Returns

any

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 string The key of the attribute to check.

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 number The index of the card to remove.

Returns

null | Card

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


setAttribute

▸ setAttribute(key, value): void

Sets an attribute on the hand.

Parameters

Name Type Description
key string The key of the attribute to set.
value any The value of the attribute to set.

Returns

void