Tomi Vauters: Hi there,I wrote a cards engine about 3 years ago for Snap/Solitair style games.The concept I used was to make the card a visual component, able to draw itself when placed on the form with all the states of a card, selected, face up/down, ghosted, etc. Ensure the new TCard component inherits from any visual component, so it also inherits all the drag/drop/draw behaviour from the parent class. In addition a container class (or deck) only needs to be a simple list of pointers to TCard components, nothing fancy. I placed all the methods for the "deck" initialization, shuffling, etc. in the container class, and in that case I used many containers, exchanging pointers, to "deal" cards into "hands/groups" or to move them from one place to another. How you develop your own system will depend on how generic/flexible you want it to be, but the concept above is proven. Let me know (mystic.smeg@yahoo.co.uk) if you want me to send you my own version for your interest.na! //global deck values TCardVal = (cvBack, cvHK,cvHQ,cvHJ,cvH0,cvH9,cvH8, cvH7,cvH6,cvH5,cvH4,cvH3,cvH2,cvHA, cvDK,cvDQ,cvDJ,cvD0,cvD9,cvD8, cvD7,cvD6,cvD5,cvD4,cvD3,cvD2,cvDA, cvSK,cvSQ,cvSJ,cvS0,cvS9,cvS8, cvS7,cvS6,cvS5,cvS4,cvS3,cvS2,cvSA, cvCK,cvCQ,cvCJ,cvC0,cvC9,cvC8, cvC7,cvC6,cvC5,cvC4,cvC3,cvC2,cvCA);//TCard visual graphic control TCard = class(TCustomControl) private fFace: boolean; //face up/down (up=true or displayed, false=back of card) fSelected: boolean; //is card selected (True/False) fSelectable: boolean; //can card be selected (True/False) fCard: TBitmap; //render of card to canvas (back or front) fCardVal: TCardVal; //the cards value fImageList: TImageList; //card images (front/back/selected/ghosted etc) procedure SetSelected(const Value: boolean); procedure SetCardVal(const Value: TCardVal); procedure SetImageList(const Value: TImageList); //card suit a! nd value (see above) protected procedure GetImage; proc! edure Paint; override; procedure Resize; override; public constructor Create(aOwner: TComponent); override; destructor Destroy; override; published property FaceUp: boolean read fFace write fFace; property ImageList: TImageList read fImageList write SetImageList; property Selected: boolean read fSelected write SetSelected; property Selectable: boolean read fSelectable write fSelectable; property Card: TCardVal read fCardVal write SetCardVal;//default properties property Cursor; property DragCursor; property DragKind; property DragMode; property Height; property Hint; property Left; property Name; property ParentShowHint; property PopupMenu; property ShowHint; property Tag; property Top; property Visible; property Width;//default events property OnClick; property OnDblClick; property OnDragOver; property OnDragDrop; property OnEndDock; property OnEndDrag; property OnMouseDown; prop! erty OnMouseMove; property OnMouseUp; property OnResize; property OnStartDock; property OnStartDrag; end; {class TCard}//container for cards TCardContainer = class(TComponent) private fParent: TWinControl; fDeck: TImageList; fCards: TList; function GetCount: Integer; function GetItem(index: Integer): TCard; procedure AddCard(Card: TCard); overload; public constructor Create(aOwner: TComponent; LibName: string); reintroduce; destructor Destroy; override; procedure Clear; procedure AddCard(Card: TCardVal; FaceUp: boolean=False); overload; procedure DelCard(Index: Integer); function GetCard(Index: Integer): TCard; procedure LoadDeckImages(Path: string); procedure InitialiseDeck(Path: string); procedure LoadCardLibrary(LibName: string);//default property property Cards[index: Integer]: TCard read GetItem; default; published property Count: Integer read GetCount; property Parent: TWinControl read fParent writ! e fParent; end; {class TCardContainer}By the way, I also developed a c! ard library system to load/save/hold card images (part of the TCardContainer)....Show more
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment