[Home] [Puzzles & Projects] [Delphi Techniques] [Math Topics] [Library] [Utilities]
Expand Cards 1 program to add graphic card images.
Background and Techniques
I worked hard this week to try to find a way to use Cards.DLL, the card image dll (dynamic link library) module that comes with windows. I learned, however, that there are 16 bit (Win 95, 98, ME) and 32 bit versions (Windows NT and 2000) of Cards.DLL and worse - both versions have the same name. Accessing 16-bit code from Delphi is non-standard, although I think it can be done. And Microsoft does not grant permission to distribute either. I finally decided to use a nice freeware TCard component written by Guilio Ferrari. (See U_CardComponent header comments for credits.) The card images look very similar to those used in Windows games.
I renamed the unit to U_CardComponent and moved my TDeck object over there, just to keep the card and deck objects in a common unit. The resource file containing the card images (U_CardComponent.res) is 500K bytes long but compresses nicely to about 37K. As in other freeware components, I have commented out the Register procedure which is required to install the component as a visual component, we'll just create cards as we need them.
Since TCard has a property to specify the card back pattern to display, I added a unit (U_Select) to select the card backs to use for the deck. It displays all of the available choices and exits when you select one.
I also added a couple of features to the main unit (U_Cards2). In addition to the Shuffle and Deal buttons, you can now drag cards around the screen with the mouse and turn cards over by right clicking. Not very useful by themselves, but will probably come in handy in implementing games. Also notice the "wiggle" in the deck image when you click on the shuffle button.
There are close to 500 lines of code here (although I must thank Mr. Ferrari for a couple of hundred of them). According to my size criteria, that puts it in the advanced category - but there really is nothing too complex going on here - just a lot of details.
Running/Exploring the Program
Suggestions for Further ExplorationsCard games, here we come!
Copyright © 2000-2015, Gary Darby
All rights reserved.