NAMA : ANGGA RUSTANJI
KELAS: 13.6B.01
NIM : 13090283
LAB : D
GAMES TIMER
TUGAS LATIHAN MEMBUAT GAMES DENGAN TIMER
unit Lati1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, jpeg, ExtCtrls, Menus;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Image6: TImage;
Label2: TLabel;
Edit2: TEdit;
Label1: TLabel;
Timer1: TTimer;
Edit3: TEdit;
Edit4: TEdit;
Image1: TImage;
Image2: TImage;
Image3: TImage;
Image4: TImage;
Image5: TImage;
MainMenu1: TMainMenu;
Memo1: TMemo;
File1: TMenuItem;
ExitGames1: TMenuItem;
Help1: TMenuItem;
AboutMe1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Button2Click(Sender: TObject);
procedure Image2MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image3MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image4MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image5MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image1Click(Sender: TObject);
procedure Image2Click(Sender: TObject);
procedure Image3Click(Sender: TObject);
procedure Image4Click(Sender: TObject);
procedure Image5Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Edit4Change(Sender: TObject);
procedure AboutMe1Click(Sender: TObject);
procedure ExitGames1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Procedure aktif;
Procedure nonaktif;
end;
var
Form1: TForm1;
awal, akhir : TDateTime;
lama : real;
implementation
uses Latihan_Form2;
{$R *.dfm}
Procedure TForm1.aktif;
Begin
Image1.Enabled:=true;
Image2.Enabled:=true;
Image3.Enabled:=true;
Image4.Enabled:=true;
Image5.Enabled:=true;
edit1.Enabled:=true;
image1.Visible:=true;
image2.Visible:=true;
image3.Visible:=true;
image4.Visible:=true;
image5.Visible:=true;
end;
Procedure TForm1.nonaktif;
Begin
Image1.Enabled:=false;
Image2.Enabled:=false;
Image3.Enabled:=false;
Image4.Enabled:=false;
Image5.Enabled:=false;
Edit1.Enabled:=false;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
nonaktif;
Timer1.Interval:=1;
Memo1.Clear;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
aktif;
if Button1.Caption='Start' then
begin
awal := Time;
Edit2.Text:=TimeToStr(Time);
Button1.Caption:='Stop';
end
else if Button1.Caption='Stop' then
begin
Button1.Caption:='Selesai';
nonaktif;
end
else
Application.Terminate;
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.Image5MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
image5.Left:=random(Left);
image5.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.Image5Click(Sender: TObject);
begin
image5.Visible:=false;
edit1.Text:=inttostr(strtoint(edit1.Text)+20);
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
If Edit1.Text='100' then
begin
nonaktif;
Edit2.Visible:=False;
Edit3.Visible:=False;
Edit4.Visible :=False;
showmessage('Anda Menang (WINER)');
end
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
Slama : string;
begin
if Button1.Caption='Stop' then
begin
akhir := Time;
Edit3.Text:=TimeToStr(akhir);
lama := (akhir-awal)*100000;
Str(lama:20:4,Slama);
Edit4.Text:=Slama;
end
end;
procedure TForm1.Edit4Change(Sender: TObject);
begin
if lama >=100000 then
Begin
Button1.Caption:='Selesai';
showmessage('GAMES OVER : ANDA KALAH >>> BEGO BETUL...??');
end
Else If lama <=100000 then
Begin
If Edit1.Text='100' Then
Begin
nonaktif;
Edit2.Visible:=False;
Edit3.Visible:=False;
Edit4.Visible :=False;
Edit1.ShowHint :=True;
Memo1.Clear;
Memo1.Text:='Anda Menang (Winner) ';
end
end
Else
Form1.Show;
end;
procedure TForm1.AboutMe1Click(Sender: TObject);
begin
Form2.Show;
end;
procedure TForm1.ExitGames1Click(Sender: TObject);
begin
Application.Terminate ;
end;
end.