unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, Menus;

type
  TForm1 = class(TForm)
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Image5: TImage;
    Image6: TImage;
    Image7: TImage;
    Image8: TImage;
    Image9: TImage;
    Image10: TImage;
    Image11: TImage;
    Image12: TImage;
    Image13: TImage;
    Image14: TImage;
    Image15: TImage;
    Image16: TImage;
    MainMenu1: TMainMenu;
    hra1: TMenuItem;
    start1: TMenuItem;
    koniec1: TMenuItem;
    hraci1: TMenuItem;
    jeden1: TMenuItem;
    dvaja1: TMenuItem;
    informacie1: TMenuItem;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Timer1: TTimer;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    procedure klikni(Sender: TObject);
    procedure urob;
    procedure porovnaj(x,y:integer);
    procedure FormCreate(Sender: TObject);
    procedure koniec1Click(Sender: TObject);
    procedure start1Click(Sender: TObject);
    procedure jeden1Click(Sender: TObject);
    procedure dvaja1Click(Sender: TObject);
    procedure informacie1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
   

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  aa,bb:boolean;
  Form1: TForm1;
  c,d,p1,p2:integer;
  b:array[1..16] of integer;
  a:array[1..16] of Timage;
  info1,info2:boolean;
implementation

{$R *.DFM}

procedure TForm1.klikni(Sender: TObject);
var i,j:integer;
    bmp5:TBitmap;
begin

 if aa then
     if p1=8 then begin
                     messagedlg('GRATULUJEME',mtinformation,[mbok],0);
                     p1:=9;
                  end;
 if not aa then
     if (p1+p2)=8 then begin
                       if (p1>p2) then   messagedlg('GRATULUJEME hrovi .1',mtinformation,[mbok],0);
                       if (p1<p2) then   messagedlg('GRATULUJEME hrovi .2',mtinformation,[mbok],0);
                       if (p1=p2) then   messagedlg('GRATULUJEME',mtinformation,[mbok],0);
                          j:=9;
                       end;
 if aa then
    if p1=9 then exit;

 if not aa then
    if j=9 then exit;

 if (d=0) then begin
                i:=tButton(SENder).tag;
                bmp5:=TBitmap.create;
                if ( a[i].ParentShowHint) then
                begin
                   if b[i]=1 then begin
                                     bmp5.LoadFromFile('sedem.bmp');
                                     a[i].canvas.draw(0,0,bmp5);
                                  end;
                   if b[i]=2 then begin
                                     bmp5.LoadFromFile('osem.bmp');
                                     a[i].canvas.draw(0,0,bmp5);
                                  end;
                   if b[i]=3 then begin
                                     bmp5.LoadFromFile('dev.bmp');
                                     a[i].canvas.draw(0,0,bmp5);
                                  end;
                   if b[i]=4 then begin
                                     bmp5.LoadFromFile('desa.bmp');
                                     a[i].canvas.draw(0,0,bmp5);
                                  end;
                    if b[i]=5 then begin
                                     bmp5.LoadFromFile('vynk.bmp');
                                     a[i].canvas.draw(0,0,bmp5);
                                   end;
                    if b[i]=6 then begin
                                     bmp5.LoadFromFile('nink.bmp');
                                     a[i].canvas.draw(0,0,bmp5);
                                   end;
                    if b[i]=7 then begin
                                     bmp5.LoadFromFile('kr.bmp');
                                     a[i].canvas.draw(0,0,bmp5);
                                   end;
                    if b[i]=8 then begin
                                     bmp5.LoadFromFile('eso.bmp');
                                     a[i].canvas.draw(0,0,bmp5);
                                 end;
if (c=0) then c:=i else

                      if (c<>i)then begin
                                      d:=i;

                                     info2:=true;
                                    timer1.interval:=timer1.interval+1;
                                    end;

                     end;
         end;
end;

procedure tForm1.porovnaj(x,y:integer);
var bmp4:TBitmap;
    s:integer;
begin
 if (b[x]<>b[y]) then begin
                        bb:=not bb;
                        if aa then label3.caption:='Na ahu je hr .1.'
                        else  begin
                                if bb then  label3.caption:='Na ahu je hr .1.'
                                else label3.caption:='Na ahu je hr .2.'
                              end;

                        bmp4:=TBitmap.Create;
                        bmp4.LoadFromFile('Pozadie.bmp');
                        a[x].Canvas.Draw(0,0,bmp4);
                        a[y].Canvas.Draw(0,0,bmp4);
                      end
 else begin
         if aa then begin
                       inc(p1);
                       label1.caption:='hr .1:  '+inttostr(p1)+'b';
                     end;
         if (not aa) then  begin
                           if bb then begin
                                        inc(p1);
                                        label1.caption:='hr .1:  '+inttostr(p1)+'b';
                                       end;
                           if not bb then  begin
                                              inc(p2);
                                              label2.caption:='hr .2:  '+inttostr(p2)+'b';
                                      end;
                            end;
                            a[x].ParentShowHint:=false;
                            a[y].ParentShowHint:=false;


        end;

c:=0; d:=0;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin

 a[1]:=image1;     a[9]:=image9;
 a[2]:=image2;     a[10]:=image10;
 a[3]:=image3;     a[11]:=image11;
 a[4]:=image4;     a[12]:=image12;
 a[5]:=image5;     a[13]:=image13;
 a[6]:=image6;     a[14]:=image14;
 a[7]:=image7;     a[15]:=image15;
 a[8]:=image8;     a[16]:=image16;
 Label5.Caption:='A';  Label6.Caption:='B';
 Label7.Caption:='C';  Label8.Caption:='D';
 Label9.Caption:='1';  Label10.Caption:='2';
 Label11.Caption:='3';  Label12.Caption:='4';
 urob;
end;

procedure TForm1.urob;
var bmp3:TBitmap;
    i,j,k:integer;
begin
  p1:=0;p2:=0;c:=0;d:=0;
  {aa:=true;}
  bb:=true;info2:=false;info1:=false;info2:=false;
  Form1.Color:=clsilver;
  timer1.interval:=1000;
  Label3.Caption:='Na ahu je hr .1.';
  Label1.caption:='hr .1:  '+inttostr(p1)+'b';
  Label2.caption:='hr .2:  '+inttostr(p2)+'b';
 for i:=1 to 16 do   a[i].ParentShowHint :=true;
 bmp3:=Tbitmap.create;
 bmp3.LoadFromFile('pozadie.bmp');
 randomize;
 for i:=1 to 16 do  a[i].Canvas.draw(0,0,bmp3);

 for i:=1 to 16 do b[i]:=0;

 for j:=1 to 2 do
 for i:=1 to 8 do
 begin
  repeat
     k:=random(16)+1;
  until (b[k]=0);
  b[k]:=i;
  end;

end;

procedure TForm1.koniec1Click(Sender: TObject);
begin
halt;
Form1.Color:=clScrollBar;
end;

procedure TForm1.start1Click(Sender: TObject);
begin
 urob;
end;

procedure TForm1.jeden1Click(Sender: TObject);
begin
 label2.visible:=false;
 label3.Visible:=false;
 UROB;
 aa:=true;
end;

procedure TForm1.dvaja1Click(Sender: TObject);
begin
 label2.Visible:=true;
 label3.Visible:=true;
 UROB;
 aa:=false;
end;

procedure TForm1.informacie1Click(Sender: TObject);
begin
   info1:= not info1;
   if info1 then label4.visible:=true
   else  label4.visible:=false;
   Label4.caption:='Autor:  Michal Sta ';

end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if info2 then  begin
           info2:=false;
           porovnaj(c,d);
           end;
end;
end.