Mega Code Archive

 
Categories / Delphi / Examples
 

Roadmap example code

Title: Roadmap - example code Question: A roadmap, very useful to make roadmap programs Answer: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, jpeg, Buttons, StdCtrls; type TForm1 = class(TForm) Image1: TImage; Image2: TImage; Image3: TImage; Image4: TImage; Image5: TImage; Image6: TImage; Image7: TImage; Image8: TImage; Image9: TImage; Image10: TImage; Image11: TImage; Image12: TImage; Image13: TImage; Image14: TImage; Image15: TImage; Image16: TImage; Image17: TImage; Image18: TImage; Image19: TImage; Image20: TImage; Image21: TImage; Image24: TImage; Timer1: TTimer; SpeedButton1: TSpeedButton; Label1: TLabel; procedure Timer1Timer(Sender: TObject); procedure SpeedButton1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } yol:integer; bulundugusehir:tcolor; function renktenyol(renk:tcolor):integer; end; var Form1: TForm1; implementation {$R *.dfm} //renktenyol : this function calculates the distance when the color of // the moving ball changes. this function did'nt finish. You decide the /// distances here simply by writing this function. function tform1.renktenyol(renk:tcolor):integer; begin if renk=16744448 then renktenyol:=15 else if renk=16777088 then renktenyol:=5 else if renk=6792595 then renktenyol:=8 else if renk=3459051 then renktenyol:=20 else ////and goes on renktenyol:=0; end; procedure TForm1.Timer1Timer(Sender: TObject); begin ////neredee////////bulundugusehir:this is the color of the place where ///the moving ball is.when the color changes,the distance is added.. if not(bulundugusehir=image21.Canvas.Pixels[image24.Left,image24.top]) then begin yol:=yol+renktenyol(image21.Canvas.Pixels[image24.Left,image24.top]); label1.Caption:='Alnan yol:'+inttostr(yol)+' km.'; //label1.Caption:='Total distance:'+inttostr(yol)+' km.'; bulundugusehir:=image21.Canvas.Pixels[image24.Left,image24.top] end; ////key controls....//////// if ((getkeystate(vk_up) =-127 ) or (getkeystate(vk_up) =-128 )) then begin if not(image21.Canvas.Pixels[image24.Left,image24.top-1]=clblack) then image24.Top:=image24.Top-1; end; if ((getkeystate(vk_down) =-127 ) or (getkeystate(vk_down) =-128 )) then begin if not(image21.Canvas.Pixels[image24.Left,image24.top+1]=clblack) then image24.Top:=image24.Top+1; end; if ((getkeystate(vk_left) =-127 ) or (getkeystate(vk_left) =-128 )) then begin if not(image21.Canvas.Pixels[image24.Left-1,image24.top]=clblack) then image24.Left:=image24.Left-1; end; if ((getkeystate(vk_right) =-127 ) or (getkeystate(vk_right) =-128 )) then begin if not(image21.Canvas.Pixels[image24.Left+1,image24.top]=clblack) then image24.Left:=image24.Left+1; end; //just to determine the number..this code is for the developer. //destroy this line afer you finish the work. caption:=inttostr(image21.Canvas.Pixels[image24.Left,image24.top]); /// end; procedure TForm1.SpeedButton1Click(Sender: TObject); begin ///reset the total way. yol:=0; label1.Caption:='Alnan yol:'+inttostr(yol)+' km.'; //label1.Caption:='Total distance:'+inttostr(yol)+' km.'; end; procedure TForm1.FormCreate(Sender: TObject); begin yol:=0; caption:=inttostr(image21.Canvas.Pixels[image24.Left,image24.top]); bulundugusehir:=16744448;///this is the first color where we are. end; end.