Monday, 29 April 2013

Cotoh program game dengan delph 7 (game pocong)


Untuk membuat "Game Tangkep Pocong" ini kita membutuhkan beberapa item. yaitu :

jika anda tidak jelas anda bisa tanyakan kepada saya di klik sini

1. gambar si pocong (tentunya)
2. sebuah label (caption : SCORE)
3. 2 buah tombol (tombol Start dan tombol stop)

ok, kita mulai saja.

Pertama, desain form hingga membentuk seperti ini


Kedua, masukan kode dibawah :

unit UPocong;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, jpeg, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
     procedure aktif;            //procedure bila sedang aktif
    procedure nonaktif;      //procedure bila sedang tidak aktif
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation


{$R *.dfm}
 procedure tform1.aktif;
begin
Image1.enabled:=True;
Image2.enabled:=True;
Image3.enabled:=True;
Image4.enabled:=True;
Edit1.Enabled:=True;
Button2.enabled:=True;
Image4.Visible:=True;
Timer1.Enabled:=True;
end;

procedure tform1.nonaktif;
begin
Image1.enabled:=false;
Image2.enabled:=false;
Image3.enabled:=false;
Image4.enabled:=false;
Edit1.Enabled:=false;
Button2.enabled:=false;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
nonaktif;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
aktif;
end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
Image1.left:=Random(Left);
Image1.Top:=Random(top);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;

procedure TForm1.Image2MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
Image2.left:=Random(Left);
Image2.Top:=Random(top);
end;

procedure TForm1.Image3MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
Image3.left:=Random(Left);
Image3.Top:=Random(top);
end;

procedure TForm1.Image4MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
Image4.left:=Random(Left);
Image4.Top:=Random(top);
end;

procedure TForm1.Image1Click(Sender: TObject);
begin
Image1.Visible:=False;
Edit1.text:=IntToStr(strtoint(Edit1.text)+20);
end;

procedure TForm1.Image2Click(Sender: TObject);
begin
Image2.Visible:=False;
Edit1.text:=IntToStr(strtoint(Edit1.text)+20);
end;

procedure TForm1.Image3Click(Sender: TObject);
begin
Image3.Visible:=False;
Edit1.text:=IntToStr(strtoint(Edit1.text)+20);
end;

procedure TForm1.Image4Click(Sender: TObject);
begin
Image4.Visible:=False;
Edit1.text:=IntToStr(strtoint(Edit1.text)+20);
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
if Edit1.Text='100' then
begin
  nonaktif;
  ShowMessage('anda menang');
end
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
aktif;
ShowMessage('Game Over');
end;
end.