1.0.3 • Published 2 years ago

simply-blackjack v1.0.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

simply-blackjack

A simple blackjack module to play and manage games.

Demo gif

Usage

You will need to require the package and create a game just like this:

const Blackjack = require('simply-blackjack');

const Game = new Blackjack({
  decks: 3,
  payouts: {
    blackjack: 1.5,
    default: 1
  }
});

Options

OptionDescriptionTypeDefault
decksThe number of decks to use when dealing cards.Number3
payoutsObject{}
payouts.blackjackThe multiplier for winning blackjack.Number1.5
payouts.defaultThe default multiplier for winning (No blackjack).Number1

Variables

VariableDescriptionTypeDefault
deckAmountThe number of decks being used.Number3
payoutsThe object defining blackjack and default payouts.Object{ blackjack: 1.5, default: 1 }
stateThe current state of the game (waiting, player_blackjack, player_win, draw, dealer_blackjack, dealer_win)String'waiting'
dealerThe dealers cards.Array[]
playerThe players cards.Array[]
tableThe current table, showing player and dealer cards (Minus hidden card) and their totals.Object{}
betAmountThe amount the player is betting.Number

Events

These are examples of the following events:

// This will fire when the game has reached the end
Game.on('end', (results) => {
  console.log(results);
  // Example output:
  // {
  //    state: 'dealer_win',
  //    bet: 20,
  //    winnings: 0,
  //    losses: 20,
  //    player: { total: 23, cards: [ [Object], [Object], [Object] ] },
  //    dealer: { total: 11, cards: [ [Object], [Object] ] }
  // }
});

Methods

Bet

This will update the players bet on the game. | Param | Type | Required | |--------|--------|----------| | Amount | Number | Yes |

// Updates your bet on the current game
Game.bet(20);

Start

This method will start the game and draw 2 cards for the player, and the dealer (One dealer card is hidden).

let cards = Game.start();

console.log(cards);
// Example output:
//{
//  "player": {
//    "total": 7,
//    "cards": [ 
//      {
//        "name": "5 of Clubs",
//        "suit": "Clubs",
//        "value": 5
//      },
//      {
//        "name": "2 of Diamonds",
//        "suit": "Diamonds",
//        "value": 2
//      }
//    ]
//  },
//  "dealer": {
//    "total": 10,
//    "cards": [
//      {
//        "name": "J of Hearts",
//        "suit": "Hearts",
//        "value": 10
//      }
//    ]
//  }
// }

Hit

This will give the player another card.

let cards = Game.hit();

console.log(cards);
// Example output:
// {
//   "name": "J of Clubs",
//   "suit": "Clubs",
//   "value": 10
// }

Stand

This will trigger the dealer to get dealt cards and trigger the end event.

// Tells the game you no longer want cards
Game.stand();