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
== 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.
Deck deck = new Deck(2);
Deck hand = new Deck(0);
hand += deck.DrawFromTop(5);
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
rank are the desired suit and rank for the card. The suits and ranks are represented by the
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!