撞墙游戏源代码
窗体初始化unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Shape1: TShape;
Timer1: TTimer;
Label1: TLabel;
ListBox1: TListBox;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Label4: TLabel;
procedure Timer1Timer(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
定时器空间
把Timer1的Interval属性改为1
procedure TForm1.Timer1Timer(Sender: TObject);
begin
image1.Left:=image1.Left+1;
if image1.Left>shape1.Left-44 then
begin
Timer1.Enabled :=False;
showmessage('Game Over');
Close;
end
end;
窗体(按下键)
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Timer1.Enabled :=True;
Label1.Caption:=IntToStr(160-(Shape1.Left-Image1.Left));
end;
窗体(松开按键)
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Timer1.Enabled:=False;
ListBox1.Items.Add(Label1.Caption);
image1.Left:=0;
shape1.Left:=Random(200)+100;
Edit1.Text:=IntToStr(StrToInt(Edit1.Text)+StrToInt(Label1.Caption));
end;
窗体(创建标签)
procedure TForm1.FormCreate(Sender: TObject);
begin
Label3.Caption:='游戏规则:按键盘上的任意键。按下时人就往前走,松开时人就停下来,并回到起点。看人离墙多近,越近分越高。如果人撞到墙,则游戏结束。';
end;
end.
页:
[1]