unit Unit1; 

{$mode objfpc}{$H+}

interface

uses
  LCLtype, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
  ExtCtrls, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);

    procedure FormKeyPress(Sender: TObject; var Key: char);
  private
    { private declarations }
  public
    { public declarations }
  end; 

var
  Form1: TForm1;
  x,y: integer;
  x2,y2: integer;
  skore: integer;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  form1.KeyPreview := True;
  randomize;
  x:= image1.width div 2;
  y:= image1.height div 2;
  x2 := Random(image1.width div 20)*20;
  y2 := Random(image1.height div 20)*20;
  Image1.canvas.brush.color := clWhite;
  Image1.canvas.FillRect(clientrect);
  Image1.canvas.Brush.color:= clRed;
  Image1.Canvas.Ellipse(x2,y2,x2+20,y2+20);
  Image1.canvas.brush.color := clWhite;
  skore := 0;
end;



procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);
begin
  Label1.Caption := 'skóre: '+inttostr(skore);
   if Key='a' then
    begin
      x := x-10;
    end;
   if Key='d' then
    begin
      x := x+10;
    end;
   if Key='w' then
    begin
      y := y-10;
    end;
   if Key='s' then
    begin
      y := y+10;
    end;

   Image1.canvas.FillRect(clientrect);
   Image1.canvas.Brush.color:= clRed;
   Image1.Canvas.Ellipse(x2,y2,x2+20,y2+20);
   Image1.canvas.brush.color := clWhite;
   if not ((x=x2)and(y=y2)) then
    begin
     Image1.canvas.rectangle(x,y,x+20,y+20);
    end
   else
    begin
     Image1.canvas.Brush.color:= clRed;
     x2 := Random(image1.width div 20)*20;
     y2 := Random(image1.height div 20)*20;
     Image1.canvas.brush.color := clWhite;
     Image1.canvas.rectangle(x,y,x+20,y+20);
     Image1.canvas.Brush.color:= clRed;
     Image1.Canvas.Ellipse(x2,y2,x2+20,y2+20);
     Image1.canvas.brush.color := clWhite;
     skore := skore + 1;
    end;
  if (x+20>Image1.width)or(x<0) then
   begin
    Image1.Canvas.Font.Height := 36;
    Image1.Canvas.Font.Color := clBlack;
    Image1.Canvas.TextOut((image1.width div 2)-36, (image1.height div 2)-36, 'Game Over');
    Form1.KeyPreview := False;
   end;
  if (y+20>Image1.height)or(y<0) then
   begin
    Image1.Canvas.Font.Height := 36;
    Image1.Canvas.Font.Color := clBlack;
    Image1.Canvas.TextOut((image1.width div 2)-36, (image1.height div 2)-36, 'Game Over');
    Form1.KeyPreview := False;
   end;

  end;





end.

