unit UCard;
interface
uses
SysUtils, Classes, Controls, Graphics, Dialogs;
type
TCardType = (CTcard, CTjoker, CTnext_player);
TCardValue = (CVblue_01, CVblue_02, CVblue_03, CVblue_04, CVblue_05, CVblue_06,
CVblue_07, CVblue_08, CVblue_09, CVblue_10, CVblue_11, CVblue_12,
CVyellow_01, CVyellow_02, CVyellow_03, CVyellow_04, CVyellow_05, CVyellow_06,
CVyellow_07, CVyellow_08, CVyellow_09, CVyellow_10, CVyellow_11, CVyellow_12,
CVgreen_01, CVgreen_02, CVgreen_03, CVgreen_04, CVgreen_05, CVgreen_06,
CVgreen_07, CVgreen_08, CVgreen_09, CVgreen_10, CVgreen_11, CVgreen_12,
CVred_01, CVred_02, CVred_03, CVred_04, CVred_05, CVred_06,
CVred_07, CVred_08, CVred_09, CVred_10, CVred_11, CVred_12);
TJokerValue = (JVblue_01, JVblue_02, JVblue_03, JVblue_04, JVblue_05, JVblue_06,
JVblue_07, JVblue_08, JVblue_09, JVblue_10, JVblue_11, JVblue_12,
JVyellow_01, JVyellow_02, JVyellow_03, JVyellow_04, JVyellow_05, JVyellow_06,
JVyellow_07, JVyellow_08, JVyellow_09, JVyellow_10, JVyellow_11, JVyellow_12,
JVgreen_01, JVgreen_02, JVgreen_03, JVgreen_04, JVgreen_05, JVgreen_06,
JVgreen_07, JVgreen_08, JVgreen_09, JVgreen_10, JVgreen_11, JVgreen_12,
JVred_01, JVred_02, JVred_03, JVred_04, JVred_05, JVred_06,
JVred_07, JVred_08, JVred_09, JVred_10, JVred_11, JVred_12,
JVall);
type
TCustomCard =
class(TGraphicControl)
private
{ Private declarations }
fCardOpen : Boolean;
fImageDirectory, fCardImagePath :
String;
fCardImage : TBitmap;
const CardFileNames :
Array[0..50]
of String = ('
blue_01.bmp','
blue_02.bmp','
blue_03.bmp','
blue_04.bmp','
blue_05.bmp','
blue_06.bmp',
'
blue_07.bmp','
blue_08.bmp','
blue_09.bmp','
blue_10.bmp','
blue_11.bmp','
blue_12.bmp',
'
yellow_01.bmp','
yellow_02.bmp','
yellow_03.bmp','
yellow_04.bmp','
yellow_05.bmp','
yellow_06.bmp',
'
yellow_07.bmp','
yellow_08.bmp','
yellow_09.bmp','
yellow_10.bmp','
yellow_11.bmp','
yellow_12.bmp',
'
green_01.bmp','
green_02.bmp','
green_03.bmp','
green_04.bmp','
green_05.bmp','
green_06.bmp',
'
green_07.bmp','
green_08.bmp','
green_09.bmp','
green_10.bmp','
green_11.bmp','
green_12.bmp',
'
red_01.bmp','
red_02.bmp','
red_03.bmp','
red_04.bmp','
red_05.bmp','
red_06.bmp',
'
red_07.bmp','
red_08.bmp','
red_09.bmp','
red_10.bmp','
red_11.bmp.bmp','
red_12.bmp',
'
joker.bmp','
next_player.bmp','
backside.bmp');
procedure setCardOpen(aCardOpen : Boolean);
protected
{ Protected declarations }
procedure Paint;
virtual;
abstract;
procedure SetCardImage;
virtual;
abstract;
public
{ Public declarations }
property CardOpen : Boolean
read fCardOpen
write setCardOpen;
property ImageDirectory :
String read fImageDirectory;
constructor Create(aOwner : TComponent);
override;
destructor Destroy;
override;
published
{ Published declarations }
end;
type
TCard =
class(TCustomCard)
private
{ Private declarations }
fCardValue : TCardValue;
protected
{ Protected declarations }
procedure Paint;
override;
procedure SetCardImage;
override;
public
{ Public declarations }
property CardValue : TCardValue
read fCardValue;
procedure Initialize(aImageDirectory :
String; aCardValue : TCardValue; aCardOpen : Boolean = false);
published
{ Published declarations }
end;
implementation
{
********************************************************************************
***********************************CUSTOMCARD***********************************
********************************************************************************
}
procedure TCustomCard.setCardOpen(aCardOpen : Boolean);
Begin
if aCardOpen <> fCardOpen
Then
Begin
fCardOpen := aCardOpen;
SetCardImage;
Invalidate;
End;
End;
constructor TCustomCard.Create(aOwner : TComponent);
Begin
inherited Create(aOwner);
Width := 57;
Height := 86;
fCardImage := TBitmap.Create;
End;
destructor TCustomCard.Destroy;
Begin
inherited Destroy;
FreeAndNil(fCardImage);
End;
{
********************************************************************************
**************************************CARD**************************************
********************************************************************************
}
procedure TCard.Paint;
Begin
Canvas.Draw(0,0,fCardImage);
End;
procedure TCard.SetCardImage;
Begin
If fCardOpen
Then
fCardImagePath := fImageDirectory + CardFileNames[Integer(fCardValue)]
Else
fCardImagePath := fImageDirectory + CardFileNames[50];
fCardImage.LoadFromFile(fCardImagePath);
End;
procedure TCard.Initialize(aImageDirectory :
String; aCardValue : TCardValue; aCardOpen : Boolean = false);
Begin
If aImageDirectory <> fImageDirectory
Then
fImageDirectory := IncludeTrailingBackslash(aImageDIrectory);
If aCardValue <> fCardValue
Then
fCardValue := aCardValue;
If aCardOpen <> fCardOpen
Then
fCardOpen := aCardOpen;
SetCardImage;
Invalidate;
End;
end.