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. I
ll post about it as soon as I get the OK from the YUI team.
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.