Click here to Skip to main content
13,090,267 members (82,243 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked
Posted 18 Apr 2004


, 18 Apr 2004
Rate this:
Please Sign up or sign in to vote.
A lesser GPL licensed class library that includes types to represent playing cards and decks of playing cards.


Arcaynn.GameThings is a lesser GPL licensed class library that includes types to represent playing cards, decks of playing cards, and dice. It enables a person designing a game that uses playing cards or dice to concentrate on how to implement the game logic, without having to be concerned with how to ensure that their game will correctly represent cards/dice.

Using the code

The types included in this library are simple to use. Following are examples on how to use each. Look through the source files for anything you do not see or understand, it is fully documented.


In order to create a standard deck of 52 playing cards, simply use Deck deck = new Deck();. To create a deck representing a stack of cards made from more than one deck, as is common in casino blackjack, use Deck deck = new Deck(n);, where n is the number of decks to include. Methods contained in the Deck type include different ways to shuffle, draw, and otherwise manipulate the deck. Type also overloads of the + and == operators, adding a card or a deck to the bottom of the deck, and telling whether two decks are of the same composition, respectively; also overloaded is the ToString() method, which returns a string consisting of the name of every card in the deck, separated by line returns. The following code snippet shows how to use some of the various methods.

// Create a deck of 104 cards, two of each.
Deck deck = new Deck(2);
// Create a deck of 0 cards, representing a hand.
Deck hand = new Deck(0);
// Shuffle the deck five times.
// Draw the top 5 cards and add them to the hand.
hand += deck.DrawFromTop(5);
// Print the hand to the screen.

Cards removed from the deck using methods will no longer be contained in the deck. Those referenced by using the included indexer will continue to be in the deck unless set to null, when they will be a null reference.


This type represents a single playing card. It is created by using PlayingCard card = new PlayingCard(CardSuit.suit, CardRank.rank); where suit and rank are the desired suit and rank for the card. The suits and ranks are represented by the CardSuit and CardRank enums, respectively.


As with all reference types, be sure to use Copy() to create a copy of the type in question, else they will simply share a reference. This was the source of much internal embarrassment to myself during debugging!

If you use my code in anything, please let me know! I'd love to see how it's used. Any comments/bugs/whatever can either be emailed to me, or posted on this board thingie here. Also, visit my website to see other things I have created!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170813.1 | Last Updated 19 Apr 2004
Article Copyright 2004 by Arcaynn_
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid