unit UKlasy;

interface

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

const SKOK = 5;

Type

MFigura = class(TShape)
public
	w_lewo : Boolean;
	w_gore : Boolean;
   
	procedure   Move();
	constructor Create(AOwner: TComponent); override;
   destructor  Destroy(); override;
end;

implementation
Uses
   Main;
{------------------------------------------------------------------------------}
constructor MFigura.Create(AOwner: TComponent);
begin
	// wystarczy samo:
	// inherited;
   // lub:
   inherited Create(AOwner);

	w_lewo := true;
   w_gore := true;
end;

destructor MFigura.Destroy();
begin
	inherited;
end;

procedure MFigura.Move();
begin
   if w_lewo then
   begin
      if (Left - SKOK) >= 0 then
      begin
         Left := Left - SKOK;
      end
      else begin
         w_lewo := false;
      end;
   end
   else begin
      if (Left + ClientWidth) < (MainForm.Width-3) then
      begin
         Left := Left + SKOK;
      end
      else begin
         w_lewo := true;
      end;
   end;

   if w_gore then
   begin
      if (Top - SKOK) >= MainForm.Panel1.Height then
      begin
         Top := Top - SKOK;
      end
      else begin
         w_gore := false;
      end;
   end
   else begin
      if (Top + ClientHeight) < (MainForm.Height - Height-3) then
      begin
         Top := Top + SKOK;
      end
      else begin
         w_gore := true;
      end;
   end;
end;

end.

