unit G1U;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TfrmMainForm = class(TForm)
lblMessage4User: TLabel;
lblColumn1: TLabel;
lblColumn2: TLabel;
lblColumn3: TLabel;
procedure FormCreate(Sender: TObject);
procedure lblColumn1MouseLeave(Sender: TObject);
procedure lblColumn1MouseEnter(Sender: TObject);
procedure lblColumn1Click(Sender: TObject);
procedure lblColumn2Click(Sender: TObject);
procedure lblColumn3Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
Procedure CardIndexToCardName;
Procedure RandomizeCard;
Function NotZeroRandomInt: Integer;
procedure CreatePanelAndImage;
Procedure PresentRandomCard;
Procedure ShowTheCard(Column: Integer);
procedure FreeControls(Var Image: TImage; Var Panel: TPanel);
public
procedure StartGame;
{ Public declarations }
end;
var
frmMainForm: TfrmMainForm;
implementation
uses frmAnswerU;
{$R *.dfm}
{$R CardBitMapRes.res}
var
CardNameByIndex, RandomizedCard: array[1..52] of String;
CardInColumn1, CardInColumn2, CardInColumn3: array[1..17] of String;
LevelCount: Integer;
Image: array[1..51] of TImage;
Panel: array[1..51] of TPanel;
Const
StartString= 'Pilih 1 kartu dalam pikiranmu dan klik kolom dimana kartu berada:';
ContinueString= 'Sekarang klik lagi kolom dimana kartu yang anda pilih itu berada:';
procedure TfrmMainForm.FormCreate(Sender: TObject);
begin
StartGame;
end;
procedure TfrmMainForm.CardIndexToCardName;
var
I: Integer;
begin
For I:= 1 To 9 do
CardNameByIndex[I]:= IntToStr(I+1)+'_Pic';
CardNameByIndex[10]:= 'J_Pic';
CardNameByIndex[11]:= 'Q_Pic';
CardNameByIndex[12]:= 'K_Pic';
CardNameByIndex[13]:= 'A_Pic';
For I:= 1 To 9 do
CardNameByIndex[I+13]:= IntToStr(I+1)+'_Del';
CardNameByIndex[13+10]:= 'J_Del';
CardNameByIndex[13+11]:= 'Q_Del';
CardNameByIndex[13+12]:= 'K_Del';
CardNameByIndex[13+13]:= 'A_Del';
For I:= 1 To 9 do
CardNameByIndex[I+26]:= IntToStr(I+1)+'_Geshniz';
CardNameByIndex[13+13+10]:= 'J_Geshniz';
CardNameByIndex[13+13+11]:= 'Q_Geshniz';
CardNameByIndex[13+13+12]:= 'K_Geshniz';
CardNameByIndex[13+13+13]:= 'A_Geshniz';
For I:= 1 To 9 do
CardNameByIndex[I+39]:= IntToStr(I+1)+'_Khesht';
CardNameByIndex[13+13+13+10]:= 'J_Khesht';
CardNameByIndex[13+13+13+11]:= 'Q_Khesht';
CardNameByIndex[13+13+13+12]:= 'K_Khesht';
CardNameByIndex[13+13+13+13]:= 'A_Khesht';
end;
procedure TfrmMainForm.RandomizeCard;
Var
CardIndex, I, J: Integer;
CheckArray: array of Integer;
IntIsInArray: Boolean;
begin
I:=0;
IntIsInArray:= False;
While I<>High(RandomizedCard) do
begin
CardIndex:=NotZeroRandomInt;
For J:= 0 to High(CheckArray) do
if CheckArray[J]= CardIndex then
begin
IntIsInArray:= True;
Break;
end;
if IntIsInArray then
begin
IntIsInArray:=False;
Continue;
end;
Inc(I);
SetLength(CheckArray,I);
CheckArray[I-1]:= CardIndex;
RandomizedCard[I]:= CardNameByIndex[CardIndex];
end;
end;
function TfrmMainForm.NotZeroRandomInt: Integer;
Var
RandomInt: Integer;
begin
repeat
RandomInt:= Random(53);
until RandomInt <> 0;
Result:= RandomInt;
end;
procedure TfrmMainForm.PresentRandomCard;
var
I, J: Integer;
begin
J:=1;
I:=1;
While I<51 do
begin
CardInColumn1[J]:= RandomizedCard[I];
CardInColumn2[J]:= RandomizedCard[I+1];
CardInColumn3[J]:= RandomizedCard[I+2];
I:= I+3;
Inc(J);
end;
J:=0;
For I:= 1 to 17 do
Begin
Inc(J);
Image[J].Picture.Bitmap.LoadFromResourceName(HInstance,CardInColumn1[I]);
Panel[J].Left:=100;
Panel[J].Top:= I*25;
end;
For I:= 1 to 17 do
Begin
Inc(J);
Image[J].Picture.Bitmap.LoadFromResourceName(HInstance,CardInColumn2[I]);
Panel[J].Left:=200;
Panel[J].Top:= I*25;
end;
For I:= 1 to 17 do
Begin
Inc(J);
Image[J].Picture.Bitmap.LoadFromResourceName(HInstance,CardInColumn3[I]);
Panel[J].Left:=300;
Panel[J].Top:= I*25;
end;
end;
procedure TfrmMainForm.lblColumn1MouseLeave(Sender: TObject);
begin
TLabel(Sender).Font.Color:= clBlue;
end;
procedure TfrmMainForm.lblColumn1MouseEnter(Sender: TObject);
begin
TLabel(Sender).Font.Color:= clPurple;
end;
procedure TfrmMainForm.lblColumn1Click(Sender: TObject);
var
I: Integer;
begin
For I:=1 To 51 do
Begin
if I<=17 then
RandomizedCard[I]:= CardInColumn2[I];
if (I>17) and (I<=17+17) then
RandomizedCard[I]:= CardIncolumn1[I-17];
if (I>17+17) and (I<=17+17+17) then
RandomizedCard[I]:= CardInColumn3[I-17-17];
end;
Inc(LevelCount);
if LevelCount=4 then
begin
ShowTheCard(1);
Exit;
end;
PresentRandomCard;
lblMessage4User.Caption:= ContinueString;
lblMessage4User.Left:= 75;
end;
procedure TfrmMainForm.lblColumn2Click(Sender: TObject);
var
I: Integer;
begin
For I:=1 To 51 do
begin
if I<=17 then
RandomizedCard[I]:= CardInColumn1[I];
if (I>17) and (I<=17+17) then
RandomizedCard[I]:= CardIncolumn2[I-17];
if (I>17+17) and (I<=17+17+17) then
RandomizedCard[I]:= CardInColumn3[I-17-17];
end;
Inc(LevelCount);
if LevelCount=4 then
begin
ShowTheCard(2);
Exit;
end;
PresentRandomCard;
lblMessage4User.Caption:= ContinueString;
lblMessage4User.Left:= 75;
end;
procedure TfrmMainForm.lblColumn3Click(Sender: TObject);
var
I: 1..51;
begin
For I:=1 To 51 do
begin
if I<=17 then
RandomizedCard[I]:= CardInColumn1[I];
if (I>17) and (I<=17+17) then
RandomizedCard[I]:= CardIncolumn3[I-17];
if (I>17+17) and (I<=17+17+17) then
RandomizedCard[I]:= CardInColumn2[I-17-17];
end;
Inc(LevelCount);
if LevelCount=4 then
begin
ShowTheCard(3);
Exit;
end;
PresentRandomCard;
lblMessage4User.Caption:= ContinueString;
lblMessage4User.Left:= 75;
end;
procedure TfrmMainForm.ShowTheCard(Column: Integer);
begin
case Column of
1: frmAnswer.imgAnswer.Picture.Bitmap.LoadFromResourceName(HInstance,CardInColumn1[9]);
2: frmAnswer.imgAnswer.Picture.Bitmap.LoadFromResourceName(HInstance,CardInColumn2[9]);
3: frmAnswer.imgAnswer.Picture.Bitmap.LoadFromResourceName(HInstance,CardInColumn3[9]);
end;
frmAnswer.ShowModal;
end;
procedure TfrmMainForm.FreeControls(var Image: TImage; var Panel: TPanel);
begin
Image.Free;
Panel.Free;
end;
procedure TfrmMainForm.CreatePanelAndImage;
var
I: 1..51;
begin
For I:=1 To 51 do
begin
Panel[I]:= TPanel.Create(Self);
Panel[I].Parent:= frmMainForm;
Panel[I].BevelInner:= bvLowered;
Panel[I].AutoSize:= True;
Image[I]:= TImage.Create(self);
Image[I].Parent:= Panel[I];
Image[I].AutoSize:= True;
end;
end;
procedure TfrmMainForm.StartGame;
begin
Randomize;
LevelCount:=0;
lblMessage4User.Caption:= StartString;
lblMessage4User.Left:= 16;
CardIndexToCardName;
RandomizeCard;
CreatePanelAndImage;
PresentRandomCard;
end;
procedure TfrmMainForm.FormClose(Sender: TObject;
var Action: TCloseAction);
var
I: 1..51;
begin
For I:= 1 to 51 do
Begin
Image[I].Free;
Panel[I].Free;
end;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TfrmMainForm = class(TForm)
lblMessage4User: TLabel;
lblColumn1: TLabel;
lblColumn2: TLabel;
lblColumn3: TLabel;
procedure FormCreate(Sender: TObject);
procedure lblColumn1MouseLeave(Sender: TObject);
procedure lblColumn1MouseEnter(Sender: TObject);
procedure lblColumn1Click(Sender: TObject);
procedure lblColumn2Click(Sender: TObject);
procedure lblColumn3Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
Procedure CardIndexToCardName;
Procedure RandomizeCard;
Function NotZeroRandomInt: Integer;
procedure CreatePanelAndImage;
Procedure PresentRandomCard;
Procedure ShowTheCard(Column: Integer);
procedure FreeControls(Var Image: TImage; Var Panel: TPanel);
public
procedure StartGame;
{ Public declarations }
end;
var
frmMainForm: TfrmMainForm;
implementation
uses frmAnswerU;
{$R *.dfm}
{$R CardBitMapRes.res}
var
CardNameByIndex, RandomizedCard: array[1..52] of String;
CardInColumn1, CardInColumn2, CardInColumn3: array[1..17] of String;
LevelCount: Integer;
Image: array[1..51] of TImage;
Panel: array[1..51] of TPanel;
Const
StartString= 'Pilih 1 kartu dalam pikiranmu dan klik kolom dimana kartu berada:';
ContinueString= 'Sekarang klik lagi kolom dimana kartu yang anda pilih itu berada:';
procedure TfrmMainForm.FormCreate(Sender: TObject);
begin
StartGame;
end;
procedure TfrmMainForm.CardIndexToCardName;
var
I: Integer;
begin
For I:= 1 To 9 do
CardNameByIndex[I]:= IntToStr(I+1)+'_Pic';
CardNameByIndex[10]:= 'J_Pic';
CardNameByIndex[11]:= 'Q_Pic';
CardNameByIndex[12]:= 'K_Pic';
CardNameByIndex[13]:= 'A_Pic';
For I:= 1 To 9 do
CardNameByIndex[I+13]:= IntToStr(I+1)+'_Del';
CardNameByIndex[13+10]:= 'J_Del';
CardNameByIndex[13+11]:= 'Q_Del';
CardNameByIndex[13+12]:= 'K_Del';
CardNameByIndex[13+13]:= 'A_Del';
For I:= 1 To 9 do
CardNameByIndex[I+26]:= IntToStr(I+1)+'_Geshniz';
CardNameByIndex[13+13+10]:= 'J_Geshniz';
CardNameByIndex[13+13+11]:= 'Q_Geshniz';
CardNameByIndex[13+13+12]:= 'K_Geshniz';
CardNameByIndex[13+13+13]:= 'A_Geshniz';
For I:= 1 To 9 do
CardNameByIndex[I+39]:= IntToStr(I+1)+'_Khesht';
CardNameByIndex[13+13+13+10]:= 'J_Khesht';
CardNameByIndex[13+13+13+11]:= 'Q_Khesht';
CardNameByIndex[13+13+13+12]:= 'K_Khesht';
CardNameByIndex[13+13+13+13]:= 'A_Khesht';
end;
procedure TfrmMainForm.RandomizeCard;
Var
CardIndex, I, J: Integer;
CheckArray: array of Integer;
IntIsInArray: Boolean;
begin
I:=0;
IntIsInArray:= False;
While I<>High(RandomizedCard) do
begin
CardIndex:=NotZeroRandomInt;
For J:= 0 to High(CheckArray) do
if CheckArray[J]= CardIndex then
begin
IntIsInArray:= True;
Break;
end;
if IntIsInArray then
begin
IntIsInArray:=False;
Continue;
end;
Inc(I);
SetLength(CheckArray,I);
CheckArray[I-1]:= CardIndex;
RandomizedCard[I]:= CardNameByIndex[CardIndex];
end;
end;
function TfrmMainForm.NotZeroRandomInt: Integer;
Var
RandomInt: Integer;
begin
repeat
RandomInt:= Random(53);
until RandomInt <> 0;
Result:= RandomInt;
end;
procedure TfrmMainForm.PresentRandomCard;
var
I, J: Integer;
begin
J:=1;
I:=1;
While I<51 do
begin
CardInColumn1[J]:= RandomizedCard[I];
CardInColumn2[J]:= RandomizedCard[I+1];
CardInColumn3[J]:= RandomizedCard[I+2];
I:= I+3;
Inc(J);
end;
J:=0;
For I:= 1 to 17 do
Begin
Inc(J);
Image[J].Picture.Bitmap.LoadFromResourceName(HInstance,CardInColumn1[I]);
Panel[J].Left:=100;
Panel[J].Top:= I*25;
end;
For I:= 1 to 17 do
Begin
Inc(J);
Image[J].Picture.Bitmap.LoadFromResourceName(HInstance,CardInColumn2[I]);
Panel[J].Left:=200;
Panel[J].Top:= I*25;
end;
For I:= 1 to 17 do
Begin
Inc(J);
Image[J].Picture.Bitmap.LoadFromResourceName(HInstance,CardInColumn3[I]);
Panel[J].Left:=300;
Panel[J].Top:= I*25;
end;
end;
procedure TfrmMainForm.lblColumn1MouseLeave(Sender: TObject);
begin
TLabel(Sender).Font.Color:= clBlue;
end;
procedure TfrmMainForm.lblColumn1MouseEnter(Sender: TObject);
begin
TLabel(Sender).Font.Color:= clPurple;
end;
procedure TfrmMainForm.lblColumn1Click(Sender: TObject);
var
I: Integer;
begin
For I:=1 To 51 do
Begin
if I<=17 then
RandomizedCard[I]:= CardInColumn2[I];
if (I>17) and (I<=17+17) then
RandomizedCard[I]:= CardIncolumn1[I-17];
if (I>17+17) and (I<=17+17+17) then
RandomizedCard[I]:= CardInColumn3[I-17-17];
end;
Inc(LevelCount);
if LevelCount=4 then
begin
ShowTheCard(1);
Exit;
end;
PresentRandomCard;
lblMessage4User.Caption:= ContinueString;
lblMessage4User.Left:= 75;
end;
procedure TfrmMainForm.lblColumn2Click(Sender: TObject);
var
I: Integer;
begin
For I:=1 To 51 do
begin
if I<=17 then
RandomizedCard[I]:= CardInColumn1[I];
if (I>17) and (I<=17+17) then
RandomizedCard[I]:= CardIncolumn2[I-17];
if (I>17+17) and (I<=17+17+17) then
RandomizedCard[I]:= CardInColumn3[I-17-17];
end;
Inc(LevelCount);
if LevelCount=4 then
begin
ShowTheCard(2);
Exit;
end;
PresentRandomCard;
lblMessage4User.Caption:= ContinueString;
lblMessage4User.Left:= 75;
end;
procedure TfrmMainForm.lblColumn3Click(Sender: TObject);
var
I: 1..51;
begin
For I:=1 To 51 do
begin
if I<=17 then
RandomizedCard[I]:= CardInColumn1[I];
if (I>17) and (I<=17+17) then
RandomizedCard[I]:= CardIncolumn3[I-17];
if (I>17+17) and (I<=17+17+17) then
RandomizedCard[I]:= CardInColumn2[I-17-17];
end;
Inc(LevelCount);
if LevelCount=4 then
begin
ShowTheCard(3);
Exit;
end;
PresentRandomCard;
lblMessage4User.Caption:= ContinueString;
lblMessage4User.Left:= 75;
end;
procedure TfrmMainForm.ShowTheCard(Column: Integer);
begin
case Column of
1: frmAnswer.imgAnswer.Picture.Bitmap.LoadFromResourceName(HInstance,CardInColumn1[9]);
2: frmAnswer.imgAnswer.Picture.Bitmap.LoadFromResourceName(HInstance,CardInColumn2[9]);
3: frmAnswer.imgAnswer.Picture.Bitmap.LoadFromResourceName(HInstance,CardInColumn3[9]);
end;
frmAnswer.ShowModal;
end;
procedure TfrmMainForm.FreeControls(var Image: TImage; var Panel: TPanel);
begin
Image.Free;
Panel.Free;
end;
procedure TfrmMainForm.CreatePanelAndImage;
var
I: 1..51;
begin
For I:=1 To 51 do
begin
Panel[I]:= TPanel.Create(Self);
Panel[I].Parent:= frmMainForm;
Panel[I].BevelInner:= bvLowered;
Panel[I].AutoSize:= True;
Image[I]:= TImage.Create(self);
Image[I].Parent:= Panel[I];
Image[I].AutoSize:= True;
end;
end;
procedure TfrmMainForm.StartGame;
begin
Randomize;
LevelCount:=0;
lblMessage4User.Caption:= StartString;
lblMessage4User.Left:= 16;
CardIndexToCardName;
RandomizeCard;
CreatePanelAndImage;
PresentRandomCard;
end;
procedure TfrmMainForm.FormClose(Sender: TObject;
var Action: TCloseAction);
var
I: 1..51;
begin
For I:= 1 to 51 do
Begin
Image[I].Free;
Panel[I].Free;
end;
end;
end.
0 komentar:
Post a Comment