Home > Back-end >  Puzzle games,
Puzzle games,

Time:09-25

Make a puzzle game

CodePudding user response:

 unit main; 

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls FileCtrl, ExtCtrls Myunit, Spin, strUtils;

Type
TForm1=class (TForm)
FileList1: TFileListBox;
Image1: TImage;
Panel1: TPanel;
Procedure FormCreate (Sender: TObject);
Procedure FileList1DblClick (Sender: TObject);
Procedure FormShow (Sender: TObject);
Procedure FormDestroy (Sender: TObject);
Procedure FileList1KeyDown (Sender: TObject; Var Key Word;
Shift: TShiftState);

Procedure InitImage (Sender: TObject);
Procedure ImgClick (Sender: TObject);
Procedure EndOr ();
Procedure ClickXtime ();

Private
{Private declarations}
Public
{Public declarations}
end;

Var
Form1: TForm1;
MyImg: array [0.. 24] of TImage;//up to 6 *
NCount: integer;//define each row of the Image number
ClickOrNot: Boolean;//determine whether myImg been click
XClick yClick: integer;//the location of the record by clicking myImg
XBegin yBegin: array [0.. 24] of Integer;//save the initialization of each Image location
BCheckEndOr: Boolean;

Implementation

{$R *. DFM}

{form Creat, loading pictures, the default is the first}

Procedure TForm1. FormCreate (Sender: TObject);
The begin
The font:=screen. IconFont;
Filelist1. Directory:=ExtractFileDir (Application. ExeName) + '\ Image;

Filelist1. ItemIndex:=0;
Image1. Picture. LoadFromFile (filelist1 Directory + '\',
Filelist1. Items [filelist1 Itemindex]);
end;

{double-click the file name, loading the image into the Image1}

Procedure TForm1. FileList1DblClick (Sender: TObject);
The begin
Image1. Picture. LoadFromFile (filelist1 Directory + '\',
Filelist1. Items [filelist1 Itemindex]);
InitImage (Sender);//initialize the pictures, cutting

BCheckEndOr:=false;//in a simulated click, do not check whether the final
ClickXtime;//replace it for a little while, simulate click, make graphics random
BCheckEndOr:=true;//allow check final
end;

{generate dynamic array Image}

Procedure TForm1. FormShow (Sender: TObject);
Var
I, j, m: integer;
The begin
M:=0;
For I:=0 to 4 do
For j:=0 to 4 do
The begin
MyImg [m] :=TImage. Create (panel1);
MyImg [m]. Parent:=panel1;
='myImg myImg [m]. Name: "+ its (j + 1) + its (I + 1);//MyImg13 name
MyImg [m]. London: OnClick=form1. Imgclick;//all unified definition of myImg click event
M:=m + 1;
end;

InitImage (sender);//initialization, cutting Image1
ClickXtime;//random disturb myImg []
end;

Release myImg {}

Procedure TForm1. FormDestroy (Sender: TObject);
Var
I: integer;
The begin
For I:=0 to 24 do
MyImg [I] Free;
end;

{initializes the Image array, images from the Image1 25 cut into small pieces and assigned to myImg [] array}

Procedure TForm1. InitImage (Sender: TObject);
Var
I, j, m: integer;
Nwidth: integer;
The begin
NCount:=5;
Nwidth:=image1. Width div nCount; High/wide/myImg,

M:=0;
For I:=0 to do nCount - 1
For j:=0 to do nCount - 1
The begin
MyImg [m]. London: the Visible=true;
MyImg [m]. Left:=I * nwidth + 1;//+ 1 for the blank lines
MyImg [m]. Top:=j * nwidth + 1;
MyImg [m]. London: Width=nwidth;
MyImg [m]. Height:=nwidth;

{call their written copy Image function, convenient}
CopyRectImage1toImage2 (image1, myImg [m]. Left, myImg [m]. Top, myImg [m]. Left
+ nwidth,
MyImg [m]. Top + nwidth, myImg [m], 1, 1, + 1, nwidth nwidth + 1);

{save initialization position of each Image is used when the completion of the inspection whether puzzles, at EndOr () in the process of}
XBegin [m] :=myImg [m]. Left;
YBegin [m] :=myImg [m]. Top;

M:=m + 1;
end;

ClickOrNot:=false;//said myImg not been click
end;

{when myImg is click, click twice before and after being myImg swap}

Procedure TForm1. ImgClick (Sender: TObject);
Var
S: a string;
X, y: integer;//and then click the myImg left and top value
Nleft, ntop: integer;//used to exchange position using the temporary storage of variable
The begin
S:=rightstr ((sender as TImage). The Name, 2);//by click on the coordinates of myImg, characters

If ClickOrNot=false then//an odd number of clicks, and set it to a floating effect
The begin
(sender as TImage). Left:=(sender as TImage). Left - 2;
(sender as TImage). Top:=(sender as TImage). Top - 2;
First click on the coordinates of myImg} {save
XClick:=sti (leftstr (s, 1));
Yclick:=sti (rightstr (s, 1));
ClickOrNot:=true;//that first click has been completed, and click next time the swap
End
Else//to even clicks, swap
The begin
{the even hits the coordinates of myImg}
X:=sti (leftstr (s, 1));
Y:=sti (rightstr (s, 1));

{two myImg swap}
With panel1 do
The begin
Nleft:=TImage (FindComponent (' myImg + its (xclick) + its (yclick))). The Left;
TImage (FindComponent (' myImg + its (xclick) + its (yclick))). Left:=
TImage (FindComponent (' myImg + its (x) + its (y))). The left;
TImage (FindComponent (' myImg + its (x) + its (y))). Left:=nleft + 2;

Ntop:=TImage (FindComponent (' myImg + its (xclick) + its (yclick))). The top;
TImage (FindComponent (' myImg + its (xclick) + its (yclick))). The top:=
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull