Monday, April 07, 2008 9:54 PM
Learning .NET & WPF through A deck of cards
I've been working on a Solitaire program on and off for years (pretty much since .NET 1.0 was in beta) The back-end engine/framework was pretty straightforward, but I could never get the animation quite right. I've kept it up-to-date with each release of the framework, updating for generics, and even trying DirectX, but I could never get it quite right.
When WPF came along and I came across some SVG Clipart for the cards, I was inspired to try again. This time around, the cards looked pretty good, and the animations (when they displayed were very smooth) but I kept having trouble with threading, so when the deck was shuffled, it only showed one card move, and that was the last one! Frustrating, to say the least, to come so far, then get hung up!
However, this week, when working on a Silverlight project, I relearned how to do animations, particularly in code, and finally (FINALLY!), I've gotten it so that it draws very smoothly, animates all actions and actually looks pretty good. (IMHO)
I'm actually amazed by how much I gained by going to Storyboards for the motions. Instead of having to fuss over each animation, and try to wait while it was done, I could do entire sets of moves with a ParallelTimeline so that a while stack of cards could move in tandem without any real manipulation necessary. The initial deal, or a pull from the deck looks like all the cards are being carelessly thrown out, but they all land exactly where they need to go. And it was all done in at least 50% less animation code than any other version I've tried in the past.
Of course, there's a lot of other stuff to fuss with, like better mouse handling and memory usage and more variants, but I'm really pleased.
Also, the rules code is almost completely abstracted from the animation code, so I think it could even be ported to Silverlight or XNA with minimal fuss.
Mind you, not tonight <grin>
At any rate, here's the current install: Solitaire
I'm going to clean up the source and release it shortly, but I've got an interview coming up this week that I want to prepare for. Wish me luck.
Filed under: .NET