урок на делфи 16 - Пинг понг
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,math;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Timer4: TTimer;
Label14: TLabel;
procedure FormCreate(Sender: TObject);
procedure Timer4Timer(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
ky,kx,skorost:integer;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
begin
skorost:=4;
ky:=skorost;
kx:=RandomRange(-skorost,skorost);
Timer4.Enabled:=true;
Label14.Visible:=false;
Button1.Top:=20;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
skorost:=4;
ky:=skorost;
kx:=RandomRange(-skorost,skorost);
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
Button2.Left:=x;
end;
procedure TForm1.Timer4Timer(Sender: TObject);
begin
Button1.top:=Button1.top+ky;
Button1.left:=Button1.left+kx;
if (Button1.Top>=Form1.Height) then
begin
Label14.Visible:=true;
Timer4.Enabled:=false;
end;
if (Button1.Top=Button2.Top-20) and ((Button1.left>Button2.left-75)or (Button1.left>Button2.left+75) ) then
begin
skorost:=skorost+1;
ky:=-4-skorost;
kx:=RandomRange(-6,6);
end;
if (Button1.left>=Form1.Width-75) then
kx:=-4-skorost;
if (Button1.Top<=0) then
ky:=4+skorost;
if (Button1.left<=0) then
kx:=4+skorost;
end;
end.