Помощь - Поиск - Пользователи - Календарь
Полная версия: Кнопки
Форум «Всё о Паскале» > Pascal, Object Pascal > Задачи
Burya_K
Помогите более рационально реализовать эффект нажатия кнопок, который описан в процедурах Perehod**. Цифры в названии процедуры обозначают то, с какой кнопки мы переходим на другую(1-Continue, 2-Help, 3-Exit). Движемся с помощью клавиш влево и вправо.


А вот и сам листинг


Код
Program Kyrs_proba;
  uses crt,graph,bmp;
  const LEFT=#075;
        RIGHT=#077;
  var f:text;
      flag:boolean;
      st,l:string;
      k:char;
      i:byte;
      x,y:integer;
      grMode, grDriver: integer;
      fl:boolean;
  Procedure Face;{********Ќ з «м­ п Є авЁ­Є *Bar3d(115,15,480,80,10,true);********}
    Begin
      SetBkColor(11);
      SetFillStyle(1,1);
      Bar(115,15,480,80);

{  ---ђ ¬Є  ¤«п "ЋЎгз ой п Їа®Ја ¬¬ "---}
      SetColor(1);
      Line(115,15,480,15);
      Line(480,15,480,80);
      Line(480,80,115,80);
      Line(115,80,115,15);
      Line(115,15,120,10);
      Line(120,10,485,10);
      Line(485,10,480,15);
      Line(485,10,485,75);
      Line(485,75,480,80);

      SetColor(15);
      SetTextStyle(7,0,5);
      OutTextXY(120,20,'Training course');

{  ---‚лў®¤ Theoretical principles of ORGANIC CHEMISTRY---}
      SetColor(4);
      settextstyle(1,0,6);
      OutTextXY(50,125,'Theoretical principles');
      OutTextXY(280,180,'of');
      OutTextXY(60,235,'ORGANIC CHEMISTRY');

{  ---ђЁб®ў ­ЁҐ 3-е Є­®Ї®Є ў­Ё§г---}
      SetColor(8);
      SetTextStyle(4,0,5);
      SetFillStyle(1,12);

{1}   Bar(25,340,180,385);
      Line(25,340,180,340);
      Line(180,340,180,385);
      Line(180,385,25,385);
      Line(25,385,25,340);
      OutTextXY(30,330,'Continue');

{2}   SetFillStyle(1,13);
      Bar3d(242,340,396,385,5,true);
      OutTextXY(280,330,'Help');
{3}   Bar3d(463,340,617,385,5,true);
      OutTextXY(505,330,'Exit');

      Setcolor(1);
      SetTextStyle(2,0,5);
      OutTextXY(445,460,'written by Nikolay Buryak');

{  ---ЊҐаж ­ЁҐ а ¬ЄЁ---           }
      fl:=true;

      While not keypressed do
        Begin
          If fl then Begin
                       SetColor(11);
                       SetLineStyle(3,0,3);
                       Line(0,0,640,0);
                       Line(639,0,639,480);
                       Line(640,479,0,479);
                       Line(0,480,0,0);
                       fl:=false;
                       delay(30000);
                    End
                else Begin
                       SetColor(4);
                       SetLineStyle(3,0,3);
                       Line(0,0,640,0);
                       Line(639,0,639,480);
                       Line(640,479,0,479);
                       Line(0,480,0,0);
                       fl:=true;
                       delay(30000);
                     End
        End;
      readkey;
    End;

    Procedure Perehod12;
      Begin
        SetFillStyle(1,13);
        Bar3d(25,340,180,385,5,true);
        OutTextXY(30,330,'Continue');

        SetFillStyle(1,11);
        Bar(241,334,402,385);

        SetFillStyle(1,12);
        Bar(242,340,396,385);
        Line(242,340,396,340);
        Line(396,340,396,385);
        Line(396,385,242,385);
        Line(242,385,242,340);
        OutTextXY(280,330,'Help');
        i:=2
      End;

    Procedure Perehod23;
      Begin
        SetFillStyle(1,13);
        Bar3d(242,340,396,385,5,true);
        OutTextXY(280,330,'Help');

        SetFillStyle(1,11);
        Bar(460,335,625,390);

        SetFillStyle(1,12);
        Bar(463,340,617,385);
        Line(463,340,617,340);
        Line(617,340,617,385);
        Line(617,385,463,385);
        Line(463,385,463,340);
        OutTextXY(505,330,'Exit');
        i:=3;
      End;

    Procedure Perehod31;
      Begin
        SetFillStyle(1,13);
        Bar3d(463,340,617,385,5,true);
        OutTextXY(505,330,'Exit');

        SetFillStyle(1,11);
        Bar(24,335,185,385);

        SetFillStyle(1,12);
        Bar(25,340,180,385);
        Line(25,340,180,340);
        Line(180,340,180,385);
        Line(180,385,25,385);
        Line(25,385,25,340);
        OutTextXY(30,330,'Continue');
        i:=1;
      End;

    Procedure Perehod13;
      Begin
        SetFillStyle(1,13);
        Bar3d(25,340,180,385,5,true);
        OutTextXY(30,330,'Continue');

        SetFillStyle(1,11);
        Bar(460,335,625,390);

        SetFillStyle(1,12);
        Bar(463,340,617,385);
        Line(463,340,617,340);
        Line(617,340,617,385);
        Line(617,385,463,385);
        Line(463,385,463,340);
        OutTextXY(505,330,'Exit');
        i:=3
      End;

    Procedure Perehod32;
      Begin
        SetFillStyle(1,13);
        Bar3d(463,340,617,385,5,true);
        OutTextXY(505,330,'Exit');

        SetFillStyle(1,11);
        Bar(241,334,402,385);

        SetFillStyle(1,12);
        Bar(242,340,396,385);
        Line(242,340,396,340);
        Line(396,340,396,385);
        Line(396,385,242,385);
        Line(242,385,242,340);
        OutTextXY(280,330,'Help');
        i:=2
      End;

    Procedure Perehod21;
      Begin
        SetFillStyle(1,13);
        Bar3d(242,340,396,385,5,true);
        OutTextXY(280,330,'Help');

        SetFillStyle(1,11);
        Bar(24,335,185,385);

        SetFillStyle(1,12);
        Bar(25,340,180,385);
        Line(25,340,180,340);
        Line(180,340,180,385);
        Line(180,385,25,385);
        Line(25,385,25,340);
        OutTextXY(30,330,'Continue');
        i:=1
      End;

    Begin {main}
      clrscr;
      grDriver:=Detect;
      initGraph (grDriver,grMode,'C:\bp\bgi');
{      Assign(f,'text.txt');
      reset(f);
      SBMI('1.bmp',0,0,0);
      l:=readkey;
      cleardevice;}
      Face;
{*******ЏҐаҐ¤ўЁ¦Ґ­ЁҐ Є« ўЁи ¬Ё-Єгаб®а ¬Ё Є­®Ї®Є ­  аЁбг­ЄҐ*************}

      SetLineStyle(0,0,0);
      SetColor(8);
      SetTextStyle(4,0,5);
      i:=1;

      While i<>4 do
        Begin
          k:=readkey;
          Case k of
            Right: Case i of
                     1:  Perehod12;
                     2:  Perehod23;
                     3:  Perehod31
                   End;
            Left:  Case i of
                     1: Perehod13;
                     2: Perehod21;
                     3: Perehod32;
                   End;
          End;
          If k=#13 then Case i of
                          1:Continue;
                          2:Continue;
                          3:Break
                        End;


        End;

{----------------END----------------------------}

    {  x:=0;
      y:=0;
      While not Eof(f) do
        Begin
          read(f,st);
          case ord(st) of
            128..239:st:=chr(ord(st)-64);
            240..255:st:=chr(ord(st)-16);
          end;
          Case st of
            '*':Begin
                  readkey;
                  cleardevice;
                  x:=0;
                  y:=0
                End;
            '/':readkey;
            else Outtextxy(x,y,st);
          End;
          x:=x+8;
          If x>635 then Begin
                          y:=y+10;
                          x:=0
                        End;

      End;
      close(F);}
    End.



{Звиняйте за неструктурность, это только здесь так получилось... }
volvo
Цитата
более рационально реализовать эффект нажатия кнопок
Гораздо более рационально будет выделить рисование кнопки в отдельную процедуру, как я сделал в аттаче. Посмотри, насколько уменьшилась программа...

(небольшая накладка с кнопкой Continue - из за того, что ты сделал ее размер в самом начале, при отрисовке, на 1 пиксель меньше чем у 2-х других кнопок. Я не стал исправлять это в процедуре Face, поправь сам...)
Burya_K
Большое спасибо за помощь! good.gif
Это текстовая версия — только основной контент. Для просмотра полной версии этой страницы, пожалуйста, нажмите сюда.