Blob Blame Raw
unit Unit1;

{$mode objfpc}{$H+}

interface

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

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Image1: TImage;
    Image2: TImage;
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  play: boolean = false;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Edit2Change(Sender: TObject);
begin
  if play then begin
    if copy(Edit1.Text, 1, Length(Edit2.Text)) <> Edit2.Text then begin
      Edit2.Text := copy(Edit2.Text, 1, Length(Edit2.Text)-1);
      Edit2.SelStart := Length(Edit2.Text);
    end else begin
      Image2.Left := Edit1.Left + round(Edit1.Width*Length(Edit2.Text)/Length(Edit1.Text));
      if Edit1.Text = Edit2.Text then begin
        play := false;
        Edit1.ReadOnly := false;
        ShowMessage('You WIN!!!');
      end;
    end;
  end;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin

end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if play then begin
    Image1.Left := Image1.Left + 10;
    if Image1.Left >= Edit1.Left + Edit1.Width then begin
      play := false;
      Edit1.ReadOnly := false;
      ShowMessage('You loze');
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 Image1.Left := Edit1.Left;
 Image2.Left := Edit2.Left;

 Edit1.ReadOnly := True;
 Edit2.Text := '';
 Edit2.SetFocus;

 play := true;
end;

end.