Poker Components II - Write a Poker Component using Cards.dll

xiaoxiao2021-03-06  47

Write and use of poker components

The last time I wrote a poker component made by bitmap. I changed this time, try using Cards.dll to do one person. This component has no size king, and the speed is more slower than the previous. However, this component can set a lot of backgrounds, and its width and length can be changed.

Cards.dll feature is very complete, we use it here to draw the front and opposite side of the playing card, other people are not used. If you are interested in these uses, you can go to Microsoft's MSDN to see it, it is no longer coming. Please see below:

UNIT Card;

// Project: 2 of the poker assembly

// Author: Huang Tao

// message: hunto@163.com

/ / Date: 2004.12.16

// This component calls Windows Cards.dll if the system is not 2000 / XP will not be available.

Interface

Uses

SYSUTILS, CLASS, Controls, Windows

Type

Tcardsuit = (CSClub, csdiamond, csheart, csspade); // color

TCARD = Class (TGRAPHICCONTROL)

Private

FFaceup: bool; // Is it faced?

FCardId: cardinal; // Poker number

FBackID: cardinal; // Rear pattern

Procedure setCardId (ID: cardinal); // Set the number of poker cards

Procedure setup (Faceup: bool); // Set whether it is facing

Procedure setBackID (const value: cardinal); // Set back pattern of poker cards

Function getsuit: tcardsuit; // Get the color of the playing card

Function getValue: cardinal; // Get the number of poker cards

protected

Procedure paint; override; // draw poker card

public

Constructor Create (Aowner: Tcomponent); OVERRIDE;

Procedure setcard (Suit: tcardsuit; value: cardinal); // Set the number of poker cards

Published

Property CardID: Cardinal Read Fcardid Write SetCardID; // Poker Number

Property Faceup: BOOL Read FFaceup Write SetFaceup Default False; // Does Positive

Property Backid: Cardinal Read FBackid Write SetBackID Default 0; // Background Patter

Property Suit: Tcardsuit Read GetSuit; // Colors, read-only

Property value: cardinal read getValue; // points, read-only

Property onclick; // Click Event

Property Ondblclick; // Double-click Event

END;

PROCEDURE register;

IMPLEMENTATION

// Unit variable, default playing card width and length

Var CardWidth, CardHeight: Integer;

// First Mohua DLL

Procedure Cdtinit (Var Width, Height: Integer; stdcall; external 'cards.dll';

// End DLL call

Procedure cdTerm; stdcall; external 'cards.dll';

/ / Painting Poker Functions

Procedure Cdtdrawext (ADC: HDC; Left, Top, Width, Height: cardinal; cardid: cardinal; mode: integer; bkgnd: integer; stdcall; exTernal 'cards.dll';

Procedure register; // Registration component

Begin

RegisterComponents ('Samples', [TCard]);

END;

{Tcard}

Constructor tcard.create (Aowner: Tcomponent);

Begin

inherited;

If Aowner Is TwinControl The Parent: = TWINCONTROL (AOWNER);

Faceup: = false; // Set the default to the poker face

Width: = cardwidth; // Set the default playing card width, modify

Height: = CardHeight; // Set the default playing card height, can be modified

END;

Function tcard.get.getsuit: tcardsuit;

Begin

Result: = tcardsuit (Cardid and 3); // Get colorful color of the playing card

END;

Function TCard.get.getValue: cardinal

Begin

Result: = CardID SHR 2 1; // Get the value of the playing card

END;

Procedure tcard.paint; // Painting Poker

VAR ID, CMD: cardinal

Begin

If not assigned (parent) THEN EXIT; // If the parent component is not defined, exit directly

If faceup kilopsis

Begin

ID: = CardID;

CMD: = 0;

end

ELSE // Back face

Begin

ID: = backid 54;

CMD: = 1;

END;

CDTDrawext (canvas.handle, 0,0, width, height, id, cmd, 0);

END;

Procedure tcard.setbackid (const value: cardinal); // Set the pattern of the background, take effect at the time

Begin

IF (Value <12) and (fbackid <> value) THEN FBACKID: = value

IF not faceup kiln.

END;

Procedure tcard.setcard (suit: tcardsuit; value: cardinal);

Begin // Set the playing card number, then redraw

Dec (Value);

CardID: = (Value SHL 2) Or Cardinal (SUIT);

END;

Procedure tcard.setcardId (ID: cardinal);

Begin // Set the playing card number, then redraw

IF ID <52 THEN FCARDID: = ID;

If Faceup Then Paint; // The front face is heavy

END;

Procedure tcard.setfaceup (Faceup: bool);

Begin // Set back or on the front

FFaceup: = Faceup;

Paint;

END;

INITIALIZATION

CDTINIT (CardWidth, CardHeight); // Initialization DLL

Finalization

CDTTERM; // End of call

End.

Component's use

Procedure TFORM1.BUTTON2CLICK (Sender: TOBJECT); VAR i: integer;

K: tcardsuit;

Begin

// Poker Component Code Demo

Fork: = low (tcardsuit) to high (tcardsuit) do // draws a poker card in each color

For i: = 1 to 13 do // Picture of various points of the number of points from left to right

With tcard.create (Self) DO

Begin

SetCard (k, i); // Settings a playing card number

LEFT: = (i-1) * 15; // Set the left force position

Top: = ORD (K) * Height; // Set top position

Faceup: = true; // front face up

END;

For i: = 0 to 11 do // draws 12 background patterns

With tcard.create (Self) DO

Begin

Backid: = i; // Set background pattern

Top: = (i and 3) * Height; // Set top position

Left: = (i shr 2) * width 180 width; // Set the left position

END;

END;

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

New Post(0)