Geeks With Blogs

Freestyle Coding Programming in the Real World

Before I begin with the Milestone 1 recap, I have a few things I need to announce. To begin with, we need to help some kids!

Every year, I participate in Extra Life. It's a charity that raises money for hospitals that are members of the Children's Miracle Network. I'm looking for sponsors. You can visit my donation page at http://www.extra-life.org/index.cfm?fuseaction=donorDrive.participant&eventID=501&participantID=4554. If you feel funny about not giving to your local CMN hospital, then I won't be mad if you want to search for someone raising money for your local hospital. All donations are 100% tax-deductable, and all 100% of the money goes to the hospital. So, let's do some good. I'll keep a link to the donations page in the Link section of the site.

Next, I have a few speaking engagements. As of right now, I'm booked for Tuesday, October 11 at the Huntsville, AL User's Group. Then, I have a little tour developing for the beginning of November. Right now, I have New Orleans on the 8th of November and Mobile, AL, on the 10th of November. A few other groups are talking about adding in. All of these will be some sort of XNA talk, so show up, support, and learn.

Now, on to the good stuff. I cranked out Milestone 1 last night. The primary goal of Milestone 1 was to create a set of objects and interfaces that could replicate a deck of cards. I tried to do a combination of intelligent design that covers all the bases and just programming what I need.

First, let's get the quickies out of the way. The Ranks and Suits enumerations are very straight forward. The only thing strange about them was the inclusion of a Joker as a rank. If you do a little research on cards, you'll see there is some historical basis for this. I did a little forethought, and calling a Joker a Spade and Heart can make my life a little easier later. It is worth noting that a generic library would have to abstract the Ranks and Suits enumerations. However, those are the only ones I needed for now.

The ICard and IDeck were made generic to help with future ideas. The only thing every "card" has is something on the front and something on the back. Think of a Flash Card, and you'll get the idea. That's why I put one layer between the ICard and the IPlayingCard. Likewise, I went pretty minimal with an IDeck. There are a lot of things you could do with a deck of cards. I thought about the things I needed for this project and only included those. I did base it on IEnumerable. Simple fact is that you might want to just look through the deck.

Now, let's get to the heavy issues. I want to start with the PokerCard. It is a concrete implementation of the IPlayingCard. I decided to make it an internal object. The idea was that a PokerCard comes from a PokerDeck. You have to get a deck of cards to get an official card. This did not come without consequence. I originally wanted to make an implicit cast from PokerCard to PokerDeck. The idea was that a card is a deck with one item. However, you can't create a cast from PokerCard to PokerDeck because the output object is more accessible than the input object. Then, you can't create a cast from IPlayingCard to PokerDeck because the input of an implicit cast can't be an interface. That's is why the PokerDeck includes a version of Merge that takes an IPlayingCard.

This brings us to the PokerDeck. My hope was to keep the entire implementation internal. That's why I do some strange things, such as have Draw( int ) call Draw() "int" times. I also decided to make the PokerDeck a class. Usually, XNA begs for something like this to be a struct. However, most of the time, we want to pass these things around and treat them like the reference they are. That is why merge drains one deck when it creates the other. Because of this, I need to be careful when I let these things go out of scope.

The final remark is back to the way the PokerDeck creates the PokerCards. I don't have the artwork right now, so I faked the Texture2Ds for the time being. Art is not my strong suit. Since I can defer the art for now, I decided to do it. This will come back up later, but not until I'm ready to actually start rendering cards.

This should make a pretty good port-mortem on this section. Please, question away. I'm sure I forgot something.

Posted on Tuesday, October 4, 2011 10:54 PM .NET , C# , XNA , Xbox 360 , Card Roulette | Back to top


Comments on this post: Card Roulette: Milestone 1

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Chris Gardner | Powered by: GeeksWithBlogs.net