马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
Delphi代码如下:
窗体初始化
unit Unit16;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Image2: TImage;
Timer1: TTimer;
Label1: TLabel;
Image3: TImage;
Timer2: TTimer;
Label2: TLabel;
procedure Timer1Timer(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormClick(Sender: TObject);
procedure Label1Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Label2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2, Unit17;
{$R *.dfm}
定时器控件
把Timer1的Interval属性改为10
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if image2.Left=0 then
begin
image2.Left:=900;
image2.Top:=Random(245)+1;
end
else
image2.Left:=image2.Left-10;
if image2.Left <=image1.Left +86 then
if image2.Top >image1.Top-66 then
if image2.Top <image1.Top +66 then
begin
timer1.Enabled:=false;
timer2.Enabled:=false;
showmessage('GAME OVER!');
image1.Visible:=false;
image2.Visible:=false;
image3.Visible:=false;
label1.Visible:=true;
label2.Visible:=true;
end
end;
窗体(鼠标移动)
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
var
x1,y1:integer;
begin
x1:=X;
y1:=Y;
image1.Top:=y1;
end;
窗体(单击)
procedure TForm1.FormClick(Sender: TObject);
begin
image1.Visible:=true;
image2.Visible:=true;
image3.Visible:=true;
timer1.Enabled:=true;
timer2.Enabled:=true;
label1.Visible:=false;
label2.Visible:=false;
end;
标签
procedure TForm1.Label1Click(Sender: TObject);
begin
timer1.Enabled:=true;
timer2.Enabled:=true;
label1.Visible:=false;
label2.Visible:=false;
end;
定时器控件
把Timer2的Interval属性改为29
procedure TForm1.Timer2Timer(Sender: TObject);
begin
if image3.Left<=0 then
begin
image3.Left:=900;
image3.Top:=Random(245)+1;
end
else
image3.Left:=image3.Left-10;
if image3.Left <=image1.Left +86 then
if image3.Top >image1.Top-66 then
if image3.Top <image1.Top +66 then
begin
timer1.Enabled:=false;
timer2.Enabled:=false;
showmessage('GAME OVER!');
image1.Visible:=false;
image2.Visible:=false;
image3.Visible:=false;
label1.Visible:=true;
label2.Visible:=true;
end
end;
窗体(按键)
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);
begin
if key=vk_f1 then
begin
form2.ShowModal;
end
end;
标签
procedure TForm1.Label2Click(Sender: TObject);
begin
timer1.Enabled:=true;
timer2.Enabled:=true;
label1.Visible:=false;
end;
end.
|