Games Delphi

//18 adet SpeedButton ve bir Timer ile Puzzle Oyunu
//16 ve 17. speedbutton New ve Exit için, 18. ise son boş kare oluyor
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, Buttons, StdCtrls, ImgList;
type
TForm1 = class(TForm)
Panel1: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
...
SpeedButton16: TSpeedButton;
SpeedButton17: TSpeedButton;
SpeedButton18: TSpeedButton;
Timer1: TTimer;
procedure SpeedButton16Click(Sender: TObject);
procedure SpeedButton17Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SpeedButton15Click(Sender: TObject);
procedure SpeedButton18Click(Sender: TObject);
procedure SpeedButton14Click(Sender: TObject);
procedure SpeedButton13Click(Sender: TObject);
procedure SpeedButton9Click(Sender: TObject);
procedure SpeedButton10Click(Sender: TObject);
procedure SpeedButton11Click(Sender: TObject);
procedure SpeedButton12Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
procedure SpeedButton7Click(Sender: TObject);
procedure SpeedButton8Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
hucre=record
deger:integer;
bos:boolean;
end;
var
Form1: TForm1;
dizi:array [1..16] of hucre;
sayac:byte;
zaman:TTime;
implementation
{$R *.DFM}
procedure TForm1.SpeedButton16Click(Sender: TObject);
begin
close
end;
procedure tusdoldur;
var a:integer;
begin
repeat
a:=random(15)+1;
if dizi[a].bos then
begin
dizi[a].bos:=false;
dizi[a].deger:=sayac;
inc(sayac);
end
else tusdoldur;
until sayac=16;
end;
procedure TForm1.SpeedButton17Click(Sender: TObject);
var i:integer;
begin
sayac:=1;
dizi[1].bos:=true;
dizi[2].bos:=true;
dizi[3].bos:=true;
dizi[4].bos:=true;
dizi[5].bos:=true;
dizi[6].bos:=true;
dizi[7].bos:=true;
dizi[8].bos:=true;
dizi[9].bos:=true;
dizi[10].bos:=true;
dizi[11].bos:=true;
dizi[12].bos:=true;
dizi[13].bos:=true;
dizi[14].bos:=true;
dizi[15].bos:=true;
dizi[16].bos:=true;
tusdoldur;
SpeedButton1.Caption:=inttostr(dizi[1].deger);
SpeedButton2.Caption:=inttostr(dizi[2].deger);
SpeedButton3.Caption:=inttostr(dizi[3].deger);
SpeedButton4.Caption:=inttostr(dizi[4].deger);
SpeedButton5.Caption:=inttostr(dizi[5].deger);
SpeedButton6.Caption:=inttostr(dizi[6].deger);
SpeedButton7.Caption:=inttostr(dizi[7].deger);
SpeedButton8.Caption:=inttostr(dizi[8].deger);
SpeedButton9.Caption:=inttostr(dizi[9].deger);
SpeedButton10.Caption:=inttostr(dizi[10].deger);
SpeedButton11.Caption:=inttostr(dizi[11].deger);
SpeedButton12.Caption:=inttostr(dizi[12].deger);
SpeedButton13.Caption:=inttostr(dizi[13].deger);
SpeedButton14.Caption:=inttostr(dizi[14].deger);
SpeedButton15.Caption:=inttostr(dizi[15].deger);
SpeedButton18.Caption:=' ';
timer1.Enabled:=true;
zaman:=now();
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;Application.HintColor:=clyellow;
end;
procedure TForm1.SpeedButton15Click(Sender: TObject);
begin
if SpeedButton18.Caption=' ' then
begin
SpeedButton18.Caption:=SpeedButton15.Caption;
SpeedButton15.Caption:=' ';
end
else
if SpeedButton11.Caption=' ' then
begin
SpeedButton11.Caption:=SpeedButton15.Caption;
SpeedButton15.Caption:=' ';
end
else
if SpeedButton14.Caption=' ' then
begin
SpeedButton14.Caption:=SpeedButton15.Caption;
SpeedButton15.Caption:=' ';
end;
end;
procedure TForm1.SpeedButton18Click(Sender: TObject);
begin
if SpeedButton12.Caption=' ' then
begin
SpeedButton12.Caption:=SpeedButton18.Caption;
SpeedButton18.Caption:=' ';
end
else
if SpeedButton15.Caption=' ' then
begin
SpeedButton15.Caption:=SpeedButton18.Caption;
SpeedButton18.Caption:=' ';
end;
end;
//diğer tüm tuşlerın içini siz üstteki gibi doldurabilirsiniz, üstünde altında sağ ve solunda
//boş hücre var ise Caption'larını yer değiştir temel mantığı...
procedure TForm1.Timer1Timer(Sender: TObject);
begin
form1.Caption:='Puzzle - ' + TimeToStr(now-zaman);
if (SpeedButton1.Caption='1')and (SpeedButton2.Caption='2')
and(SpeedButton3.Caption='3')and (SpeedButton4.Caption='4')
and(SpeedButton5.Caption='5')and (SpeedButton6.Caption='6')
and(SpeedButton7.Caption='7')and (SpeedButton8.Caption='8')
and(SpeedButton9.Caption='9')and (SpeedButton10.Caption='10')
and(SpeedButton11.Caption='11')and (SpeedButton12.Caption='12')
and(SpeedButton13.Caption='13')and (SpeedButton14.Caption='14')
and(SpeedButton15.Caption='15')and (SpeedButton18.Caption=' ')
then begin
timer1.Enabled:=false;
form1.Caption:='Puzzle - ' + TimeToStr(now-zaman);
ShowMessage('Finished!..');
end;
end;
end.