unit UKlasy;

interface

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

Type

MFigura = class(TShape)
public
   skok   : Integer;
	w_lewo : Boolean;
	w_gore : Boolean;

	procedure   Move();
	constructor Create(AOwner: TComponent; parSkok: Integer);
   destructor  Destroy(); override;
end;

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

   skok := parSkok;
   
	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.PaintBox.ClientWidth) then
      begin
         Left := Left + skok;
      end
      else begin
         w_lewo := true;
      end;
   end;

   if w_gore then
   begin
      if (Top - skok) >= MainForm.PaintBox.Top then
      begin
         Top := Top - skok;
      end
      else begin
         w_gore := false;
      end;
   end
   else begin
      if (Top + ClientHeight) <= (MainForm.PaintBox.ClientHeight) then
      begin
         Top := Top + skok;
      end
      else begin
         w_gore := true;
      end;
   end;
end;

end.

