Click here to Skip to main content
Licence 
First Posted 18 Apr 2004
Views 27,293
Bookmarked 8 times

Arcaynn.GameThings

By | 18 Apr 2004 | Article
A lesser GPL licensed class library that includes types to represent playing cards and decks of playing cards.

Introduction

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.

Arcaynn.GameThings.Deck

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.
deck.Shuffle(5);
// Draw the top 5 cards and add them to the hand.
hand += deck.DrawFromTop(5);
// Print the hand to the screen.
Console.WriteLine(hand.ToString());

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.

Arcaynn.GameThings.PlayingCard

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.

Remarks

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!

License

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

Arcaynn_



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 19 Apr 2004
Article Copyright 2004 by Arcaynn_
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid