Title: Puzzle Game (an example)
Question: just another game sample...
Answer:
unit Unit1;
interface
uses
 SysUtils, Types, Classes, Variants, QTypes, QGraphics, QControls, QForms,
 QDialogs, QStdCtrls, QMenus, QExtCtrls,windows, QButtons;
type
 Typboz = class(TForm)
 Image1: TImage;
 MainMenu1: TMainMenu;
 Dosyase1: TMenuItem;
 OpenDialog1: TOpenDialog;
 Panel1: TPanel;
 SpeedButton1: TSpeedButton;
 Timer1: TTimer;
 SpeedButton2: TSpeedButton;
 SpeedButton3: TSpeedButton;
 procedure Dosyase1Click(Sender: TObject);
 procedure FormKeyDown(Sender: TObject; var Key: Word;
 Shift: TShiftState);
 procedure Timer1Timer(Sender: TObject);
 procedure FormCreate(Sender: TObject);
 procedure SpeedButton1Click(Sender: TObject);
 procedure SpeedButton2Click(Sender: TObject);
 procedure SpeedButton3Click(Sender: TObject);
 private
 { Private declarations }
 public
 { Public declarations }
 seciliparca:timage;
 parcalar:array [0..15]of timage;
 bp:integer;
 end;
var
 ypboz: Typboz;
implementation
{$R *.xfm}
/////////paraal fonksiyonu parametreye gre o paray alyor.
function parcaal( resim:timage;yanparsay:integer;dikparsay:integer;hanpar:integer):tImage;
 var r:timage;
 alimt,verimt:trect;
begin ////bottom:alt taraf
r:=timage.Create(ypboz.Panel1); /////////////////paray oluturuyo
r.Width:=(resim.Width div yanparsay) ; //////genilii yampara saysna bl
r.Height:=resim.Height div dikparsay; ///////ykseklii dikpara saysn a bl
 verimt.Right:= resim.Width div yanparsay ; /////
 verimt.Bottom:= resim.Height div dikparsay;
 verimt.Left:=0;
 verimt.Top:=0;
alimt.Left:=r.Width*(hanpar mod yanparsay ); /////deneme yanlmaile zor buldum
 alimt.Right:=r.Width*(hanpar mod yanparsay)+r.Width;
 alimt.Top:= r.Height*(hanpar div dikparsay);
 alimt.Bottom:=r.Height*(hanpar div dikparsay)+r.Height ;
r.Canvas.CopyRect(verimt,resim.Canvas,alimt ); ////resmin gereken yerini kopyalayan fonksiyon
r.Parent:= ypboz.Panel1; ///paray panelin iine koyan fonksiyon
parcaal:=r; ////r yi dner
end;
procedure Typboz.Dosyase1Click(Sender: TObject);
var seciliresim:timage;
x,y,sec:integer;
begin
if opendialog1.Execute then
begin
 sec:=0;
image1.Picture.LoadFromFile(opendialog1.filename);
//////////////////
for x:=0 to panel1.Controlcount-1 do
begin
panel1.Controls[0].Free;
end;
for y:=0 to 3 do ////////dikey
for x:=0 to 3 do ///ve yatay iin
begin
seciliresim:=parcaal(image1,4,4,sec); //
seciliresim.Left:=(x)*(seciliresim.Width+10); ///gerekli yerine yeerletirio
seciliresim.Top:=(y)*(seciliresim.height+10);
parcalar[sec] :=seciliresim;
sec:=sec+1;
end;
 ///////////////////////////
end
else Application.Terminate;
seciliresim.Visible:=false; ////son paray grnmez yap
SpeedButton1.Visible:=True;
bp:=15; ////bo para 16 nc
panel1.Width:=image1.Width+40;
panel1.Height:=image1.Height+40;
end;
procedure Typboz.FormKeyDown(Sender: TObject; var Key: Word;
 Shift: TShiftState);
 var x,y,i,sec:integer;
 kazandi:boolean;
 seciliresim:timage;
 begin
 kazandi:=True;
if (key=4117) then ///yukar
begin
for i:=0 to 15 do
begin
 ////aadaki resmi kontrol edip
if (parcalar[i].Left=parcalar[15].Left) and (parcalar[i].Top=parcalar[15].top-(parcalar[i].Height+10) ) then
begin
parcalar[i].Top:= parcalar[i].Top+parcalar[i].Height+10;
parcalar[15].Top:=parcalar[15].Top-(parcalar[i].Height+10); ///yukar gnder
break;
end;
end;
end;
if (key=4115) then ///aa
begin
for i:=0 to 15 do
begin
if (parcalar[i].Left=parcalar[15].Left) and (parcalar[i].Top=parcalar[15].top+(parcalar[i].Height+10) ) then
begin
parcalar[i].Top:= parcalar[i].Top-(parcalar[i].Height+10);
parcalar[15].Top:=parcalar[15].Top+(parcalar[i].Height+10);
break;
end;
end;
end;
if (key =4114 ) then ////sola
begin
for i:=0 to 15 do
begin
if (parcalar[i].Left=parcalar[15].Left+parcalar[15].Width+10 ) and (parcalar[i].top=parcalar[15].top ) then
begin
parcalar[i].left:= parcalar[i].left-(parcalar[i].width+10);
parcalar[15].left:=parcalar[15].left+(parcalar[i].width+10);
break;
end;
end;
end;
if (key =4116 ) then ///saa
begin
for i:=0 to 15 do
begin
if (parcalar[i].Left=parcalar[15].Left-(parcalar[15].Width+10 )) and (parcalar[i].top=parcalar[15].top ) then
begin
parcalar[i].left:= parcalar[i].left+(parcalar[i].width+10);
parcalar[15].left:=parcalar[15].left-(parcalar[i].width+10);
break;
end;
end;
end;
sec:=0;
for y:=0 to 3 do
for x:=0 to 3 do
begin
seciliresim:=parcalar[sec];
if not (seciliresim.Left=(x)*(seciliresim.Width+10)) or
not (seciliresim.Top=(y)*(seciliresim.height+10)) then
kazandi:=false;
sec:=sec+1;
end;
if kazandi and not(timer1.Enabled) then
begin
showmessage('tebrikler oyunu basaryla kazandnz...');
parcalar[15].Visible:=true;
sec:=0;
for y:=0 to 3 do
for x:=0 to 3 do
begin
seciliresim:=parcalar[sec];
seciliresim.Left:=(x)*(seciliresim.Width); ///gerekli yerine yeerletirio
seciliresim.Top:=(y)*(seciliresim.height);
sec:=sec+1;
end;
 end;
 end;
procedure Typboz.Timer1Timer(Sender: TObject);
var c:word;
begin
c:= word(random(4)+4114) ;
self.FormKeyDown(self,c,[]); ////forma tua basma mesajlarn random gnder
end;
procedure Typboz.FormCreate(Sender: TObject);
begin
Dosyase1Click(self); ////alta doya se mensne kendisi tklyo
end;
procedure Typboz.SpeedButton1Click(Sender: TObject);
begin
timer1.Enabled:=true;/////kartrmay balaty
end;
procedure Typboz.SpeedButton2Click(Sender: TObject);
begin
timer1.Enabled:=false; /////kartrmay durduruyo
SpeedButton1.Visible:=False;
end;
procedure Typboz.SpeedButton3Click(Sender: TObject);
begin
Application.Terminate;
end;
end.