1.4.1 • Published 1 year ago

sweet-blackjack v1.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

sweet-blackjack

A simple implementation of the classic card game Blackjack (also known as 21), written in TypeScript. This implementation includes classes for a Blackjack game and a Deck of cards.

Installation

npm install sweet-blackjack

Usage

import { Blackjack } from "sweet-blackjack";

const game = new Blackjack(4);

game.onEnd((data) => {
  console.log("Game state:", data.state);
  console.log("Player's cards:", data.player.cards);
  console.log("Dealer's cards:", data.dealer.cards);
  console.log("Payout:", data.payout);
});

game.placeBet(100);

game.start();

game.doubleDown();
game.hit();
game.stand();

API

Blackjack

constructor(decks: number)

  • decks - The number of decks to use in the game

placeBet(amount: number)

  • amount - The amount of money to bet

start()

Starts the game and deals the initial cards

hit()

Draws a card from the deck

stand()

Ends the player's turn

doubleDown()

Doubles the player's bet and draws one more card

onEnd(callback: (data: GameEndData) => void)

  • callback - A function to be called when the game ends

Deck

constructor(decks: number)

  • decks - The number of decks to use in the game

shuffleDeck(amount: number = 1)

Shuffles the deck

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

License

This project is licensed under the MIT License - see the LICENSE file for details.

1.4.1

1 year ago

1.4.0

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.2

1 year ago

1.2.0

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.2.1

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago