Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Code Samples & Tips
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Code Samples & Tips Share your recent discoveries and ideas with other users.


Card images


Reply
 
LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old 02-02-2008, 12:32 AM
Junior Member
 
Join Date: Apr 2007
Location: Olympia, Washington USA
Posts: 24
Default

Marc, the cards.dat is a binary file created with B4PPC's binaryfile.dll. First, I assembled the bitmaps for each card and card back. Then I wrote a short program using the EmbedFile method to put all the bitmaps into a single file -- cards.dat.

As you can see from the CardDemo program, the images are retrieved using the RetrieveImage method. To retrieve a particular card image (bitmap), you need to know the starting position for that image within cards.dat. The CardDemo program gives you the algorithm for retrieving images 1-63, where images 1-52 are the cards in a standard deck, 53 is the joker, and 54-63 are different card backs.

All of the bitmaps are 96 x 71 pixels but the first 53 images have only 4 bits per pixel whereas the rest of the cards have 8 bits per pixel which means the storage space for those images is larger. This makes calculating the starting position a little more difficult but again, the algorithm for doing so is in the CardDemo program.

When you create an image control to receive the image with the RetrieveImage method, you should define its size in the same ratio as the original bitmap. The card demo program uses 96 x 71, 69 x 51, and 46 x 34, all of which have the same height to width ratio. Pick any height you wish and make the width proportional, or vice-versa.

As you can see in the carddemo program, the first card in cards.dat is the Ace of Clubs, followed by the 2 through the King. Then comes Diamonds in the same rank order, then Hearts and then Spades. It is easy enough to "shuffle" the 52 cards and deal a random hand. But you need a way of identifying the rank and suit of a give card (say, for example, card number 31). Here is the algorithm for doing that (be sure to define Rank and Suit as global):

Sub randcard(c)
Rank = 1 + (c-1) Mod 13
Suit = 1 + Int((c - 1) / 13)
End Sub

Rank returns a 1 for ace, 2-10, 11 = jack, 12 = queen, and 13 = king.
Suit returns 1 = clubs, 2 = diamonds, 3 = hearts, 4 = spades.
So if you enter the subroutine with C=31, you would get Rank = 5 and Suit = 3, i.e. the 5 of hearts.

I hope this enough information to get you going. Good luck with your project!

-Dave Fallen
Reply With Quote
  #12 (permalink)  
Old 02-02-2008, 04:44 PM
Basic4ppc Veteran
 
Join Date: Apr 2007
Posts: 200
Default

Thanks Dave!,

I already made the backbone of my Texas Hold Em Pokerhand evaluator. This works great.

marc
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing file on device or storage card tsteward Questions & Help Needed 2 11-02-2008 12:32 AM
Find serial number of SD card after formatting Paul Questions & Help Needed 0 10-19-2008 10:43 PM
SD-Card in sleep mode berndgoedecke Questions & Help Needed 0 07-17-2008 07:02 PM
SD Card fix partition table? MM2forever Chit Chat 3 06-07-2008 10:04 AM
Scan for presence of GPS card alfcen Code Samples & Tips 0 05-26-2007 01:57 PM


All times are GMT. The time now is 06:35 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0