Code Monkey home page Code Monkey logo

pick-a-card's Introduction

Pick a Card Build Status npm version

A node package for playing cards.

Usage

Initializing

To install the node package run npm i pick-a-card

Requiring the package brings two classes which are Deck and Card.

const {Deck, Card} = require("pick-a-card");

Creating a Deck

Deck class creates a classic playing cards deck. Optionally 2 jokers can be added to the deck using jokers parameter. Created deck will have 4 suits with 13 cards each. Every card will have their value where Ace is 1 and King is 13.

const deckWithoutJockers = new Deck();

const deckWithJockers = new Deck({jokers: true});

Picking and Checking Cards from the Deck

Use pick and check methods of Deck instance to extract or reveal a card from the deck. Both methods can have parameters of position which are "random", "top" and "bottom" and count which is an integer between 0 and the length of the cards in the deck. After using pick returned Card array is removed from the deck, and after using check the deck does not change.

deck.pick(); //extracts 1 card from a random position.
deck.pick({position: "top", count: 3}); //extracts 3 cards from the top of the deck.

deck.check(); //reveal 1 card from a random position.
deck.check({position: "bottom", count: 2}); //reveals 2 cards from the bottom of the deck.

Shuffle the Deck

Calling the shuffle method of the deck randomly repositions all the cards in the deck. Mutates the main deck, does not return a shuffled copy.

pick-a-card's People

Contributors

srcnalt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

sanhar igvarius

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.