Delphi Components Written - Poker Components

xiaoxiao2021-03-06  52

Delphi Components Writing - Poker Components Hunter read a lot about the writing of poker components online, mostly calling the cards.dll under Windows / System32. In fact, if we do not call these functions, it is also a good poker component. The specific steps are as follows: 1, first do a bitmap file, in line with the following format, all the playing cards are equally sized, each color row, from A to K, colored, red peach, square, plum blossom arrangement . If you don't want to export from the cardres.dll under QQ Game, this component is the bitmap of QQ GAME. Then create a text file named card.rc, the content is Card Bitmap "card.bmp", then compile with Brcc32.exe into card.res. 2, the poker component inherits from TGRAPHICCONTROL. Can be used as a single playing card. Its main attribute has cardid, is the number of its brand, Faceup is the attribute of the poker front or down or down. LEFT, TOP, WIDTH, Height, Visual and other properties are inherited to TGRAPHICCONTROL, just need to explain it. The source code is as follows:

unit uCard; // unit: visual component - // assembly of cards: Tao // E_Mail: hunto@163.com// Date: 2004.12.7 // Review Date: 2004.12.8

Interface

Uses Windows, Messages, Classes, Graphics, Controls, Dialogs

Type // Puke's color definition, black peach, red heart, square, plum tcardsuit = (CSSPADE, CSHEART, CSCLUB, CSDIAMOND); TCARD = Class (TgraphicControl) // Poker Component FcardId: cardinal; // Poker The number, 0-51 is 1-k, 52 for each flower, 53 Xiao Wang ffaceup: bool; // Whether positive face up procedure setcardid (ID: cardinal); // Set the number of Poker SetFaceup (flag) : Bool); // Set whether to face up in function getValue: integer; // Get a point of Poker GetSuit: tcardsuit; // Get a Poker's Sticewler Protected Procedure Paint; Override; / / Poker Public Contructor Create (AOwner: TComponent); overload; override; // constructor constructor Create (AOwner: TComponent; Id: Cardinal); overload; procedure SetCard (Suit: TCardSuit; Value: Cardinal); // set the number of cards published property CardId: Cardinal read FCardId write SetCardId; // number of cards property faceUp: bool read FFaceUp write SetFaceUp default False; // face up property Value: integer read GetValue; // poker points, read-only property Suit: TCardSuit read GetSuit ; // Poker's color, read-only Property OnClick; / / Click Property OndblClick; // Double click End; Implementat ION {$ r card.res} {tcard} var cardmap: Tbitmap; // Poker's graphics, get constructor tcard.create (Aowner: Tcomponent) from Card.Res; begin inherited; // If the parent control is WindowControl Set its Parent property if aowner is twinControl dam.parent: = twinControl (aowner); width: = cardmap.width Div 14; // Get the width of the playing card Height: = cardmap.height Div 4; // Get a playing card Height faceup: = false; // default playing card facing down;

Constructor tcard.create (Aowner: Tcomponent; ID: cardinal); begin create (aowner); cardid: = ID; // Setting the numbering of the poker card;

Procedure tcard.setcardid (ID: cardinal); begin if id <54 Then fcardid: = ID; // Setting the number of Poker's number Paint; // Researchers the Poker End;

Procedure tcard.setcard (suit: tcardsuit; value: cardinal); begin dec (value); cardid: = value shl 2 cardinal (suit) and 3; // Set the number of poker cards and redraw over; procedure tcard.paint; // Painting Poker VAR X, Y, TMP: Integer; Begin if not assigned (parent) THENE EXIT; // Directly exited directly to avoid error inherited; if faceup dam: = CardID // If face DPRK, draw the front ELSE TMP: = 54; // Anti-painting back x: = (TMP SHR 2) * width; // The poker card is in the position of the horizontal coordinate Y: = (TMP and 3) * Height; // This playing card is placed in the position of the position Bitblt (canvas.handle, 0, 0, width, height, // draw cardmap.canvas.handle, x, y, srcopy);

Procedure tcard.setfaceup (flag: bool); // Set the card face up or down to begin ffaceup: = flag; paint; // Heavy painting END;

Function TCard.getValue: Integer; Begin Result: = CardID SHR 2; // Get the value inc (Result);

Function tcard.get.getsuit: tcardsuit; begin result: = tcardsuit (cardid and 3); // Get the color of the card;

Initialization // Unit Initialization CardMap: = Tbitmap.create; // Creating Bitchart CardMap.LoadFromResourceName (Hinstance, 'Card'); // Import Finalization CardMap.Free; // Clear bitmap END from the resource.

转载请注明原文地址:https://www.9cbs.com/read-83118.html

New Post(0)