Click here to Skip to main content
15,867,330 members
Articles / Programming Languages / C#

Cards Game Library

Rate me:
Please Sign up or sign in to vote.
4.40/5 (20 votes)
29 Aug 2008CPOL2 min read 111.7K   9K   66   11
A library for creating a cards games with Silverlight, with two sample Solitaire games.

CardsSilverlight

Introduction

This is a C# class library for card games; it’s very useful for anyone who is thinking of developing a cards game especially with Silverlight, though it could be used with other .NET technologies as well. It’s also useful as a complete example for anyone who wants to learn Silverlight.

I’ve built two games (Solitaire and Spider Solitaire) using this library, and you can see from the source code that the code written in the individual game projects is minimal and only represent the game rules.

You can see the games on action in my blog:

The actual Silverlight applications are hosted on http://streaming.live.com, which is a great free service from Microsoft.

Overview

The solution contains the following projects:

  • Cards.Data

    This is a library for card games, only contains card data and logic, and doesn’t contain anything that is specific to Silverlight.

    Contains the following classes:

    • Game: a class that represents the card game, which contains decks and cards. From this class, you can traverse all the other data classes.
    • Deck: a stack of cards that could be initialized and used as the full cards deck (52 cards) and drawn from it to other decks like player hands or ground stacks.
    • Card: the actual card object.
  • Cards.Silverlight

    This is a library that has Silverlight controls that represent each of the above classes. Each control has a pointer to its associated data class, and provides event handlers to its events and responds with graphics and animations.

    Contains the following controls:

    • GameShape: This is the graphical representation of the Game class. Doesn’t have a lot of graphics logic, but it contains a list of other graphical representations of the decks and cards that exist in the associated game. It provides utility functions to find a shape that represents a card or deck data object.
    • DeckShape: This is the graphical representation of the Deck class. Handles the positioning of its contained cards according to a set of rules. Like drawing vertically and with a fixed space between cards and a maximum space for the whole deck.
    • CardShape: This is the graphical representation of the Card class. Provide animations to card events, mouse events, and drag and drop behaviors.
  • Solitaire

    This is the Solitaire game. It only contains the main page with the logic of the game in the code-behind.

  • SpiderSolitaire

    This is the Spider Solitaire game. It only contains the main page with the logic of the game in the code-behind.

Future

I’m thinking of expanding these libraries to include game logic that facilitates computer AI players and multiplayer network options. I’ll do this if I have time, but if anyone of you can implement these features, that would make me very happy to know.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader Link Development
Egypt Egypt
IF YOU WANT TO IMPROVE YOUR SOFTWARE, DON'T TEST MORE; DEVELOP BETTER.

http://bishoylabib.blogspot.com

Comments and Discussions

 
GeneralMy vote of 5 Pin
snakewine3-Oct-13 16:36
snakewine3-Oct-13 16:36 
GeneralMy vote of 1 Pin
Farhan Ghumra21-May-13 0:37
professionalFarhan Ghumra21-May-13 0:37 
GeneralMy vote of 1 Pin
Norman Hunt15-Jun-12 20:42
Norman Hunt15-Jun-12 20:42 
GeneralBug in gameshape Pin
kiss_of_death5-Nov-10 3:04
kiss_of_death5-Nov-10 3:04 
GeneralBroken Silverlight Hosting, Updated Code Pin
Bryan Livingston27-Feb-10 13:00
Bryan Livingston27-Feb-10 13:00 
GeneralRe: Broken Silverlight Hosting, Updated Code Pin
Bryan Livingston7-Mar-10 11:23
Bryan Livingston7-Mar-10 11:23 
GeneralCreate Poker game using this library: Pin
nccsbim07115-Jul-09 17:49
nccsbim07115-Jul-09 17:49 
QuestionPorting to WPF? Pin
Greg in Cary, NC5-Jul-09 11:55
Greg in Cary, NC5-Jul-09 11:55 
GeneralThanks Pin
Jordanwb16-Nov-08 5:49
Jordanwb16-Nov-08 5:49 
GeneralVS2008 and SL RTW Pin
aquamoon13-Nov-08 21:49
aquamoon13-Nov-08 21:49 
Generalpage question Pin
Member 99439116-Oct-08 15:13
Member 99439116-Oct-08 15:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.