Click here to Skip to main content
5,788,212 members and growing! (19,524 online)
Email Password   helpLost your password?
Web Development » Silverlight » General     Intermediate License: The Code Project Open License (CPOL)

Cards Game Library

By Bishoy Labib

A library for creating cards games with Silverlight with 2 sample Solitaire games
C#, Silverlight

Posted: 29 Aug 2008
Updated: 29 Aug 2008
Views: 5,143
Bookmarked: 20 times
Note: This is an unedited reader contribution
Announcements
Loading...



Search    
Advanced Search
Sitemap
8 votes for this Article.
Popularity: 3.68 Rating: 4.07 out of 5
1 vote, 12.5%
1
0 votes, 0.0%
2
1 vote, 12.5%
3
1 vote, 12.5%
4
5 votes, 62.5%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article
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. 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:

http://bishoylabib.blogspot.com/2008/05/solitaire.html
http://bishoylabib.blogspot.com/2008/08/spider-solitaire.html 

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 represent 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 draw 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 exists in the associated Game. And provides utility functions to find a shape that represent a card or deck data object.

DeckShape: This is the graphical representation of the Deck class. Handle 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 code behind.

  • SpiderSolitaire

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

Future

I’m thinking of expanding these libraries to include game logic that facilitate 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)

About the Author

Bishoy Labib


IF YOU WANT TO IMPROVE YOUR SOFTWARE, DON'T TEST MORE; DEVELOP BETTER.

http://bishoylabib.blogspot.com
Occupation: Team Leader
Company: Link Development
Location: Egypt Egypt

Other popular Silverlight articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 3 of 3 (Total in Forum: 3) (Refresh)FirstPrevNext
GeneralThanksmemberJordanwb6:49 16 Nov '08  
GeneralVS2008 and SL RTWmemberaquamoon22:49 13 Nov '08  
Generalpage questionmemberMember 99439116:13 16 Oct '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 29 Aug 2008
Editor:
Copyright 2008 by Bishoy Labib
Everything else Copyright © CodeProject, 1999-2009
Web12 | Advertise on the Code Project