ts-playing-cards
v2.1.2
Published
A simple module to create card games.
Downloads
9
Maintainers
Readme
ts-playing-cards
A simple package that enables the creation of playing cards and decks, to help you create card games!
Features
Features
- Cards
- Cards
- Four suits + 1 no-suit
SuitValues.CLUBS
SuitValues.SPADES
SuitValues.HEARTS
SuitValues.DIAMONDS
- Joker have
SuitValues.NO_SUIT
(noSuit
) - Use
Suit.availableSuits()
to getSuitValues
string values
- Card faces
- All face cards are implemented through
FaceValues
- Use
FaceValues.availableFaces()
to getFaceValues
string values
- All face cards are implemented through
- Create cards
- Default constructor
new Card()
returnsace
ofclubs
. - Optional object constructor with
SuitValues
new Card( { suit: SuitValues, face: FaceValues, } )
- Optional object constructor with
string
new Card( { suit: 'hearts', face: 'six', face: FaceValues, } )
- Optional object constructor with
string
new Card( { suit: 'hearts', face: 'six', } )
- Default constructor
- Compare color cards
card.suit.isRed
orcard.suit.isBlack
- Compare face values
card.compare(Card)
⇒ returnsRank.LOWER, Rank.EQUAL, Rank.HIGHER
- Deck and Pile
- Deck and Pile
- Three deck types
DeckType.STANDARD
(52 cards)DeckType.STANDARD_JOKERS
(54 cards) andDeckType.FORTY
(40 cards).- Use
Deck.availableDecks()
to getDeckType
string values to create new decks
- Create decks
- Default constructor
new Deck()
returns a standard 52 cards deck - Optional object constructor with
DeckType
new Deck( { deckType: DeckType, numberOfDecks: number, customCards: Card[], } )
- Optional object constructor with
string
new Deck( { deckType: 'forty', numberOfDecks: number, customCards: Card[], } )
deckType
determines deck typenumberOfDecks
multiplies the number of cards in a deck by the specified number of decks amountcustomCards
creates a deck with custom cards
- Default constructor
- Shuffle cards
deck.shuffle()
- Remove cards from end and beginning of deck
deck.removeCard()
ordeck.removeCardFromBegin()
- Add cards to deck
deck.addCard(Card)
- Check remaining cards
deck.remainingCards
- Check empty decks
deck.isEmpty
Pile
has the same methods asDeck
, but it's created without cards.