0.0.1 • Published 9 years ago

jscards v0.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
9 years ago

#Cards Github ##A javascript library for basic data representations of the Card, Hand, and Deck. Useful for creating card games.

  1. Creating a deck

First, load the library: var Cards = require('Cards');

Creating a deck is usually the first thing you want to do. var myDeck = new Cards.Deck();

This will create a 52 card deck (without jokers) and shuffle it automatically.

Now that you have a deck, I'll explain some of the methods you can call on it.

To shuffle the deck, just call myDeck.shuffle()

Dealing the deck is pretty simple as well: myDeck.deal(4); To deal the deck, you just pass in a number that can be divided into 52. Otherwise, you will get an error. This method returns an array containing the number of hands you supply the first parameter.

That's pretty much the deck. Hopefully, it is very easy and understandable.

  1. The Card

Cards are object that have a value and a suite. Creating them manually is simple–var myCard = new Cards.Card(Cards.KING, Cards.HEART)–but usually you will create a deck, which generates a standard 52 card automatically.

  1. The Hand

The Hand class is definitely the most robust.

To create a hand, you can call var myHand = new Cards.Hand(myArrayofCardObjects).

To sort a hand, calling myHand.sort() will sort by suite, and then by value, ace being the highest value.

Adding a card to a hand is done by calling myHand.addCard(new Card(5, Cards.SPADE))

Removing a card from the deck is done like this: myHand.removeCard(new Card(5, Cards.SPADE))

Important : Removing cards can be done by passing a position parameter or a card parameter. Cards are stored in cards as an array of card objects, so passing a position will throw an error if it is less than 0, or greater than the amount of cards in the hand. If you pass a card object that doesn't exists in the hand, it will also throw and error.

Getting a card by position is easy: myHand.getCard(4).

myHand.count() will return the number of cards in the hand.

###Notes

I don't know why I wrote the documentation for this, but I hope it comes in handy to someone. Just so you know, when trying to rename this README, I use rm instead of mv, so this is the rewrite of the documentation....sigh

Anyway, enjoy

  • Sam
0.0.1

9 years ago