unit index;

interface

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

type
  Tstart = class(TForm)
    img1: TImage;
    lbl1: TLabel;
    lbl2: TLabel;
    img2: TImage;
    img3: TImage;
    lbl3: TLabel;
    lbl4: TLabel;
    imgPir: TImage;
    imgU1: TImage;
    KeyControl: TMemo;
    GoT: TButton;
    GoD: TButton;
    GoR: TButton;
    GoL: TButton;
    Go: TButton;
    lbl5: TLabel;
    eat: TButton;
    rmk: TButton;
    imgU2: TImage;
    imgU3: TImage;
    lbl9: TLabel;
    lbl10: TLabel;
    lbl8: TLabel;
    dif: TEdit;
    lbl6: TLabel;
    mmo1: TMemo;
    mmo2: TMemo;
    edt1: TEdit;
    edt2: TEdit;
    edt3: TEdit;
    edt4: TEdit;
    edt5: TEdit;
    edt6: TEdit;
    sett: TButton;
    btn1: TButton;
    scr: TEdit;
    mmoRecords: TMemo;
    procedure lbl4MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure lbl3Click(Sender: TObject);
    procedure lbl3MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure lbl3MouseLeave(Sender: TObject);
    procedure lbl4MouseLeave(Sender: TObject);
    procedure KeyControlKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
    procedure GoClick(Sender: TObject);
    procedure GoTClick(Sender: TObject);
    procedure GoDClick(Sender: TObject);
    procedure GoRClick(Sender: TObject);
    procedure GoLClick(Sender: TObject);
    procedure eatClick(Sender: TObject);
    procedure lbl4Click(Sender: TObject);
    procedure rmkClick(Sender: TObject);
    procedure difChange(Sender: TObject);
    procedure settClick(Sender: TObject);
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  start: Tstart;
  i,i1,food1,hod,backtop,backleft,hour1,PirTop,PirLeft,U1Top,U2Top,U3Top,U1Left,U2Left,U3Left,DifI: Integer;
  Left,Right,Up,Down,pifA,pifB,sc0re: Real;
implementation

uses Unit2, Unit3, Unit1, Unit5, Unit4, food, Unit6;

{$R *.dfm}

procedure Tstart.lbl4MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  img3.Visible:=True;
end;


procedure Tstart.lbl3Click(Sender: TObject);
var w:integer;
begin
  w:=Exitt.ShowModal;
end;

procedure Tstart.lbl3MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  img2.Visible:=True;
end;

procedure Tstart.lbl3MouseLeave(Sender: TObject);
begin
  img2.Visible:=False;
end;

procedure Tstart.lbl4MouseLeave(Sender: TObject);
begin
  img3.Visible:=False;
end;

procedure Tstart.KeyControlKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
  var w,i,klad:Integer;
begin
  backtop:=imgPir.Top;
  backleft:=imgPir.Left;
  begin
  case Key of
    vk_up:
       begin
        if imgPir.Top=4 then
        w:=Border.ShowModal
        else
        imgPir.Top:=imgPir.Top-99;
        edt1.Text:='Top:'+inttostr(imgPir.Top);
            if (imgPir.Top=imgU1.Top) and (imgPir.Left=imgU1.Left) or
            (imgPir.Top=imgU2.Top) and (imgPir.Left=imgU2.Left) or
            (imgPir.Top=imgU3.Top) and (imgPir.Left=imgU3.Left) then
              begin
               imgPir.Top:=backtop;
               imgPir.Left:=backleft;
               island.Caption:='Кэп, команда бунтует!';
               island.edt1.Text:='Ваша команда бунтует против Вашего спонтанного решения!!!';
               island.btn1.Caption:='А я хотел сдаться :(     Ну... ок... Придётся потерпеть...';
               w:=island.ShowModal;
              end;
   end;

    vk_down:
       begin
          if imgPir.Top=697 then
        w:=Border.ShowModal
        else
         imgPir.Top:=imgPir.Top+99;
         edt1.Text:='Top:'+inttostr(imgPir.Top);
         if (imgPir.Top=imgU1.Top) and (imgPir.Left=imgU1.Left) or
            (imgPir.Top=imgU2.Top) and (imgPir.Left=imgU2.Left) or
            (imgPir.Top=imgU3.Top) and (imgPir.Left=imgU3.Left) then
              begin
               imgPir.Top:=backtop;
               imgPir.Left:=backleft;
               island.Caption:='Кэп, команда бунтует!';
               island.edt1.Text:='Ваша команда бунтует против Вашего спонтанного решения!!!';
               island.btn1.Caption:='А я хотел сдаться :(     Ну... ок... Придётся потерпеть...';
               w:=island.ShowModal;
              end;
         end;

    vk_left:
       begin
          if imgPir.Left=19 then
        w:=Border.ShowModal
        else
         imgPir.Left:=imgPir.Left-99;
         edt2.Text:='Left:'+inttostr(imgPir.Left);
         if (imgPir.Top=imgU1.Top) and (imgPir.Left=imgU1.Left) or
            (imgPir.Top=imgU2.Top) and (imgPir.Left=imgU2.Left) or
            (imgPir.Top=imgU3.Top) and (imgPir.Left=imgU3.Left) then
              begin
               imgPir.Top:=backtop;
               imgPir.Left:=backleft;
               island.Caption:='Кэп, команда бунтует!';
               island.edt1.Text:='Ваша команда бунтует против Вашего спонтанного решения!!!';
               island.btn1.Caption:='А я хотел сдаться :(     Ну... ок... Придётся потерпеть...';
               w:=island.ShowModal;

              end;
         end;

    vk_right:
       begin
          if imgPir.Left=811 then
        w:=Border.ShowModal
        else
         imgPir.Left:=imgPir.Left+99;
         edt2.Text:='Left:'+inttostr(imgPir.Left);
         if (imgPir.Top=imgU1.Top) and (imgPir.Left=imgU1.Left) or
            (imgPir.Top=imgU2.Top) and (imgPir.Left=imgU2.Left) or
            (imgPir.Top=imgU3.Top) and (imgPir.Left=imgU3.Left) then
              begin
               imgPir.Top:=backtop;
               imgPir.Left:=backleft;
               island.Caption:='Кэп, команда бунтует!';
               island.edt1.Text:='Ваша команда бунтует против Вашего спонтанного решения!!!';
               island.btn1.Caption:='А я хотел сдаться :(     Ну... ок... Придётся потерпеть...';
               w:=island.ShowModal;
              end;


       end;
  end;
      if (imgPir.Top=4) and (imgPir.Left=415) or
         (imgPir.Top=103) and (imgPir.Left=118) or
         (imgPir.Top=103) and (imgPir.Left=712) or
         (imgPir.Top=202) and (imgPir.Left=811) or
         (imgPir.Top=301) and (imgPir.Left=217) or
         (imgPir.Top=301) and (imgPir.Left=415) or
         (imgPir.Top=301) and (imgPir.Left=613) or
         (imgPir.Top=400) and (imgPir.Left=118) or
         (imgPir.Top=400) and (imgPir.Left=712) or
         (imgPir.Top=499) and (imgPir.Left=415) or
         (imgPir.Top=598) and (imgPir.Left=217) or
         (imgPir.Top=598) and (imgPir.Left=613) then
      begin

          Randomize;
          klad:=Random(20);
          if klad<>0 then
       begin
          imgPir.Top:=backtop;
          imgPir.Left:=backleft;
          island.edt1.Text:='Капитан, зачем Вы тратите время на ветер? Мы обыскали остров - там пусто!';
          island.btn1.Caption:='Ок! Поворачива-ай!';
          w:=island.ShowModal
       end
          else
       begin
       klad:=Random(3)+1;

       if klad=1 then
          begin
             imgPir.Top:=backtop;
             imgPir.Left:=backleft;
          found.lbl2.Caption:='Их хватит на 1 день';
          food1:=food1-1;
          w:=found.ShowModal;
          end
          else
           if klad=2 then
              begin
             imgPir.Top:=backtop;
             imgPir.Left:=backleft;
          found.lbl2.Caption:='Их хватит на 2 дня';
          food1:=food1-2;
          w:=found.ShowModal;
              end
              else
               if klad=3 then
                  begin
              imgPir.Top:=backtop;
              imgPir.Left:=backleft;
          found.lbl2.Caption:='Их хватит на 3 дня';
          food1:=food1-3;
          w:=found.ShowModal;
                  end;
       end;
       eat.Click;
       end;
end;
  begin
    if (imgPir.Top<>backtop) or (imgPir.Left<>backleft) then
    eat.Click;
  end;

  begin
    if (imgPir.Top=4) and (imgPir.Left=811) or
       (imgPir.Top=697) and (imgPir.Left=811) then  begin
        GameEnd.lbl1.Caption:='Вы выйграли!!!';
        sc0re:=(food1*(20*food1)-hod)*strtoint(dif.Text);
        if sc0re<0 then
        sc0re:=sc0re*(-1);
        scr.Text:=FloatToStr(sc0re);
        w:=GameEnd.ShowModal;
     end;
  end;
end;

procedure Tstart.FormCreate(Sender: TObject);
begin
DoubleBuffered:= True;
i1:=0;
dif.Text:='2';
DifI:=2;
food1:=-12;
hour1:=8;
//УБрать всё по полочкам. Нужное действие=нажатие кнопки, т.к. необходимо
//обозначивать каждый островок, кораблики есть, финальные точки
PirTop:=imgPir.Top;
PirLeft:=imgPir.Left;
U1Top:=imgU1.Top;
U2Top:=imgU2.Top;
U3Top:=imgU3.Top;
U1Left:=imgU1.Left;
U2Left:=imgU2.Left;
U3Left:=imgU3.Left;
end;

procedure Tstart.GoClick(Sender: TObject);
var Left: Real;
i,w: Integer;
begin
 Repeat
   i1:=i1+1;
  if i1=1 then
  begin
 For i:=1 to 2 do
 begin
  begin
   if (imgU1.Top=4) and ((imgU1.Left-99)=415) or
         (imgU1.Top=103) and ((imgU1.Left-99)=118) or
         (imgU1.Top=103) and ((imgU1.Left-99)=712) or
         (imgU1.Top=202) and ((imgU1.Left-99)=811) or
         (imgU1.Top=301) and ((imgU1.Left-99)=217) or
         (imgU1.Top=301) and ((imgU1.Left-99)=415) or
         (imgU1.Top=301) and ((imgU1.Left-99)=613) or
         (imgU1.Top=400) and ((imgU1.Left-99)=118) or
         (imgU1.Top=400) and ((imgU1.Left-99)=712) or
         (imgU1.Top=499) and ((imgU1.Left-99)=415) or
         (imgU1.Top=598) and ((imgU1.Left-99)=217) or
         (imgU1.Top=598) and ((imgU1.Left-99)=613) then
            Left:=500000    else
            begin
  PifA:=Sqr(imgU1.Top-imgPir.Top);
  PifB:=Sqr(imgU1.Left-imgPir.Left-99);
  Left:=Sqrt(PifA+PifB);
  end;
  end;

  begin
   if (imgU1.Top=4) and ((imgU1.Left+99)=415) or
         (imgU1.Top=103) and ((imgU1.Left+99)=118) or
         (imgU1.Top=103) and ((imgU1.Left+99)=712) or
         (imgU1.Top=202) and ((imgU1.Left+99)=811) or
         (imgU1.Top=301) and ((imgU1.Left+99)=217) or
         (imgU1.Top=301) and ((imgU1.Left+99)=415) or
         (imgU1.Top=301) and ((imgU1.Left+99)=613) or
         (imgU1.Top=400) and ((imgU1.Left+99)=118) or
         (imgU1.Top=400) and ((imgU1.Left)=712) or
         (imgU1.Top=499) and ((imgU1.Left+99)=415) or
         (imgU1.Top=598) and ((imgU1.Left+99)=217) or
         (imgU1.Top=598) and ((imgU1.Left+99)=613) then
            Right:=500000 else
  begin
  PifA:=Sqr(imgU1.Top-imgPir.Top);
  PifB:=Sqr(imgU1.Left-imgPir.Left+99);
  Right:=Sqrt(PifA+PifB);

  end;
  end;

  begin
   if ((imgU1.Top+99)=4) and (imgU1.Left=415) or
         ((imgU1.Top+99)=103) and (imgU1.Left=118) or
         ((imgU1.Top+99)=103) and (imgU1.Left=712) or
         ((imgU1.Top+99)=202) and (imgU1.Left=811) or
         ((imgU1.Top+99)=301) and (imgU1.Left=217) or
         ((imgU1.Top+99)=301) and (imgU1.Left=415) or
         ((imgU1.Top+99)=301) and (imgU1.Left=613) or
         ((imgU1.Top+99)=400) and (imgU1.Left=118) or
         ((imgU1.Top+99)=400) and (imgU1.Left=712) or
         ((imgU1.Top+99)=499) and (imgU1.Left=415) or
         ((imgU1.Top+99)=598) and (imgU1.Left=217) or
         ((imgU1.Top+99)=598) and (imgU1.Left=613) then
            Down:=500000    else
  begin
  PifA:=Sqr(imgU1.Top-imgPir.Top+99);
  PifB:=Sqr(imgU1.Left-imgPir.Left);
  Down:=Sqrt(PifA+PifB);

  end;
  end;

  begin
     if ((imgU1.Top-99)=4) and (imgU1.Left=415) or
         ((imgU1.Top-99)=103) and (imgU1.Left=118) or
         ((imgU1.Top-99)=103) and (imgU1.Left=712) or
         ((imgU1.Top-99)=202) and (imgU1.Left=811) or
         ((imgU1.Top-99)=301) and (imgU1.Left=217) or
         ((imgU1.Top-99)=301) and (imgU1.Left=415) or
         ((imgU1.Top-99)=301) and (imgU1.Left=613) or
         ((imgU1.Top-99)=400) and (imgU1.Left=118) or
         ((imgU1.Top-99)=400) and (imgU1.Left=712) or
         ((imgU1.Top-99)=499) and (imgU1.Left=415) or
         ((imgU1.Top-99)=598) and (imgU1.Left=217) or
         ((imgU1.Top-99)=598) and (imgU1.Left=613) then
            Up:=500000    else
  begin
  PifA:=(imgU1.Top-imgPir.Top-99);
  PifB:=(imgU1.Left-imgPir.Left);
  Up:=Sqrt(Sqr(PifA)+Sqr(PifB));

  end;
     end;
          begin  // сравниваем варианты для перемещения
            if (Up<Down) and (Up<Left) and (Up<Right) then
              GoT.Click
              else
                if (Down<Left) and (Down<Right) then
                  GoD.Click
                  else
                    if Right<Left then
                      GoR.Click
                      else
                        GoL.Click;
          end;
edt6.Text:='Up='+floattostr(Up);
  edt5.Text:='Down='+floattostr(Down);
    edt4.Text:='Right='+floattostr(Right);
     edt3.Text:='Left='+floattostr(Left);
     if (imgU1.Top=imgPir.Top) and (imgU1.Left=imgPir.Left) then
      begin
        GameEnd.lbl1.Caption:='Вы проиграли! :(';
        w:=GameEnd.ShowModal;
      end;

end;
end
else
if i1=2 then
begin
 For i:=1 to 2 do
 begin
  begin
   if (imgU2.Top=4) and ((imgU2.Left-99)=415) or
         (imgU2.Top=103) and ((imgU2.Left-99)=118) or
         (imgU2.Top=103) and ((imgU2.Left-99)=712) or
         (imgU2.Top=202) and ((imgU2.Left-99)=811) or
         (imgU2.Top=301) and ((imgU2.Left-99)=217) or
         (imgU2.Top=301) and ((imgU2.Left-99)=415) or
         (imgU2.Top=301) and ((imgU2.Left-99)=613) or
         (imgU2.Top=400) and ((imgU2.Left-99)=118) or
         (imgU2.Top=400) and ((imgU2.Left-99)=712) or
         (imgU2.Top=499) and ((imgU2.Left-99)=415) or
         (imgU2.Top=598) and ((imgU2.Left-99)=217) or
         (imgU2.Top=598) and ((imgU2.Left-99)=613) then
            Left:=500000    else
            begin
  PifA:=Sqr(imgU2.Top-imgPir.Top);
  PifB:=Sqr(imgU2.Left-imgPir.Left-99);
  Left:=Sqrt(PifA+PifB);
  end;
  end;

  begin
   if (imgU2.Top=4) and ((imgU2.Left+99)=415) or
         (imgU2.Top=103) and ((imgU2.Left+99)=118) or
         (imgU2.Top=103) and ((imgU2.Left+99)=712) or
         (imgU2.Top=202) and ((imgU2.Left+99)=811) or
         (imgU2.Top=301) and ((imgU2.Left+99)=217) or
         (imgU2.Top=301) and ((imgU2.Left+99)=415) or
         (imgU2.Top=301) and ((imgU2.Left+99)=613) or
         (imgU2.Top=400) and ((imgU2.Left+99)=118) or
         (imgU2.Top=400) and ((imgU2.Left)=712) or
         (imgU2.Top=499) and ((imgU2.Left+99)=415) or
         (imgU2.Top=598) and ((imgU2.Left+99)=217) or
         (imgU2.Top=598) and ((imgU2.Left+99)=613) then
            Right:=500000 else
  begin
  PifA:=Sqr(imgU2.Top-imgPir.Top);
  PifB:=Sqr(imgU2.Left-imgPir.Left+99);
  Right:=Sqrt(PifA+PifB);

  end;
  end;

  begin
   if ((imgU2.Top+99)=4) and (imgU2.Left=415) or
         ((imgU2.Top+99)=103) and (imgU2.Left=118) or
         ((imgU2.Top+99)=103) and (imgU2.Left=712) or
         ((imgU2.Top+99)=202) and (imgU2.Left=811) or
         ((imgU2.Top+99)=301) and (imgU2.Left=217) or
         ((imgU2.Top+99)=301) and (imgU2.Left=415) or
         ((imgU2.Top+99)=301) and (imgU2.Left=613) or
         ((imgU2.Top+99)=400) and (imgU2.Left=118) or
         ((imgU2.Top+99)=400) and (imgU2.Left=712) or
         ((imgU2.Top+99)=499) and (imgU2.Left=415) or
         ((imgU2.Top+99)=598) and (imgU2.Left=217) or
         ((imgU2.Top+99)=598) and (imgU2.Left=613) then
            Down:=500000    else
  begin
  PifA:=Sqr(imgU2.Top-imgPir.Top+99);
  PifB:=Sqr(imgU2.Left-imgPir.Left);
  Down:=Sqrt(PifA+PifB);

  end;
  end;

  begin
     if ((imgU2.Top-99)=4) and (imgU2.Left=415) or
         ((imgU2.Top-99)=103) and (imgU2.Left=118) or
         ((imgU2.Top-99)=103) and (imgU2.Left=712) or
         ((imgU2.Top-99)=202) and (imgU2.Left=811) or
         ((imgU2.Top-99)=301) and (imgU2.Left=217) or
         ((imgU2.Top-99)=301) and (imgU2.Left=415) or
         ((imgU2.Top-99)=301) and (imgU2.Left=613) or
         ((imgU2.Top-99)=400) and (imgU2.Left=118) or
         ((imgU2.Top-99)=400) and (imgU2.Left=712) or
         ((imgU2.Top-99)=499) and (imgU2.Left=415) or
         ((imgU2.Top-99)=598) and (imgU2.Left=217) or
         ((imgU2.Top-99)=598) and (imgU2.Left=613) then
            Up:=500000    else
  begin
  PifA:=(imgU2.Top-imgPir.Top-99);
  PifB:=(imgU2.Left-imgPir.Left);
  Up:=Sqrt(Sqr(PifA)+Sqr(PifB));

  end;

          begin
            if (Up<Down) and (Up<Left) and (Up<Right) then
              GoT.Click
              else
                if (Down<Left) and (Down<Right) then
                  GoD.Click
                  else
                    if Right<Left then
                      GoR.Click
                      else
                        GoL.Click;
          end;
edt6.Text:='Up='+floattostr(Up);
  edt5.Text:='Down='+floattostr(Down);
    edt4.Text:='Right='+floattostr(Right);
     edt3.Text:='Left='+floattostr(Left);
     if (imgU2.Top=imgPir.Top) and (imgU2.Left=imgPir.Left) then
      begin
        GameEnd.lbl1.Caption:='Вы проиграли! :(';
        w:=GameEnd.ShowModal;
      end;
end;
end;
end
else
 For i:=1 to 2 do
 begin
  begin
   if (imgU3.Top=4) and ((imgU3.Left-99)=415) or
         (imgU3.Top=103) and ((imgU3.Left-99)=118) or
         (imgU3.Top=103) and ((imgU3.Left-99)=712) or
         (imgU3.Top=202) and ((imgU3.Left-99)=811) or
         (imgU3.Top=301) and ((imgU3.Left-99)=217) or
         (imgU3.Top=301) and ((imgU3.Left-99)=415) or
         (imgU3.Top=301) and ((imgU3.Left-99)=613) or
         (imgU3.Top=400) and ((imgU3.Left-99)=118) or
         (imgU3.Top=400) and ((imgU3.Left-99)=712) or
         (imgU3.Top=499) and ((imgU3.Left-99)=415) or
         (imgU3.Top=598) and ((imgU3.Left-99)=217) or
         (imgU3.Top=598) and ((imgU3.Left-99)=613) then
            Left:=500000    else
            begin
  PifA:=Sqr(imgU3.Top-imgPir.Top);
  PifB:=Sqr(imgU3.Left-imgPir.Left-99);
  Left:=Sqrt(PifA+PifB);
  end;
  end;

  begin
   if (imgU3.Top=4) and ((imgU3.Left+99)=415) or
         (imgU3.Top=103) and ((imgU3.Left+99)=118) or
         (imgU3.Top=103) and ((imgU3.Left+99)=712) or
         (imgU3.Top=202) and ((imgU3.Left+99)=811) or
         (imgU3.Top=301) and ((imgU3.Left+99)=217) or
         (imgU3.Top=301) and ((imgU3.Left+99)=415) or
         (imgU3.Top=301) and ((imgU3.Left+99)=613) or
         (imgU3.Top=400) and ((imgU3.Left+99)=118) or
         (imgU3.Top=400) and ((imgU3.Left)=712) or
         (imgU3.Top=499) and ((imgU3.Left+99)=415) or
         (imgU3.Top=598) and ((imgU3.Left+99)=217) or
         (imgU3.Top=598) and ((imgU3.Left+99)=613) then
            Right:=500000 else
  begin
  PifA:=Sqr(imgU3.Top-imgPir.Top);
  PifB:=Sqr(imgU3.Left-imgPir.Left+99);
  Right:=Sqrt(PifA+PifB);

  end;
  end;

  begin
   if ((imgU3.Top+99)=4) and (imgU3.Left=415) or
         ((imgU3.Top+99)=103) and (imgU3.Left=118) or
         ((imgU3.Top+99)=103) and (imgU3.Left=712) or
         ((imgU3.Top+99)=202) and (imgU3.Left=811) or
         ((imgU3.Top+99)=301) and (imgU3.Left=217) or
         ((imgU3.Top+99)=301) and (imgU3.Left=415) or
         ((imgU3.Top+99)=301) and (imgU3.Left=613) or
         ((imgU3.Top+99)=400) and (imgU3.Left=118) or
         ((imgU3.Top+99)=400) and (imgU3.Left=712) or
         ((imgU3.Top+99)=499) and (imgU3.Left=415) or
         ((imgU3.Top+99)=598) and (imgU3.Left=217) or
         ((imgU3.Top+99)=598) and (imgU3.Left=613) then
            Down:=500000    else
  begin
  PifA:=Sqr(imgU3.Top-imgPir.Top+99);
  PifB:=Sqr(imgU3.Left-imgPir.Left);
  Down:=Sqrt(PifA+PifB);

  end;
  end;

  begin
     if ((imgU3.Top-99)=4) and (imgU3.Left=415) or
         ((imgU3.Top-99)=103) and (imgU3.Left=118) or
         ((imgU3.Top-99)=103) and (imgU3.Left=712) or
         ((imgU3.Top-99)=202) and (imgU3.Left=811) or
         ((imgU3.Top-99)=301) and (imgU3.Left=217) or
         ((imgU3.Top-99)=301) and (imgU3.Left=415) or
         ((imgU3.Top-99)=301) and (imgU3.Left=613) or
         ((imgU3.Top-99)=400) and (imgU3.Left=118) or
         ((imgU3.Top-99)=400) and (imgU3.Left=712) or
         ((imgU3.Top-99)=499) and (imgU3.Left=415) or
         ((imgU3.Top-99)=598) and (imgU3.Left=217) or
         ((imgU3.Top-99)=598) and (imgU3.Left=613) then
            Up:=500000    else
  begin
  PifA:=(imgU3.Top-imgPir.Top-99);
  PifB:=(imgU3.Left-imgPir.Left);
  Up:=Sqrt(Sqr(PifA)+Sqr(PifB));

  end;

          begin  
            if (Up<Down) and (Up<Left) and (Up<Right) then
              GoT.Click
              else
                if (Down<Left) and (Down<Right) then
                  GoD.Click
                  else
                    if Right<Left then
                      GoR.Click
                      else
                        GoL.Click;
          end;
edt6.Text:='Up='+floattostr(Up);
  edt5.Text:='Down='+floattostr(Down);
    edt4.Text:='Right='+floattostr(Right);
     edt3.Text:='Left='+floattostr(Left);
     if (imgU3.Top=imgPir.Top) and (imgU3.Left=imgPir.Left) then
      begin
        GameEnd.lbl1.Caption:='Вы проиграли! :(';
        w:=GameEnd.ShowModal;
      end;
end;
end;
Until i1=DifI;
i1:=0;
end;


procedure Tstart.GoTClick(Sender: TObject);
begin
  if i1=1 then
imgU1.Top:=imgU1.Top-99
else if i1=2 then
     imgU2.Top:=imgU2.Top-99
     else if i1=3 then
          imgU3.Top:=imgU3.Top-99;
end;

procedure Tstart.GoDClick(Sender: TObject);
begin
  if i1=1 then
imgU1.Top:=imgU1.Top+99
else if i1=2 then
     imgU2.Top:=imgU2.Top+99
     else if i1=3 then
          imgU3.Top:=imgU3.Top+99;
end;

procedure Tstart.GoRClick(Sender: TObject);
begin
  if i1=1 then
imgU1.Left:=imgU1.Left+99
else if i1=2 then
     imgU2.Left:=imgU2.Left+99
     else if i1=3 then
          imgU3.Left:=imgU3.Left+99;
end;

procedure Tstart.GoLClick(Sender: TObject);
begin
  if i1=1 then
imgU1.Left:=imgU1.Left-99
else if i1=2 then
     imgU2.Left:=imgU2.Left-99
     else if i1=3 then
          imgU3.Left:=imgU3.Left-99;
end;

procedure Tstart.eatClick(Sender: TObject);
var w: Integer;
begin
                  if hour1=16 then
      begin
        food1:=food1+1;
        hour1:=8;
        Go.Click;
        hod:=hod+1;
      end
      else hour1:=16;
   food1:=food1*(-1);
   lbl5.Caption:='На '+intToStr(food1)+' дней';
   if lbl5.Caption='На 1 дней' then
   lbl5.Caption:='На сегодня';
   food1:=food1*(-1);
   hod:=hod+1;
   if food1=0 then                begin
   lbl5.Caption:='Еда кончилась';
   w:=eatF.ShowModal;             end;
end;

procedure Tstart.lbl4Click(Sender: TObject);
var w: integer;
begin
  sett.Click;
end;

procedure Tstart.rmkClick(Sender: TObject);
begin
food1:=-12;
hour1:=8;
  if StrToInt(dif.Text)=2 then  begin
  start.imgU3.Visible:=False; start.imgU2.Visible:=False;
  start.imgU3.Top:=0; start.imgU3.Left:=0;
  start.imgU2.Top:=0; start.imgU2.Left:=0
            end  else if StrToInt(dif.Text)=3 then begin
                       start.imgU3.Visible:=False; start.imgU2.Visible:=True;
                       start.imgU3.Top:=0; start.imgU3.Left:=0;
                       start.imgU2.Top:=697; start.imgU2.Left:=613;
                                 end else begin
                                          start.imgU3.Visible:=True;
                                          start.imgU2.Visible:=True;
                                          start.imgU2.Top:=697; start.imgU2.Left:=613;
                                          start.imgU3.Top:=103; start.imgU3.Left:=811;
                                          end;
imgU1.Top:=U1Top;  imgU1.Left:=U1Left;
imgPir.Top:=PirTop;
imgPir.Left:=PirLeft;
lbl5.Caption:='На 12 дней';
hod:=0;
end;

procedure Tstart.difChange(Sender: TObject);
begin
DifI:=StrToInt(dif.Text);
  if DifI=2 then
    begin
    imgU2.Visible:=False;
    imgU3.Visible:=False;
    end
    else if DifI=3 then     begin
    imgU3.Visible:=False;
    imgU2.Visible:=True;    end
           else             begin
               imgU3.Visible:=True;
               imgU2.Visible:=True;
end;
end;
procedure Tstart.settClick(Sender: TObject);
var w: Integer;
begin
  w:=setting.ShowModal;
end;

procedure Tstart.btn1Click(Sender: TObject);
begin
  Close;
end;

end.
