Initializing a deck can be done in several ways.

To create a standard 52 card deck with 4 suits, 13 cards per suit just call:

var deck = new PlayingCardDeck();

To create a deck as above but include jokers use:

var deck = new PlayingCardDeck(2);

note: the argument '2' is the number of jokers required, if no argument is supplied a deck with no jokers is initialized

For a more customized deck the following constructor can be used:

var deck = new PlayingCardDeck(CardSuits.Default(), CardIdentities.AceLow(), 0);

note: CardSuits & CardIdentities classes contain static methods of common configurations of cards, but can also be customized to create any sort of playing card deck required.

for more information see CardSuits & CardIdentities


Shuffling the deck is as simple as calling the Shuffle() method, optionally specifying an integer for the number of times to shuffle.


Dealing / Assigning cards

Once the deck is initialized cards can be assigned to any class that implements the ICardSet interface. (e.g. a Player or Hand class maybe) using the AssignSet method.

For example you may create a Hand class as follows:

internal class Hand : ICardSet
     private Guid _setId;

     #region ICardSet Members

     public Guid CardSetId
             if (_setId == Guid.Empty) _setId = Guid.NewGuid();
             return _setId;

     public int ItemCount
         get { throw new NotImplementedException(); }


And then ‘assign’ cards to that hand as follows:

var hand1 = new Hand();
deck.AssignSet(7, hand1);

CardSuits & CardIdentities


Last edited Nov 4, 2010 at 12:33 PM by dve, version 3


No comments yet.