Blame lazarus/hide-n-seek/unit1.pas

5a459c
unit Unit1;
5a459c
5a459c
{$mode objfpc}{$H+}
5a459c
5a459c
interface
5a459c
5a459c
uses
5a459c
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls;
5a459c
5a459c
type
5a459c
5a459c
  { TForm1 }
5a459c
5a459c
  TForm1 = class(TForm)
5a459c
    Panel1: TPanel;
5a459c
    Panel2: TPanel;
5a459c
    Shape1: TShape;
5a459c
    Timer1: TTimer;
5a459c
    Timer2: TTimer;
5a459c
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
5a459c
    procedure Shape1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer
5a459c
      );
5a459c
    procedure Timer1Timer(Sender: TObject);
5a459c
    procedure Timer2Timer(Sender: TObject);
5a459c
  private
5a459c
    { private declarations }
5a459c
  public
5a459c
    { public declarations }
5a459c
  end;
5a459c
5a459c
var
5a459c
  Form1: TForm1;
5a459c
  mouseX, mouseY: integer;
5a459c
5a459c
implementation
5a459c
5a459c
{$R *.lfm}
5a459c
5a459c
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
5a459c
  Y: Integer);
5a459c
begin
5a459c
  mouseX := X;
5a459c
  mouseY := Y;
5a459c
end;
5a459c
5a459c
procedure TForm1.Timer1Timer(Sender: TObject);
5a459c
begin
5a459c
  if Shape1.Left + Shape1.Width div 2 < mouseX then Shape1.Left := Shape1.Left + 5;
5a459c
  if Shape1.Left + Shape1.Width div 2 > mouseX then Shape1.Left := Shape1.Left - 5;
5a459c
  if Shape1.Top + Shape1.Height div 2 < mouseY then Shape1.Top := Shape1.Top + 5;
5a459c
  if Shape1.Top + Shape1.Height div 2 > mouseY then Shape1.Top := Shape1.Top - 5;
5a459c
end;
5a459c
5a459c
procedure TForm1.Shape1MouseMove(Sender: TObject; Shift: TShiftState; X,
5a459c
  Y: Integer);
5a459c
begin
5a459c
  Beep;
5a459c
  Shape1.Brush.Color := clRed;
5a459c
  Cursor := crNone;
5a459c
  Timer2.Enabled := true;
5a459c
  Timer1.Enabled := false;
5a459c
end;
5a459c
5a459c
procedure TForm1.Timer2Timer(Sender: TObject);
5a459c
begin
5a459c
  Cursor := crDefault;
5a459c
  Shape1.Brush.Color := clWhite;
5a459c
  Timer1.Enabled := true;
5a459c
  Timer2.Enabled := false;
5a459c
end;
5a459c
5a459c
end.
5a459c