Generic Card Game System (First Look)

I am suffering from massive writers block today, and have been very busy trying to complete the data storage project for YUI. I am please to note that I am nearly finished, just working out some issues with the flash storage object currently employed by YUI. Ill post about it as soon as I get the OK from the YUI team.

Because of my writers block, I decided to share a project that I have been tinkering on over the past few weeks, a generic card-game management system. The goal of this system is to build a set of easy to extend, MVC JavaScript objects that can be used as the backbone of any card-game system. I will be tackling solitaire card games first, and have developed the card management architecture, but havent even begun to design the game architecture.

The card architecture consists of three objects: Deck, CardModel, CardView. The Deck object will handle a collection of cards and has methods to add or remove cards, and a shuffle method using the Knuth algorithm. Games are played by interacting with the Deck object and a developer would extend the object to meet the needs of their game. For example a blackjack game might extend Deck with a MultiDeck subclass, which manages 7 internal Deck objects. The CardModel is a very basic representation of a card: suit, value, name. These are the properties that define typical playing cards, however, if you took a complex card game like Magic the Gathering, you would extend CardModel with a subclass containing many more properties. The CardView object is more like a rendering engine, which handles how to represent cards in the DOM. The default system just insert the suit and name as a string into the DOM, but I have written the CardViewImg subclass which uses images to represent the cards. Right now I am planning on developing three CardView systems: CardViewImg, CardViewCss (using backgrounds for card images), and CardViewCanvas (rendering the cards using canvas).

One other neat feature is that the CardViewImg system allows the images for cards to be updated by passing in a JSON object to the static "CardViewImg.loadImages" method; this will change all instances of the CardViewImg automatically. There is also the capability to turn cards over, since that is an important part of many card games.

Here is a demo page to play around with the deck and card management system. Initially, the cards will be in order, but this can be changed by pressing the shuffle button. Cards are randomly turned over as well, but you can see what they are supposed to be by looking at their title.