{************************************}
{* Demonstratia functionarii presei *}
{* hidraulice si  cateva informatii *}
{*   despre aceasta, adica teorie.  *}
{*   Fisiere: presa.pas;presa.txt;  *}
{*      Data 12 noembrie 1997       *}
{************************************}
program piston;
uses crt,graph;
label 1;
const
  paus=5000;
  m=50;
var
   fis:text;
   xx,w,i,j,k,h,e:longint;
   p2,ret1,ret2,x1,x2,y1,y2:integer;
   gd,gm,q:integer;
   g,p,l,ch:char;
procedure init;
begin
  gd:=detect;gm:=0;
  initgraph(gd,gm,'c:\limbaje\tp\bgi');
  if graphresult<>grOk then halt(1);
end;
function readtext(nrlinie:byte):string;
  var s:string;
    j:byte;
    begin
       readtext:='';
       reset(fis);
       for j:=1 to nrlinie do
          readln(fis,s);
       close(fis);
       readtext:=s;
    end;
procedure txt;
begin
  assign(fis,'presa.txt');
  settextjustify(0, 1);
     for i:=1 to 50 do
         begin
           setcolor(3);
           outtextxy(2,8+19*i,readtext(i));
         end;
end;
procedure despre;
begin
  cleardevice;
    setfillstyle(1,red);bar(160,100,450,400);
    setfillstyle(1,darkgray);bar(450,120,465,410);bar(180,401,465,416);
    setcolor(white);
    rectangle(162,102,448,398);rectangle(164,104,446,396);
    setcolor(yellow);settextstyle(defaultfont,0,1);
    outtextxy(170,125,'Author     MICLIUC TIMOTEI (Tim)');
    outtextxy(170,170,'Job        student at Grup Scolar');
    outtextxy(170,185,'           Octavian Goga Marghita');
    outtextxy(170,220,'Address    TimSoft Corporation');
    outtextxy(170,235,'           C.Republicii Street,');
    outtextxy(170,250,'           bl.82/A5 ap.7 3775');
    outtextxy(170,265,'           Marghita Bihor Romania');
    outtextxy(170,305,'Phone      369 284');
    outtextxy(170,330,'E-mail     micliuc@tim.soft');
    outtextxy(170,345,'WWW        http//mtt/timsoft.com');
    outtextxy(250,380,'Press X to end');
  repeat
    p:=readkey;
  until p='x';
end;
procedure aplic;
begin
 setcolor(15);setbkcolor(3);
 setviewport(0,0,getmaxx,getmaxy,FALSE);
 cleardevice;
 settextjustify(0,2);
 settextstyle(1,0,3);setlinestyle(0,0,2);
 setviewport(0,0,getmaxx,100,false);setfillstyle(1,1);bar(0,0,getmaxx,110);
 outtextxy(135,0,'Aplicatii ale Legii lui Pascal');settextstyle(1,0,4);setcolor(14);line(2,14,133,14);line(2,14,2,100);
 settextstyle(0,0,1);
 outtextxy(20,70,'Registered version 2.0 - November 1997');
 line(5,16,133,16);line(2,100,getmaxx-2,100);line(5,16,5,98);line(5,98,getmaxx-5,98);line(getmaxx-2,100,getmaxx-2,14);
 line(getmaxx-5,98,getmaxx-5,16);line(getmaxx-2,14,getmaxx-187,14);line(getmaxx-5,16,getmaxx-187,16);
 settextstyle(1,0,1);outtextxy(220,30,'Presa Hidraulica');settextstyle(1,0,1);
 settextstyle(1,0,1);
 bar(197,180,383,360);
 setfillstyle(1,darkgray);bar(384,195,394,360);bar(210,361,394,370);
 setfillstyle(1,1);
 rectangle(205,185,375,350);rectangle(208,187,372,348);
 bar(0,410,getmaxx,getmaxy);
 rectangle(2,410,getmaxx-2,getmaxy-2);
 rectangle(4,412,getmaxx-4,getmaxy-4);
 settextstyle(0,0,1);
 outtextxy(20,430,'Graphic program by TimSoft Corporation');
 outtextxy(20,450,'                                  Author: Micliuc Timotei (Tim)');
end;
procedure teorie;
begin
  cleardevice;
   setcolor(cyan);
   setbkcolor(0);
    settextstyle(1,0,4);
    settextjustify(0,2);
    outtext('           Presa Hidraulica');
    settextstyle(0,0,1);  TXT;
    setcolor(3);
    setlinestyle(0,1,1);
    rectangle(420,280-m,530,400-m);line(430,280-m,430,265-m);line(450,280-m,450,265-m);
    line(490,280-m,490,265-m);line(510,280-m,510,265-m);
    setcolor(0);line(430,280-m,450,280-m);line(490,280-m,510,280-m);
 h:=0;
setcolor(3);
setlinestyle(3,1,1);
 repeat
  line(420,280-m+h,530,280-m+h);
  line(425,280-m+h+10,526,280-m+h+10);
  h:=h+20;
 until h=120;setfillstyle(4,3);setlinestyle(0,1,3);setcolor(3);
    setcolor(6);
    for i:=1 to 16 do
     begin
      line(493,235-m+i,507,235-m+i);
      line(433,260-m+i,447,260-m+i);
      end;setcolor(3);
      line(499,165-m,499,215-m);line(494,210-m,499,215-m);line(505,210-m,499,215-m);
      p:=readkey;
    if p<>'q' then
      begin
        setcolor(0);
          line(499,165-m,499,215-m);line(494,210-m,499,215-m);line(505,210-m,499,215-m);
        setcolor(3);
          line(499,180-m,499,230-m);line(494,225-m,499,230-m);line(505,225-m,499,230-m);
        Sound(200);Delay(200);NoSound;
     i:=0;
   repeat
      setcolor(0);line(493,235-m+i,507,235-m+i);
       setcolor(0);line(433,276-m-i,447,276-m-i);
      for j:=1 to paus do begin end;
      sound(35);delay(10);nosound;
      setcolor(6);line(493,251-m+i,507,251-m+i);
      setcolor(6);line(433,260-m-i,447,260-m-i);
      i:=i+1;
   until i=25;
     i:=0;
    end;
readln;
end;
procedure desenare;
begin
 cleardevice;
 setcolor(15);setbkcolor(0);
 setviewport(0,0,getmaxx,getmaxy,false);
  rectangle(30,30,100,400);line(60,400,60,500);line(70,400,70,500);
  rectangle(100,390,300,400);rectangle(300,30,600,400);
  setcolor(0);line(30,30,100,30);line(60,400,70,400);
   line(100,390,100,399);line(300,390,300,399);line(300,30,600,30);
  setcolor(15);line(55,378,55,399);line(75,378,75,399);line(55,378,60,378);line(75,378,70,378);
   line(300,385,320,385);line(320,385,320,390);line(320,395,320,399);
  for i:=1 to 20 do
    begin
     line(30,350+i,100,350+i);
     line(300,360+i,600,360+i);
    end;
end;
procedure p1s;
begin
 settextstyle(0,0,1);setcolor(15);
 outtextxy(getmaxx div 3,getmaxy-20,'Press "Enter" to exit');
i:=0;
 for e:=1 to 20 do
  begin
   setcolor(0);line(60,398-(e div 2),70,398-(e div 2));line(308+(e div 2),390,308+(e div 2),399);
   setcolor(15);line(60,390-(e div 2),70,390-(e div 2));line(300+(e div 2),390,300+(e div 2),399);
  end;
  repeat
    if keypressed then k:=50;
    setcolor(0);line(31,370-i,99,370-i);
   for j:=1 to paus do begin end;
    setcolor(15);line(31,350-i,99,350-i);
    i:=i+1;
  until i=320;
end;
procedure p1j;
begin
  i:=0;
 for e:=1 to 20 do
  begin
    setcolor(15);line(60,398-(e div 2),70,398-(e div 2));line(308+(e div 2),390,308+(e div 2),399);
    setcolor(0);line(60,390-(e div 2),70,390-(e div 2));line(300+(e div 2),390,300+(e div 2),399);
  end;
  repeat
    if keypressed then k:=50;
    setcolor(0);line(31,30+i,99,30+i);
    for j:=1 to paus do begin end;
     setcolor(15);line(31,50+i,99,50+i);
     i:=i+1;
  until i=320;
  k:=k-1;
end;
begin
  init;
  x1:=240;x2:=350;y2:=230;y1:=200;
repeat
   aplic;
   setfillstyle(1,red);bar(x1,y1,x2,y2);
   setcolor(14);
   settextstyle(1,0,1);
   outtextxy(225,200,'  Experiment');
   outtextxy(225,230,'  Teorie');
   outtextxy(225,260,'  Despre...');
   outtextxy(225,290,'  Iesire');
 repeat
   case p of #80:begin
                                      setfillstyle(1,1);bar(x1,y1,x2,y2);
                                      setcolor(14);
                                      settextstyle(1,0,1);
                                      outtextxy(225,200,'  Experiment');
                                      outtextxy(225,230,'  Teorie');
                                      outtextxy(225,260,'  Despre...');
                                      outtextxy(225,290,'  Iesire');
                  if y2=320 then begin x1:=240;x2:=350;y1:=200;y2:=230;
                                       setfillstyle(1,red);bar(x1,y1,x2,y2);
                                       setcolor(14);
                                       settextstyle(1,0,1);
                                       outtextxy(225,200,'  Experiment');
                                       outtextxy(225,230,'  Teorie');
                                       outtextxy(225,260,'  Despre...');
                                       outtextxy(225,290,'  Iesire');
                                 end
                            else begin y1:=y1+30;y2:=y2+30;
                                       setfillstyle(1,red);bar(x1,y1,x2,y2);
                                       setcolor(14);
                                       settextstyle(1,0,1);
                                       outtextxy(225,200,'  Experiment');
                                       outtextxy(225,230,'  Teorie');
                                       outtextxy(225,260,'  Despre...');
                                       outtextxy(225,290,'  Iesire');
                                  end;
                 end;
               #72:begin
                                      setfillstyle(1,1);bar(x1,y1,x2,y2);
                                      setcolor(14);
                                      settextstyle(1,0,1);
                                      outtextxy(225,200,'  Experiment');
                                      outtextxy(225,230,'  Teorie');
                                      outtextxy(225,260,'  Despre...');
                                      outtextxy(225,290,'  Iesire');
                  if y1=200 then  begin x1:=240;x2:=350;y1:=290;y2:=320;
                                        setfillstyle(1,red);bar(x1,y1,x2,y2);
                                        setcolor(14);
                                        settextstyle(1,0,1);
                                        outtextxy(225,200,'  Experiment');
                                        outtextxy(225,230,'  Teorie');
                                        outtextxy(225,260,'  Despre...');
                                        outtextxy(225,290,'  Iesire');
                                  end
                            else begin y1:=y1-30;y2:=y2-30;
                                       setfillstyle(1,red);bar(x1,y1,x2,y2);
                                       setcolor(14);
                                       settextstyle(1,0,1);
                                       outtextxy(225,200,'  Experiment');
                                       outtextxy(225,230,'  Teorie');
                                       outtextxy(225,260,'  Despre...');
                                       outtextxy(225,290,'  Iesire');
                                  end;
                 end;
      end;
  p:=readkey;
  if p=#27 then exit;
 until p=#13;
     case y1 of
            200:begin
                  desenare;k:=380;p2:=380;
                  repeat p1s;p1j;
                    if p2<>0 then
                      begin
                        setcolor(0);
                        line(301,p2,599,p2);
                        line(301,p2-1,599,p2-1);
                        setcolor(15);
                        line(300,p2-20,600,p2-20);
                        line(300,p2-21,600,p2-21);
                        p2:=p2-2;
                      end;
                    if (keypressed) then k:=50;
                  until  (k=50); readln; y1:=200;
                end;
            230:begin teorie;y1:=230;end;
            260:begin despre;y1:=260;end;
            290:exit;
     end;
until l=#27;
 closegraph;
end.