Mega Code Archive

 
Categories / Delphi / Examples
 

BALLSGAME with very tiny code!!

Title: BALLSGAME with very tiny code!! Question: How to make graphical games using delphi, the ide. The purpose is how to use yo learn the gdi functions etc. And the source is very short... Answer: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, ImgList, ComCtrls, ToolWin, StdCtrls, Buttons,math; type TForm1 = class(TForm) ToolBar1: TToolBar; ImageList1: TImageList; SpeedButton1: TSpeedButton; SpeedButton2: TSpeedButton; Label1: TLabel; ToolButton1: TToolButton; procedure FormCreate(Sender: TObject); procedure SpeedButton1Click(Sender: TObject); procedure SpeedButton2Click(Sender: TObject); private { Private declarations } public { Public declarations } toplar:array [0..20,0..30] of tshape; secililer:tlist; puan:extended; procedure usttekinidusur(topi:tshape); function iliskililerisec(topi:tshape):integer ; function toplusil(topi:tshape):integer; procedure sec(top:tshape); procedure Shape1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); end; var Form1: TForm1; implementation {$R *.dfm} procedure tform1.usttekinidusur(topi:tshape); var x,y:integer; begin for y:=0 to 29 do for x:=0 to 19 do begin if (topi.Left=toplar[x,y].Left)then if ( topi.Toptoplar[x,y].Top )then begin toplar[x,y].Top:=toplar[x,y].Top+16; end; end; end; procedure tform1.Sec(top:tshape); begin tshape(top).pen.Width:=4; end; function tform1.iliskililerisec(topi:tshape):integer ; var x,y,secsay:integer; begin secsay:=0; for x:=0 to 19 do for y:=0 to 29 do begin if toplar[x,y].Visible then begin if (toplar[x,y].top= topi.top) and (toplar[x,y].Left=topi.Left-16 )and(toplar[x,y].Brush.Color=topi.Brush.Color) then begin if not (toplar[x,y].Pen.Width=4) then begin sec( toplar[x,y]); secsay:=secsay+1; iliskililerisec(toplar[x,y]); end; end; if (toplar[x,y].top= topi.top) and (toplar[x,y].Left=topi.Left+16 )and(toplar[x,y].Brush.Color=topi.Brush.Color) then begin if not (toplar[x,y].Pen.Width=4) then begin sec( toplar[x,y]); secsay:=secsay+1; iliskililerisec(toplar[x,y]); end; end; if (toplar[x,y].top= topi.top-16) and (toplar[x,y].Left=topi.Left )and(toplar[x,y].Brush.Color=topi.Brush.Color) then begin if not (toplar[x,y].Pen.Width=4) then begin sec( toplar[x,y]); secsay:=secsay+1; iliskililerisec(toplar[x,y]); end; end; if (toplar[x,y].top= topi.top+16) and (toplar[x,y].Left=topi.Left )and(toplar[x,y].Brush.Color=topi.Brush.Color) then begin if not (toplar[x,y].Pen.Width=4) then begin sec( toplar[x,y]); secsay:=secsay+1; iliskililerisec(toplar[x,y]); end; end; end; end; iliskililerisec:=secsay; end; function tform1.toplusil(topi:tshape):integer; var silinecekler:tlist; i:integer; begin silinecekler:=tlist.Create; silinecekler.Add(topi); for i:=0 to silinecekler.Count-1 do begin tshape(silinecekler.Items[i]).visible:=false; end; silinecekler.Destroy; //// listeyi bellekten sil toplusil:=1; end; procedure TForm1.FormCreate(Sender: TObject); var x,y:integer; begin secililer:=tlist.Create; ////seili toplarn listesi puan:=0; for x:=0 to 19 do for y:=0 to 29 do begin toplar[x,y]:=tshape.Create(form1);///////ekli olutur toplar[x,y].Parent:=form1;///////ekli formun iine koy toplar[x,y].width:=16;///genilii 16 olsun toplar[x,y].height:=16;////ykseklii 16 olsun toplar[x,y].Shape:= stEllipse; toplar[x,y].Left:=50+x*16; toplar[x,y].top:=50+y*16; toplar[x,y].Pen.Color:=clblue; toplar[x,y].Brush.Color:=((random(2)+1)*100)+(random(2)*255*255); toplar[x,y].OnMouseDown:=Shape1MouseDown; end; end; procedure TForm1.Shape1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var e:integer; begin e:=0; if tshape(sender).Pen.Width=4 then begin for x:=0 to 19 do for y:=0 to 29 do begin if toplar[x,y].Pen.Width=4 then begin toplar[x,y].Visible:=false; e:=e+1; end; end; puan:=puan+power(2,e); label1.Caption:='PUAN: '+floattostr(puan); ////////////drme burayaaaa///////////// for x:=0 to 19 do for y:=0 to 29 do begin if (toplar[x,y].Visible=false) then if (not(toplar[x,y].Pen.Width=3)) then begin toplar[x,y].Pen.Width:=3; usttekinidusur(toplar[x,y]); end; end; ////////////drme burayaaaa///////////// end else begin //////////seilleri temizleeeeeeeee///////////// for x:=0 to 19 do for y:=0 to 29 do begin if (toplar[x,y].Pen.Width=4) and(toplar[x,y].Visible) then toplar[x,y].Pen.Width:=1; end; //ve yeniden se//// if(iliskililerisec(tshape(sender)))0 then begin sec(tshape(sender)); end; //////////////////////////////////////// end; end; procedure TForm1.SpeedButton1Click(Sender: TObject); var x,y:integer; begin puan:=0; label1.Caption:='PUAN: '+floattostr(puan); for x:=0 to 19 do for y:=0 to 29 do begin toplar[x,y].Visible:=true; toplar[x,y].Parent:=form1; toplar[x,y].width:=16; toplar[x,y].height:=16; toplar[x,y].Shape:= stEllipse; toplar[x,y].Left:=50+x*16; toplar[x,y].top:=50+y*16; toplar[x,y].Pen.Color:=clblue; toplar[x,y].Pen.Width:=0; toplar[x,y].Brush.Color:=((random(2)+1)*100)+(random(2)*255*255); toplar[x,y].OnMouseDown:=Shape1MouseDown; end; end; procedure TForm1.SpeedButton2Click(Sender: TObject); begin close; end; end.