Logická hra zápalky, posledný prehráva

Delphi & Pascal (èeská wiki)
Pøejít na: navigace, hledání
Kategórie: KMP (Programy mladých programátorù)
z35.pngAutor: Martin Truben
Program: Z35.pas
Soubor exe: Z35.exe

Toto je hra zápalky. Je to jednoduchá logická hra, v ktorej mô¾ete hra» buï proti poèítaèu, alebo proti ïal¹iemu hráèovi. Na zaèiatku hry sú 3 kopy v ktorých sú zápalky. Hráèi si striedavo za sebou »ahajú z týchto kôp. Ten kto u¾ nemô¾e »aha», preto¾e u¾ nie je v ¾iadnej kope zápalka, prehráva.
{ Z35.PAS                                                           }
{ Toto je hra zapalky. Je to jednoducha logicka hra, v ktorej       }
{ mozete hrat bud proti pocitacu alebo proti dalsiemu hracovi.      }
{ Na zaciatku hry su 3 kopy v ktorych su zapalky. Hraci si striedavo}
{ za sebou tahaju z tychto kop. Ten kto si uz nemoze tahat, pretoze }
{ uz nie je v ziadnej kope zapalka, prehrava.                       }
{                                                                   }
{ Author: Martin Truben                                             }
{ Datum: 12.10.2005                           http://www.trsek.com  }
 
program z35;
uses crt;
var stlp, stlp2, stlp3, z1, z2, z3,  kopa4, pocet, tahac, zap1, zap2, zap3 : integer;
    uvod, ukoncenie, xx, yy, spust,xxx, textcol1, textcol2,  yyy, xxx2, yyy2 : integer; {procedure uvodom}
    meno2, meno, spustam : string;
    zaciatok1, nekoncim : boolean;
 
procedure vyhralsi;
begin
 
    clrscr;
  xxx:=7;
  yyy:=3;
  textmode(1000);
  textcol1:=1;
  repeat
    textcolor(textcol1);
    clrscr;
    gotoxy(xxx,yyy-2);write ('Gratulujem ti ');
    gotoxy(xxx,yyy);write  ('          ');
    gotoxy(xxx,yyy+3);write('      o ');
    gotoxy(xxx,yyy+5);write('         ');
    gotoxy(xxx,yyy+6);write('         ');
    gotoxy(xxx,yyy+7);write('         ');
    gotoxy(xxx,yyy+8);write('       ');
    gotoxy(xxx,yyy+9);write('     ');
    textcol1:=textcol1+1;
    if (textcol1=15) then textcol1:=1;
    xxx:=xxx+1;
    yyy:=yyy+1;
 
    delay(100);
  until (xxx=32);
   xxx2:=34;
  yyy2:=25;
   textcol2:=1;
   repeat
   textcolor(textcol2);
    clrscr;
    gotoxy(xxx2,yyy2-2);write('  k vyhre  ');
    gotoxy(xxx2,yyy2);write  ('          ');
    gotoxy(xxx2,yyy2+3);write('     o ');
    gotoxy(xxx2,yyy2+5);write('        ');
    gotoxy(xxx2,yyy2+6);write('        ');
    gotoxy(xxx2,yyy2+7);write('        ');
    gotoxy(xxx2,yyy2+8);write('      ');
    gotoxy(xxx2,yyy2+9);write('    ');
    textcol2:=textcol2+1;
    if (textcol2=15) then textcol2:=1;
    xxx2:=xxx2+1;
    yyy2:=yyy2-1;
    delay(100);
    until(yyy2=2);
end;
 
 
 
procedure RozdelenieKop;
begin
    clrscr;
  textcolor(white);
  gotoxy(2,2);write(' ',meno,', napis pocet zapaliek v 1. stlpci (max.999)  ');
  readln(z1);
  if (z1<0) or (z1>999) then
  repeat
  clrscr;
  gotoxy(2,2);
  if (z1<0) then
  begin
    clrscr;
    gotoxy(2,2);
    write(' ',meno,', Toto cislo musi byt kladne, zadaj nove cislo ');
  end;
  if (z1>999) then
  begin
    clrscr;
    gotoxy(2,2);
    write(' ',meno,', Zadaj cislo do 999 ')
  end;
  readln(z1);
  until (z1>-1) and (z1<1000);
  textcolor(blue);
  clrscr;
  gotoxy(2,2);write(' ',meno,', napis pocet zapaliek v 2. stlpci (max999)  ');
  readln(z2);
  if (z2<0) or (z2>999) then
  repeat
  clrscr;
  gotoxy(2,2);
  if (z2<0) then
  begin
    clrscr;
    gotoxy(2,2);
    write(' ',meno,', Toto cislo musi byt kladne, zadaj nove cislo ');
  end;
  if (z2>999) then
  begin
    clrscr;
    gotoxy(2,2);
    write(' ',meno,', Zadaj cislo do 999 ');
  end;
  readln(z2);
  until(z2>-1) and (z2<1000);
  textcolor(red);
  clrscr;
  gotoxy(2,2);write(' ',meno,', napis pocet zapaliek v 3. stlpci (max999) ');
  readln(z3);
  if (z3<0) or (z3>999) then
  repeat
  clrscr;
  gotoxy(2,2);
  if (z3<0) then
  begin
    clrscr;
    gotoxy(2,2);
    write(' ',meno,', Toto cislo musi byt kladne, zadaj nove cislo ');
  end;
  if (z3>999) then
  begin
    clrscr;
    gotoxy(2,2);
    write(' ',meno,', Zadaj cislo do 999 ');
  end;
  readln(z3);
  until (z3>-1) and (z3<1000);
end;
 
 
 
 
 
procedure TahHraca1( var k1, k2, k3 : integer);
begin
    textcolor(7);
    writeln(' º     º     º     º ');
    write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',meno,', napis stlpec z ktoreho chces tahat ');
    read(kopa4);
    if (kopa4=1) and (k1=0) then
      repeat
        begin
          write(' º     º     º     º   ',meno,', tu nie su zapalky,tahaj z ineho stlpca ');
          readln(kopa4);
        end;
      until (kopa4=2) or (kopa4=3);
    if (kopa4=2) and (k2=0) then
      repeat
        begin
          write(' º     º     º     º   ',meno,', tu nie su zapalky,tahaj z ineho stlpca ');
          readln(kopa4);
        end;
      until (kopa4=1) or (kopa4=3);
    if (kopa4=3) and (k3=0) then
      repeat
        begin
          write(' º     º     º     º   ',meno,', tu nie su zapalky,tahaj z ineho stlpca ');
          readln(kopa4);
        end;
      until (kopa4=1) or (kopa4=2);
    repeat
      if (kopa4<1) or (kopa4>3) then
        begin
          write(' º     º     º     º   ',meno,', su iba tri stlpce, tahaj si z troch stlpcov ');
          read(kopa4);
        end;
    until (kopa4>0) and (kopa4<4);
    write(' º     º     º     º   ',meno,', napis kolko zapaliek chces tahat ');
    read(pocet);
    repeat
      if (pocet<1)  then
        begin
          write(' º     º     º     º   ',meno,', tak sa tahat neda, tahaj znova     ');
          read(pocet);
        end;
 
      if (kopa4=1)  then
        begin
          repeat
            if (pocet>k1) then
              begin
                write(' º     º     º     º   ',meno,', tolko zapaliek v kope nezostalo, tahaj znova ');
                read(pocet);
              end;
          until (pocet=k1) or (pocet<k1);
        end;
 
      if (kopa4=2)  then
        begin
          repeat
            if (pocet>k2) then
              begin
                write(' º     º     º     º   ',meno,', tolko zapaliek v kope nezostalo, tahaj znova ');
                read(pocet);
              end;
          until (pocet=k2) or (pocet<k2);
        end;
 
      if (kopa4=3)  then
        begin
          repeat
            if (pocet>k3) then
              begin
                write(' º     º     º     º   ',meno,', tolko zapaliek v kope nezostalo, tahaj znova ');
                read(pocet);
              end;
          until (pocet=k3) or (pocet<k3);
        end;
    until (pocet>0);
    case kopa4 of
    1 : if (k1-pocet)>-1 then k1:=k1-pocet;
    2 : if (k2-pocet)>-1 then k2:=k2-pocet;
    3 : if (k3-pocet)>-1 then k3:=k3-pocet;
   end;
end;
 
 
 
 
procedure TahHraca(var k1, k2, k3 : integer);
begin
    textcolor(7);
    writeln(' º     º     º     º ');
    write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',meno2,', napis stlpec z ktoreho chces tahat ');
    read(kopa4);
    if (kopa4=1) and (k1=0) then
      repeat
        begin
          write(' º     º     º     º   ',meno2,', tu nie su zapalky,tahaj z ineho stlpca ');
          readln(kopa4);
        end;
      until (kopa4=2) or (kopa4=3);
    if (kopa4=2) and (k2=0) then
      repeat
        begin
          write(' º     º     º     º   ',meno2,', tu nie su zapalky,tahaj z ineho stlpca ');
          readln(kopa4);
        end;
      until (kopa4=1) or (kopa4=3);
    if (kopa4=3) and (k3=0) then
      repeat
        begin
          write(' º     º     º     º   ',meno2,', tu nie su zapalky,tahaj z ineho stlpca ');
          readln(kopa4);
        end;
      until (kopa4=1) or (kopa4=2);
    repeat
      if (kopa4<1) or (kopa4>3) then
        begin
          write(' º     º     º     º   ',meno2,', su iba tri stlpce, tahaj si z troch stlpcov ');
          read(kopa4);
        end;
    until (kopa4>0) and (kopa4<4);
    write(' º     º     º     º   ',meno2,', napis kolko zapaliek chces tahat ');
    read(pocet);
    repeat
      if (pocet<1)  then
        begin
          write(' º     º     º     º   ',meno2,', tak sa tahat neda, tahaj znova     ');
          read(pocet);
        end;
 
      if (kopa4=1)  then
        begin
          repeat
            if (pocet>k1) then
              begin
                write(' º     º     º     º   ',meno2,', tolko zapaliek v kope nezostalo, tahaj znova ');
                read(pocet);
              end;
          until (pocet=k1) or (pocet<k1);
        end;
 
      if (kopa4=2)  then
        begin
          repeat
            if (pocet>k2) then
              begin
                write(' º     º     º     º   ',meno2,', tolko zapaliek v kope nezostalo, tahaj znova ');
                read(pocet);
              end;
          until (pocet=k2) or (pocet<k2);
        end;
 
      if (kopa4=3)  then
        begin
          repeat
            if (pocet>k3) then
              begin
                write(' º     º     º     º   ',meno2,', tolko zapaliek v kope nezostalo, tahaj znova ');
                read(pocet);
              end;
          until (pocet=k3) or (pocet<k3);
        end;
    until (pocet>0);
    case kopa4 of
    1 : if (k1-pocet)>-1 then k1:=k1-pocet;
    2 : if (k2-pocet)>-1 then k2:=k2-pocet;
    3 : if (k3-pocet)>-1 then k3:=k3-pocet;
   end;
end;
 
 
 
procedure TahPocitaca(var k1, k2, k3 : integer);
begin
 
  if (k1>(k2 xor k3)) then
    begin
    textcolor(2);
      write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ','          taham z 1. stlpca: ',k1-(k2 xor k3));
        if (k1-(k2 xor k3)=0) then
          writeln (' zapaliek               ');
        if (k1-(k2 xor k3)=1) then
          writeln (' zapalku                ');
        if (k1-(k2 xor k3)>1) and (k1-(k2 xor k3)<5) then
          writeln (' zapalky                ');
        if (k1-(k2 xor k3)>4) then
          writeln (' zapaliek               ');
      if k1-(k2 xor k3)>-1 then k1 := (k2 xor k3);
       write(' º     º     º     º   ');
      writeln(' ');
      exit
    end;
 
randomize;
stlp:=random(2)+1;
zap1:=random(k1)+1;
zap2:=random(k2)+1;
zap3:=random(k3)+1;
  if ((k1-(k2 xor k3))=0) then
  begin
  textcolor(2);
    if (k2>0) and (k3=0) then
      begin
        write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 2. stlpca: ',zap2);
        if (zap2=0) then
          writeln (' zapaliek               ');
        if (zap2=1) then
          writeln (' zapalku                ');
        if (zap2>1) and (zap2<5) then
          writeln (' zapalky                ');
        if (zap2>4) then
          writeln (' zapaliek               ');
        k2:= (k2-zap2);
       write(' º     º     º     º   ');
      writeln(' ');
      exit
      end;
    if (k2=0) and (k3>0) then
      begin
        write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 3. stlpca: ',zap3);
        if (zap3=0) then
          writeln (' zapaliek               ');
        if (zap3=1) then
          writeln (' zapalku                ');
        if (zap3>1) and (zap3<5) then
          writeln (' zapalky                ');
        if (zap3>4) then
          writeln (' zapaliek               ');
        k3:= (k3-zap3);
        write(' º     º     º     º   ');
        writeln(' ');
        exit
      end;
    if (k2>0) and (k3>0) then
      begin
        if (stlp=1) then
        begin
          write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 2. stlpca: ',zap2);
          if (zap2=0) then
            writeln (' zapaliek               ');
          if (zap2=1) then
            writeln (' zapalku                ');
          if (zap2>1) and (zap2<5) then
            writeln (' zapalky                ');
          if (zap2>4) then
            writeln (' zapaliek               ');
          k2:= (k2-zap2);
          write(' º     º     º     º   ');
          writeln(' ');
        end;
        if (stlp=2) then
        begin
          write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 3. stlpca: ',zap3);
          if (zap3=0) then
            writeln (' zapaliek               ');
          if (zap3=1) then
            writeln (' zapalku                ');
          if (zap3>1) and (zap3<5) then
            writeln (' zapalky                ');
          if (zap3>4) then
            writeln (' zapaliek               ');
          k3:= (k3-zap3);
          write(' º     º     º     º   ');
          writeln(' ');
        end;
      end;
      exit
  end;
 
    if (k2>(k1 xor k3)) then
    begin
    textcolor(2);
      write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ','          taham z 2. stlpca: ',k2-(k1 xor k3));
        if (k2-(k1 xor k3)=0) then
          writeln (' zapaliek               ');
        if (k2-(k1 xor k3)=1) then
          writeln (' zapalku                ');
        if (k2-(k1 xor k3)>1) and (k2-(k1 xor k3)<5) then
          writeln (' zapalky                ');
        if (k2-(k1 xor k3)>4) then
          writeln (' zapaliek               ');
      if k2-(k1 xor k3)>-1 then k2 := (k1 xor k3);
      write(' º     º     º     º   ');
      writeln(' ');
      exit
    end;
 
randomize;
stlp2:=random(2)+1;
 
  if ((k2-(k1 xor k3))=0) then
  begin
  textcolor(2);
    if (k1>0) and (k3=0) then
      begin
        write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 1. stlpca: ',zap1);
          if (zap1=0) then
            writeln (' zapaliek               ');
          if (zap1=1) then
            writeln (' zapalku                ');
          if (zap1>1) and (zap1<5) then
            writeln (' zapalky                ');
          if (zap1>4) then
            writeln (' zapaliek               ');
        k1:= (k1-zap1);
        write(' º     º     º     º   ');
        writeln(' ');
        exit
      end;
    if (k1=0) and (k3>0) then
      begin
        write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 3. stlpca: ',zap3);
          if (zap3=0) then
            writeln (' zapaliek               ');
          if (zap3=1) then
            writeln (' zapalku                ');
          if (zap3>1) and (zap3<5) then
            writeln (' zapalky                ');
          if (zap3>4) then
            writeln (' zapaliek               ');
        k3:= (k3-zap3);
        write(' º     º     º     º   ');
        writeln(' ');
        exit
      end;
    if (k1>0) and (k3>0) then
      begin
        if (stlp2=1) then
        begin
          write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 1. stlpca: ',zap1);
          if (zap1=0) then
            writeln (' zapaliek               ');
          if (zap1=1) then
            writeln (' zapalku                ');
          if (zap1>1) and (zap1<5) then
            writeln (' zapalky                ');
          if (zap1>4) then
            writeln (' zapaliek               ');
          k1:= (k1-zap1);
          write(' º     º     º     º   ');
          writeln(' ');
        end;
        if (stlp2=2) then
        begin
           write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 3. stlpca: ',zap3);
          if (zap3=0) then
            writeln (' zapaliek               ');
          if (zap3=1) then
            writeln (' zapalku                ');
          if (zap3>1) and (zap3<5) then
            writeln (' zapalky                ');
          if (zap3>4) then
            writeln (' zapaliek               ');
           k3:= (k3-zap3);
           write(' º     º     º     º   ');
           writeln(' ');
           exit
        end;
      end;
      exit
  end;
 
    if (k3>(k2 xor k1)) then
    begin
    textcolor(2);
      write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ','          taham z 3. stlpca: ',k3-(k2 xor k1));
        if (k3-(k2 xor k1)=0) then
          writeln (' zapaliek               ');
        if (k3-(k2 xor k1)=1) then
          writeln (' zapalku                ');
        if (k3-(k2 xor k1)>1) and (k3-(k2 xor k1)<5) then
          writeln (' zapalky                ');
        if (k3-(k2 xor k1)>4) then
          writeln(' zapaliek               ');
      if k3-(k2 xor k1)>-1 then k3 := (k2 xor k1);
      write(' º     º     º     º   ');
      writeln(' ');
      exit
    end;
 
randomize;
stlp3:=random(2)+1;
 
  if ((k3-(k2 xor k1))=0) then
  begin
  textcolor(2);
    if (k1>0) and (k2=0) then
      begin
        write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 1. stlpca: ',zap1);
          if (zap1=0) then
            writeln (' zapaliek               ');
          if (zap1=1) then
            writeln (' zapalku                ');
          if (zap1>1) and (zap1<5) then
            writeln (' zapalky                ');
          if (zap1>4) then
            writeln (' zapaliek               ');
        k1:= (k1-zap1);
        write(' º     º     º     º   ');
        writeln(' ');
        exit
      end;
    if (k1=0) and (k2>0) then
      begin
        write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 2. stlpca: ',zap2);
          if (zap2=0) then
            writeln (' zapaliek               ');
          if (zap2=1) then
            writeln (' zapalku                ');
          if (zap2>1) and (zap2<5) then
            writeln (' zapalky                ');
          if (zap2>4) then
            writeln (' zapaliek               ');
        k2:= (k2-zap2);
        write(' º     º     º     º   ');
        writeln(' ');
        exit
      end;
    if (k1>0) and (k2>0) then
      begin
        if (stlp3=1) then
        begin
          write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 1. stlpca: ',zap1);
          if (zap1=0) then
            writeln (' zapaliek               ');
          if (zap1=1) then
            writeln (' zapalku                ');
          if (zap1>1) and (zap1<5) then
            writeln (' zapalky                ');
          if (zap1>4) then
            writeln (' zapaliek               ');
          k1:= (k1-zap1);
          write(' º     º     º     º   ');
          writeln(' ');
        end;
        if (stlp3=2) then
        begin
           write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 2. stlpca: ',zap2);
          if (zap2=0) then
            writeln (' zapaliek               ');
          if (zap2=1) then
            writeln (' zapalku                ');
          if (zap2>1) and (zap2<5) then
            writeln (' zapalky                ');
          if (zap2>4) then
            writeln (' zapaliek               ');
           k2:= (k2-zap2);
           write(' º     º     º     º   ');
           writeln(' ');
        end;
      end;
      exit
  end;
 
end;
 
 
 
procedure TahPocitacaLahky(var k1, k2, k3 : integer);
begin
 
randomize;
 
 
 
randomize;
stlp:=random(2)+1;
 
 
  if (k1>0) then
    begin
        write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 1. stlpca: zopar zapaliek');
        k1:= (k1-(random(k1)+1));
        writeln(' ');
        exit
    end
  else
  begin
  textcolor(2);
    if (k2>0) and (k3=0) then
      begin
        write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 2. stlpca: zopar zapaliek');
        k2:= (k2-(random(k2)+1));
        writeln(' ');
        exit
      end;
    if (k2=0) and (k3>0) then
      begin
        write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 3. stlpca: zopar zapaliek');
        k3:= (k3-(random(k3)+1));
        writeln(' ');
        exit
      end;
    if (k2>0) and (k3>0) then
      begin
        if (stlp=1) then
        begin
          write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 2. stlpca: zopar zapaliek');
          k2:= (k2-(random(k2)+1));
          writeln(' ');
        end;
        if (stlp=2) then
        begin
          write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 3. stlpca: zopar zapaliek');
          k3:= (k3-(random(k3)+1));
          writeln(' ');
        end;
      end;
      exit
  end;
 
 
 
randomize;
stlp2:=random(2)+1;
 
  if (k2>0) then
    begin
        write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 2. stlpca: zopar zapaliek');
        k2:= (k2-(random(k2)+1));
        writeln(' ');
        exit
    end
    else
  begin
  textcolor(2);
    if (k1>0) and (k3=0) then
      begin
        write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 1. stlpca: zopar zapaliek');
        k1:= (k1-(random(k1)+1));
        writeln(' ');
        exit
      end;
    if (k1=0) and (k3>0) then
      begin
        write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 3. stlpca: zopar zapaliek');
        k3:= (k3-(random(k3)+1));
        writeln(' ');
        exit
      end;
    if (k1>0) and (k3>0) then
      begin
        if (stlp2=1) then
        begin
          write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 1. stlpca: zopar zapaliek');
          k1:= (k1-(random(k1)+1));
          writeln(' ');
        end;
        if (stlp2=2) then
        begin
           write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 3. stlpca: zopar zapaliek');
           k3:= (k3-(random(k3)+1));
           writeln(' ');
           exit
        end;
      end;
      exit
  end;
 
 
randomize;
stlp3:=random(2)+1;
 
  if (k3>0) then
    begin
        write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 3. stlpca: zopar zapaliek');
        k3:= (k3-(random(k3)+1));
        writeln(' ');
        exit
    end
    else
  begin
  textcolor(2);
    if (k1>0) and (k2=0) then
      begin
        write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 1. stlpca: zopar zapaliek');
        k1:= (k1-(random(k1)+1));
        writeln(' ');
        exit
      end;
    if (k1=0) and (k2>0) then
      begin
        write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 2. stlpca: zopar zapaliek');
        k2:= (k2-(random(k2)+1));
        writeln(' ');
        exit
      end;
    if (k1>0) and (k2>0) then
      begin
        if (stlp3=1) then
        begin
          write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 1. stlpca: zopar zapaliek');
          k1:= (k1-(random(k1)+1));
          writeln(' ');
        end;
        if (stlp3=2) then
        begin
           write(' º ',k1:3,' º ',k2:3,' º ',k3:3,' º   ',' taham z 2. stlpca: zopar zapaliek');
           k2:= (k2-(random(k2)+1));
           writeln(' ');
        end;
      end;
      exit
  end;
 
end;
 
 
 
 
var x, y, gd, gm, u, i, lt, hra, kopa1, kopa2, tah, kopa3, zaciatok, zaciatok2 :integer;
    zap, vyhra, prehra : boolean;
    a, b : string;
 
 
 
 
begin
  clrscr;
  zap:=false;
  vyhra:=false;
  tah:=0;
  x:=2;
  y:=3;
  u:=0;
 
 
 
begin
    spustam:= '.';
    zaciatok1:= false;
    nekoncim:=false;
    textcolor(6);
    gotoxy(4,12);write('Program sa spusta');
    for spust := 1 to 50 do
    begin
      write(spustam);
      delay(30);
    end;
    textmode(100);
    clrscr;
    gotoxy(2,2);
    textcolor(9);write('1.');
    textcolor(15); writeln('Nova hra ');
    textcolor(9);write(' 2.');
    textcolor(15); writeln('Navod ku hre ');
    textcolor(9);write(' 3.');
    textcolor(15); writeln('Koniec ');
    gotoxy(2,7);write('Vyber si co chces urobit: ');
    read(uvod);
    repeat
    if (uvod<1) or (uvod>3) then
      begin
        gotoxy(2,10);
        textcolor(15);write('zadaj ');
        textcolor(9);write('1. 2. ');
        textcolor(15);write('alebo ');
        textcolor(9);write('3. ');
        gotoxy(26,10);write('        ');
        gotoxy(26,10);read(uvod);
 
      end;
    until (uvod=1) or (uvod=2) or (uvod=3);
 
    xx:=13;
    yy:=13;
 
    if (uvod=1) then zaciatok1:= true;
 
    if (uvod=2) then
    begin
      textcolor(2);
      repeat
        gotoxy(1,xx);  write('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»');
        gotoxy(1,xx+1);write('º                                                                             º');
        gotoxy(1,yy);  write('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ');
        gotoxy(1,yy-1);write('º                                                                             º');
        xx:=xx-1;
        yy:=yy+1;
        delay(60);
        if (yy=26) then
       begin
 
        textcolor(14);
        textbackground(4);
        gotoxy(2,2);
        writeln('  Toto je hra zapalky. Je to jednoducha logicka hra, v ktorej mozete hrat    ');
        gotoxy(2,3);writeln('  bud proti pocitacu alebo proti dalsiemu hracovi. Na zaciatku hry su 3      ');
        gotoxy(2,4);writeln('  kopy v ktorych su zapalky. Hraci si striedavo za sebou tahaju z tychto     ');
        gotoxy(2,5);writeln('  kop. Ten kto si uz nemoze tahat, pretoze uz nie je v ziadnej kope          ');
        gotoxy(2,6);writeln('  zapalka, prehrava.                                                         ');
       end;
      until (yy=26);
      readln;
    end;
      readln;
 
 
    if (uvod=3) then
    begin
      textcolor(10);
      gotoxy(2,13);write(' To vazne chces uz ukoncit tuto hru (a/n)? ');
      writeln;
      writeln;
      textcolor(9);write('         1. ');
      textcolor(15); writeln('ano ');
      writeln;
      textcolor(9);write('         2. ');
      textcolor(15); writeln('nie ');
      gotoxy(46,13);read(ukoncenie);
      repeat
        if (ukoncenie<1) or (ukoncenie>2) then
          begin
            gotoxy(10,19);
            textcolor(15);write('zadaj ');
            textcolor(9);write('1. ');
            textcolor(15);write('alebo ');
            textcolor(9);write('2. ');
            gotoxy(29,19);write('        ');
            gotoxy(29,19);read(ukoncenie);
 
         end;
      until (ukoncenie=1) or (ukoncenie=2);
      if (ukoncenie=2) then nekoncim:=true;
      readln;
    end;
end;
 
 
 
    if (zaciatok1) or (nekoncim) then
    begin
    clrscr;
    textmode(100);
    gotoxy(31,7);
    textcolor(10);
    write(' Ako sa volas ? ');
    read(meno);
    textcolor(10);
    gotoxy(10,9);write('vyber si ci chces hrat proti ');
    gotoxy(10,11);
    textcolor(9);write('1. ');
    textcolor(15);write('pocitacu ');
    gotoxy(10,13);
    textcolor(9);write('2. ');
    textcolor(15);write('alebo proti inemu hracovi ');
    read(hra);
    repeat
    if (hra<1) or (hra>2) then
      begin
        gotoxy(15,17);
        textcolor(15);write('zadaj ');
        textcolor(9);write('1. ');
        textcolor(15);write('alebo ');
        textcolor(9);write('2. ');
        gotoxy(33,17);write('        ');
        gotoxy(33,17);read(hra);
 
      end;
    until (hra=1) or (hra=2);
  if(hra=1) then
    begin
      clrscr;
      readln(a);
      gotoxy(30,7);
      textcolor(10);
      write('vyber si typ hry ');
    gotoxy(10,11);
    textcolor(9);write('1. ');
    textcolor(15);write('lahka ');
    gotoxy(10,13);
    textcolor(9);write('2. ');
    textcolor(15);write('tazka ');
    readln(lt);
    repeat
    if (lt<1) or (lt>2) then
      begin
        gotoxy(15,17);
        textcolor(15);write('zadaj ');
        textcolor(9);write('1. ');
        textcolor(15);write('alebo ');
        textcolor(9);write('2. ');
        gotoxy(33,17);write('        ');
        gotoxy(33,17);read(lt);
 
      end;
    until (lt=1) or (lt=2);
    end;
    if (lt=2) then
    begin
      begin
        clrscr;
        gotoxy(25,11);
        textcolor(10);write('vyber si kto zacina tuto hru: ');
        gotoxy(15,13);
        textcolor(9); write('1.');
        textcolor(15);write(' zacinas ty');
        gotoxy(15,15);
        textcolor(9); write('2.');
        textcolor(15);write(' zacina pocitac  ');
        read(zaciatok);
      end;
    repeat
    if (zaciatok<1) or (zaciatok>2) then
      begin
        gotoxy(15,17);
        textcolor(15);write('zadaj ');
        textcolor(9);write('1. ');
        textcolor(15);write('alebo ');
        textcolor(9);write('2. ');
        gotoxy(33,17);write('        ');
        gotoxy(33,17);read(zaciatok);
 
      end;
    until (zaciatok=1) or (zaciatok=2);
    end;
  if (zaciatok=1) then
 
  begin
  RozdelenieKop;
  begin
    clrscr;
    kopa1 :=z1;
    kopa2 :=z2;
    kopa3 :=z3;
    textbackground(0);
    textcolor(15);
    write('                                                             ');
    textbackground(1);
    write('Zapalky');
    textbackground(4);
    writeln('(verzia1)');
    textcolor(7);
    textbackground(0);
    write(' É');textcolor(white);write('ÍÍÍÍÍ');
    textcolor(7);write('Ë');textcolor(blue);write('ÍÍÍÍÍ');
    textcolor(7);write('Ë');textcolor(red);write('ÍÍÍÍÍ');
    textcolor(7);writeln('» ');
    writeln(' º ',kopa1:3,' º ',kopa2:3,' º ',kopa3:3,' º');
    writeln(' ºÄÄÄÄĺÄÄÄÄĺÄÄÄÄĺ  ');
    gotoxy(1,y+1);
    repeat
   TahHraca1(kopa1, kopa2, kopa3);
   if (Kopa1=Kopa2) and (kopa2=kopa3) and (kopa3=0) then vyhra:= true;
   TahPocitaca(kopa1, kopa2, kopa3);
   if (Kopa1=Kopa2) and (kopa2=kopa3) and (kopa3=0) then prehra:=true;
  y:=y+2;
  x:=x+2;
  u:=u+5;
  tah:= tah+1;
 
     until (Kopa1=Kopa2) and (kopa2=kopa3) and (kopa3=0);
   writeln(' º     º     º     º   ');
   writeln(' º ',kopa1:3,' º ',kopa2:3,' º ',kopa3:3,' º');
   writeln(' ÈÍÍÍÍÍÊÍÍÍÍÍÊÍÍÍÍͼ ':15);
       if vyhra then
       begin
    writeln ('                        ',meno,', to je tvoja vyhra!');
    if tah=1 then write('                          vyhral si na ',tah,' tah');
    if (tah>1) and (tah<5) then write('                          vyhral si na ',tah,' tahy');
    if (tah>4) then write('                          vyhral si na ',tah,' tahov');
    readln;
    readln;
    vyhralsi;
       end
    else
    begin
    writeln ('                          ',meno,', prehral si!');
    if tah=1 then write('                         pocitac vyhral na ',tah,' tah');
    if (tah>1) and (tah<5) then write('                         pocitac vyhral na ',tah,' tahy');
    if (tah>4) then write('                         pocitac vyhral na ',tah,' tahov');
    readln;
    end;
 
  end;
  readln;
  end;
 
 
 
 
 
  if (zaciatok=2) then
  begin
  RozdelenieKop;
  begin
    clrscr;
    kopa1 :=z1;
    kopa2 :=z2;
    kopa3 :=z3;
    textbackground(0);
    textcolor(15);
    write('                                                             ');
    textbackground(1);
    write('Zapalky');
    textbackground(4);
    writeln('(verzia1)');
    textcolor(7);
    textbackground(0);
    textcolor(7);
    write(' É');textcolor(white);write('ÍÍÍÍÍ');
    textcolor(7);write('Ë');textcolor(blue);write('ÍÍÍÍÍ');
    textcolor(7);write('Ë');textcolor(red);write('ÍÍÍÍÍ');
    textcolor(7);writeln('» ');
    writeln(' º ',kopa1:3,' º ',kopa2:3,' º ',kopa3:3,' º');
    writeln(' ºÄÄÄÄĺÄÄÄÄĺÄÄÄÄĺ ');
    gotoxy(1,y+1);
    TahPocitaca(kopa1, kopa2, kopa3);
    repeat
   TahHraca1(kopa1, kopa2, kopa3);
   if (Kopa1=Kopa2) and (kopa2=kopa3) and (kopa3=0) then vyhra:= true;
   TahPocitaca(kopa1, kopa2, kopa3);
   if (Kopa1=Kopa2) and (kopa2=kopa3) and (kopa3=0) then prehra:=true;
  y:=y+2;
  x:=x+2;
  u:=u+5;
  tah:= tah+1;
 
     until (Kopa1=Kopa2) and (kopa2=kopa3) and (kopa3=0);
   writeln(' º     º     º     º   ');
   writeln(' º ',kopa1:3,' º ',kopa2:3,' º ',kopa3:3,' º');
   writeln(' ÈÍÍÍÍÍÊÍÍÍÍÍÊÍÍÍÍͼ ':15);
       if vyhra then
       begin
    writeln ('                        ',meno,', to je tvoja vyhra!');
    if tah=1 then write('                          vyhral si na ',tah,' tah');
    if (tah>1) and (tah<5) then write('                          vyhral si na ',tah,' tahy');
    if (tah>4) then write('                          vyhral si na ',tah,' tahov');
    readln;
    readln;
    vyhralsi;
       end
    else
    begin
    writeln ('                          ',meno,', prehral si!');
    if tah=1 then write('                         pocitac vyhral na ',tah,' tah');
    if (tah>1) and (tah<5) then write('                         pocitac vyhral na ',tah,' tahy');
    if (tah>4) then write('                         pocitac vyhral na ',tah,' tahov');
    readln;
    end;
 
  end;
  readln;
  end;
 
 
 
  if(lt=1) then
    begin
    begin
      begin
        clrscr;
        gotoxy(25,11);
        textcolor(10);write('vyber si kto zacina tuto hru: ');
        gotoxy(15,13);
        textcolor(9); write('1.');
        textcolor(15);write(' zacinas ty');
        gotoxy(15,15);
        textcolor(9); write('2.');
        textcolor(15);write(' zacina pocitac  ');
        read(zaciatok);
      end;
    repeat
    if (zaciatok<1) or (zaciatok>2) then
      begin
        gotoxy(15,17);
        textcolor(15);write('zadaj ');
        textcolor(9);write('1. ');
        textcolor(15);write('alebo ');
        textcolor(9);write('2. ');
        gotoxy(33,17);write('        ');
        gotoxy(33,17);read(zaciatok);
 
      end;
    until (zaciatok=1) or (zaciatok=2);
    end;
  if (zaciatok=1) then
 
  begin
  RozdelenieKop;
  begin
    clrscr;
    kopa1 :=z1;
    kopa2 :=z2;
    kopa3 :=z3;
    textbackground(0);
    textcolor(15);
    write('                                                             ');
    textbackground(1);
    write('Zapalky');
    textbackground(4);
    writeln('(verzia1)');
    textcolor(7);
    textbackground(0);
    textcolor(7);
    write(' É');textcolor(white);write('ÍÍÍÍÍ');
    textcolor(7);write('Ë');textcolor(blue);write('ÍÍÍÍÍ');
    textcolor(7);write('Ë');textcolor(red);write('ÍÍÍÍÍ');
    textcolor(7);writeln('» ');
    writeln(' º ',kopa1:3,' º ',kopa2:3,' º ',kopa3:3,' º');
    writeln(' ºÄÄÄÄĺÄÄÄÄĺÄÄÄÄĺ ');
    gotoxy(1,y+1);
    repeat
   TahHraca1(kopa1, kopa2, kopa3);
   if (Kopa1=Kopa2) and (kopa2=kopa3) and (kopa3=0) then vyhra:= true;
   TahPocitacaLahky(kopa1, kopa2, kopa3);
   if (Kopa1=Kopa2) and (kopa2=kopa3) and (kopa3=0) then prehra:=true;
  y:=y+2;
  x:=x+2;
  u:=u+5;
  tah:= tah+1;
 
     until (Kopa1=Kopa2) and (kopa2=kopa3) and (kopa3=0);
   writeln(' º     º     º     º   ');
   writeln(' º ',kopa1:3,' º ',kopa2:3,' º ',kopa3:3,' º');
   writeln(' ÈÍÍÍÍÍÊÍÍÍÍÍÊÍÍÍÍͼ ':15);
       if vyhra then
       begin
    writeln ('                        ',meno,', to je tvoja vyhra!');
    if tah=1 then write('                          vyhral si na ',tah,' tah');
    if (tah>1) and (tah<5) then write('                          vyhral si na ',tah,' tahy');
    if (tah>4) then write('                          vyhral si na ',tah,' tahov');
    readln;
    readln;
    vyhralsi;
       end
    else
    begin
    writeln ('                          ',meno,', prehral si!');
    if tah=1 then write('                         pocitac vyhral na ',tah,' tah');
    if (tah>1) and (tah<5) then write('                         pocitac vyhral na ',tah,' tahy');
    if (tah>4) then write('                         pocitac vyhral na ',tah,' tahov');
    readln;
    end;
 
  end;
  readln;
  end;
 
 
 
 
 
  if (zaciatok=2) then
  begin
  RozdelenieKop;
  begin
    clrscr;
    kopa1 :=z1;
    kopa2 :=z2;
    kopa3 :=z3;
    textbackground(0);
    textcolor(15);
    write('                                                             ');
    textbackground(1);
    write('Zapalky');
    textbackground(4);
    writeln('(verzia1)');
    textcolor(7);
    textbackground(0);
    textcolor(7);
    write(' É');textcolor(white);write('ÍÍÍÍÍ');
    textcolor(7);write('Ë');textcolor(blue);write('ÍÍÍÍÍ');
    textcolor(7);write('Ë');textcolor(red);write('ÍÍÍÍÍ');
    textcolor(7);writeln('» ');
    writeln(' º ',kopa1:3,' º ',kopa2:3,' º ',kopa3:3,' º');
    writeln(' ºÄÄÄÄĺÄÄÄÄĺÄÄÄÄĺ ');
    gotoxy(1,y+1);
    TahPocitacaLahky(kopa1, kopa2, kopa3);
    repeat
   TahHraca1(kopa1, kopa2, kopa3);
   if (Kopa1=Kopa2) and (kopa2=kopa3) and (kopa3=0) then vyhra:= true;
   TahPocitacaLahky(kopa1, kopa2, kopa3);
   if (Kopa1=Kopa2) and (kopa2=kopa3) and (kopa3=0) then prehra:=true;
  y:=y+2;
  x:=x+2;
  u:=u+5;
  tah:= tah+1;
 
     until (Kopa1=Kopa2) and (kopa2=kopa3) and (kopa3=0);
   writeln(' º     º     º     º   ');
   writeln(' º ',kopa1:3,' º ',kopa2:3,' º ',kopa3:3,' º');
   writeln(' ÈÍÍÍÍÍÊÍÍÍÍÍÊÍÍÍÍͼ ':15);
       if vyhra then
       begin
    writeln ('                        ',meno,', to je tvoja vyhra!');
    if tah=1 then write('                          vyhral si na ',tah,' tah');
    if (tah>1) and (tah<5) then write('                          vyhral si na ',tah,' tahy');
    if (tah>4) then write('                          vyhral si na ',tah,' tahov');
    readln;
    readln;
    vyhralsi;
       end
    else
    begin
    writeln ('                          ',meno,', prehral si!');
    if tah=1 then write('                         pocitac vyhral na ',tah,' tah');
    if (tah>1) and (tah<5) then write('                         pocitac vyhral na ',tah,' tahy');
    if (tah>4) then write('                         pocitac vyhral na ',tah,' tahov');
    readln;
    end;
 
  end;
  readln;
  end;
 
    end;
 
 
 
 
  if (hra=2) then
 
begin
 
    clrscr;
    readln;
    gotoxy(26,7);
    textcolor(10);
    write(' Ako sa vola druhy hrac ? ');
    read(meno2);
 
    gotoxy(25,11);
    textcolor(10);write('vyber si kto zacina tuto hru: ');
    gotoxy(15,13);
    textcolor(9); write('1.');
    textcolor(15);write(' zacina ',meno,' ');
    gotoxy(15,15);
    textcolor(9); write('2.');
    textcolor(15);write(' zacina ',meno2,' ');
    read(zaciatok);
    repeat
    if (zaciatok<1) or (zaciatok>2) then
      begin
        gotoxy(15,17);
        textcolor(15);write('zadaj ');
        textcolor(9);write('1. ');
        textcolor(15);write('alebo ');
        textcolor(9);write('2. ');
        gotoxy(33,17);write('        ');
        gotoxy(33,17);read(zaciatok);
 
      end;
    until (zaciatok=1) or (zaciatok=2);
 
  if (zaciatok=1) then
  begin
  RozdelenieKop;
  begin
    clrscr;
    kopa1 :=z1;
    kopa2 :=z2;
    kopa3 :=z3;
    textbackground(0);
    textcolor(15);
    write('                                                             ');
    textbackground(1);
    write('Zapalky');
    textbackground(4);
    writeln('(verzia1)');
    textcolor(7);
    textbackground(0);
    textcolor(7);
    write(' É');textcolor(white);write('ÍÍÍÍÍ');
    textcolor(7);write('Ë');textcolor(blue);write('ÍÍÍÍÍ');
    textcolor(7);write('Ë');textcolor(red);write('ÍÍÍÍÍ');
    textcolor(7);writeln('» ');
    writeln(' º ',kopa1:3,' º ',kopa2:3,' º ',kopa3:3,' º' );
    writeln(' ºÄÄÄÄĺÄÄÄÄĺÄÄÄÄĺ ');
    gotoxy(1,y+1);
    repeat
      TahHraca1(kopa1, kopa2, kopa3);
      if (Kopa1=0) and (kopa2=0) and (kopa3=0) then
      begin
        vyhra:= true;
      end
      else
      begin
        TahHraca(kopa1, kopa2, kopa3);
      end;
   if (Kopa1=Kopa2) and (kopa2=kopa3) and (kopa3=0) then prehra:=true;
  y:=y+2;
  x:=x+2;
  u:=u+5;
  tah:= tah+1;
 
until (Kopa1=0) and (kopa2=0) and (kopa3=0) or vyhra;
   writeln(' º     º     º     º   ');
   writeln(' º ',kopa1:3,' º ',kopa2:3,' º ',kopa3:3,' º');
   writeln(' ÈÍÍÍÍÍÊÍÍÍÍÍÊÍÍÍÍͼ ':15);
       if vyhra then
       begin
    writeln ('                        ',meno,', to je tvoja vyhra!');
    if tah=1 then write('                          vyhral si na ',tah,' tah');
    if (tah>1) and (tah<5) then write('                          vyhral si na ',tah,' tahy');
    if (tah>4) then write('                          vyhral si na ',tah,' tahov');
    readln;
       end
    else
    begin
    writeln ('                          ',meno2,', to je tvoja vyhra!');
    if tah=1 then write('                          vyhral si na ',tah,' tah');
    if (tah>1) and (tah<5) then write('                          vyhral si na ',tah,' tahy');
    if (tah>4) then write('                          vyhral si na ',tah,' tahov');
    readln;
    end;
 
  end;
  readln;
  end
  else
 
 
  begin
  RozdelenieKop;
  begin
    clrscr;
    kopa1 :=z1;
    kopa2 :=z2;
    kopa3 :=z3;
    textbackground(0);
    textcolor(15);
    write('                                                             ');
    textbackground(1);
    write('Zapalky');
    textbackground(4);
    writeln('(verzia1)');
    textcolor(7);
    textbackground(0);
    textcolor(7);
    write(' É');textcolor(white);write('ÍÍÍÍÍ');
    textcolor(7);write('Ë');textcolor(blue);write('ÍÍÍÍÍ');
    textcolor(7);write('Ë');textcolor(red);write('ÍÍÍÍÍ');
    textcolor(7);writeln('» ');
    writeln(' º ',kopa1:3,' º ',kopa2:3,' º ',kopa3:3,' º');
    writeln(' ºÄÄÄÄĺÄÄÄÄĺÄÄÄÄĺ ');
    gotoxy(1,y+1);
    TahHraca(kopa1, kopa2, kopa3);
    repeat
      TahHraca1(kopa1, kopa2, kopa3);
      if (Kopa1=0) and (kopa2=0) and (kopa3=0) then
      begin
        vyhra:= true;
      end
      else
      begin
        TahHraca(kopa1, kopa2, kopa3);
      end;
   if (Kopa1=Kopa2) and (kopa2=kopa3) and (kopa3=0) then prehra:=true;
  y:=y+2;
  x:=x+2;
  u:=u+5;
  tah:= tah+1;
 
     until (Kopa1=Kopa2) and (kopa2=kopa3) and (kopa3=0);
   writeln(' º     º     º     º   ');
   writeln(' º ',kopa1:3,' º ',kopa2:3,' º ',kopa3:3,' º');
   writeln(' ÈÍÍÍÍÍÊÍÍÍÍÍÊÍÍÍÍͼ ':15);
       if vyhra then
       begin
    writeln ('                        ',meno,', to je tvoja vyhra!');
    if tah=1 then write('                          vyhral si na ',tah,' tah');
    if (tah>1) and (tah<5) then write('                          vyhral si na ',tah,' tahy');
    if (tah>4) then write('                          vyhral si na ',tah,' tahov');
    readln;
       end
    else
    begin
    writeln ('                          ',meno2,', to je tvoja vyhra!');
    if tah=1 then write('                          vyhral si na ',tah,' tah');
    if (tah>1) and (tah<5) then write('                          vyhral si na ',tah,' tahy');
    if (tah>4) then write('                          vyhral si na ',tah,' tahov');
    readln;
    end;
 
  end;
  readln;
  end;
  end;
  end;
end.