Snažím sa to nejako takto, ale je to asi zlé:
Kód:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
ScrollBar1: TScrollBar;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ScrollBar1Change(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
x:integer;
y:integer;
x1:integer;
y1:integer;
spravne:integer;
nespravne:integer;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled:=True;
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
x := Mouse.CursorPos.X;
y := Mouse.CursorPos.Y;
Label4.Caption:='Position: '+IntToStr(X)+', '+IntToStr(Y);
if shift=[ssleft] then
begin
if (x=x1) and (y=y1) then spravne:=spravne+1;
end
else
nespravne:=nespravne+1;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
procedure zmaz;
begin
Image1.Canvas.Brush.Color:=clWhite;
Image1.Canvas.FillRect(Image1.ClientRect);
end;
begin
Randomize;
zmaz;
Image1.Canvas.Brush.Color:=clRed;
Image1.Canvas.Rectangle(400+x1, 400+y1,430+x1,430+y1);
x1:=x1+Random(100)+30;
y1:=y1+Random(100)+30;
Label1.Caption:='Position: '+IntToStr(X1)+', '+IntToStr(Y1);
Label2.Caption:='spravny: '+IntToStr(spravne);
Label3.Caption:='nespravny: '+IntToStr(nespravne);
end;
procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
Timer1.Interval := Scrollbar1.Position+500;
end;
end.
// Spojený príspevok 07.10.2018 21:12Už to mám.