Forum > Arabic

شاركـ ببرنامج

<< < (2/5) > >>

pascal111:
برنامج ظريف كنموذج للبرمجة المرئيّة لبرمجة برامج من نوع الـ command line الإعتياديّة بما يُقابلها في البرمجة المرئيّة.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project1; {$mode objfpc}{$H+} uses  interfaces,  {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Classes, Dialogs, sysutils, forms, LCLType  { you can add units after this }; var   s:string;  i:integer; label  again; begin again:   s:=inputbox('Where...','Where you would like to put the cup?'+lineending+  '1) On the table              2) On the air'+lineending+lineending+  'Type ''1'' or ''2'':','');   case s of   '':    begin    showmessage('You canceled the game!');    exit;    end;   '1': showmessage('The table bears the cup, it''s on the table.');   '2': showmessage('The cup fell because the gravity and broken on the ground.');   else    begin    showmessage('You entered invalid value!');    goto again;    end;  end;   i:=application.messagebox('Do you like playing again?', 'Again?',MB_YESNO+  MB_ICONQUESTION);   if i=idyes then goto again; end.  

Handoko:
Thank you for sharing the simple text game.

Because Pascal encourages good programming practices using structured programming (https://en.wikipedia.org/wiki/Pascal_%28programming_language%29), I rewrote your code using more structural way:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project1; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Classes, Dialogs, sysutils, Forms, LCLType, Interfaces  { you can add units after this }; procedure Play;const  LE = LineEnding;var  S: string;begin  repeat     S := InputBox    ('Where...',     'Where you would like to put the cup?'       + LE +     '1) On the table              2) On the air' + LE + LE +     'Type ''1'' or ''2'':','');     case S of    '':   begin          ShowMessage('You canceled the game!');          Halt;          end;    '1':  begin          ShowMessage('The table bears the cup, it''s on the table.');          Exit;          end;    '2':  begin          ShowMessage('The cup fell because the gravity and broken on the ground.');          Exit;          end    else      ShowMessage('You entered invalid value!');    end;   until False;end; var  i: Integer; begin  repeat    Play;    i := Application.MessageBox      ('Do you like playing again?', 'Again?', MB_YESNO + MB_ICONQUESTION);  until i <> IDYES;end.
Usually, it is good to avoid using label. Because using label often makes the code harder to debug. Most programmers against using it. Others allow using it but only for some extremely rare cases.

-edit-
It would be more correct to say:
Usually, it is good to avoid using GOTO. Because using GOTO often makes the code harder to debug. Most Pascal programmer against using it. Others allow using it but only for some extremely rare cases.

pascal111:

--- Quote from: Handoko on September 05, 2021, 04:52:13 pm ---Thank you for sharing the simple text game.

Because Pascal encourages good programming practices using structured programming (https://en.wikipedia.org/wiki/Pascal_%28programming_language%29), I rewrote your code using more structural way:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project1; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Classes, Dialogs, sysutils, Forms, LCLType, Interfaces  { you can add units after this }; procedure Play;const  LE = LineEnding;var  S: string;begin  repeat     S := InputBox    ('Where...',     'Where you would like to put the cup?'       + LE +     '1) On the table              2) On the air' + LE + LE +     'Type ''1'' or ''2'':','');     case S of    '':   begin          ShowMessage('You canceled the game!');          Halt;          end;    '1':  begin          ShowMessage('The table bears the cup, it''s on the table.');          Exit;          end;    '2':  begin          ShowMessage('The cup fell because the gravity and broken on the ground.');          Exit;          end    else      ShowMessage('You entered invalid value!');    end;   until False;end; var  i: Integer; begin  repeat    Play;    i := Application.MessageBox      ('Do you like playing again?', 'Again?', MB_YESNO + MB_ICONQUESTION);  until i <> IDYES;end.
Usually, it is good to avoid using label. Because using label often makes the code harder to debug. Most programmers against using it. Others allow using it but only for some extremely rare cases.

--- End quote ---

تعديلاتكـ رائعة! لقد جعلت البرنامج فعلاً أكثر تطبيقاً لمفهوم البرمجة البنيويّة ،سأضع هذه التعديلات في الإعتبار. من الجدير بالذكر كما ذكرت عن الـ labels أنّ الباسكال منذ البدء وهي تتجه إلى البرمجة التي تمتاز بالـ goto-less أي الإستخدام الأقل لعبارة goto.

pascal111:
هذا برنامج يسأل عن بعض المعلومات الشخصيّة ويُعلّق ببعض التعليقات الظريفة وفي النّهاية يعرض نموذجاً كصندوق حوار متقدّم لعرض ما سلف تدوينه من معلومات شخصيّة.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project1; {$mode objfpc}{$H+} uses   {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Classes, Dialogs, sysutils, forms, LCLType, interfaces, Unit1  { you can add units after this }; type   personal_card=record    p_name:string[20];    p_age:1..200;    p_nationality:string[25];  end; var   p:personal_card;  s:string[20];  i:real;  err:integer; begin   repeat  s:=inputbox('Name...', 'What''s your name (max 20 letters):','');  if s='' then showmessage('You should enter a name!');  until s<>'';   p.p_name:=s;   showmessage('Hi! '+p.p_name);   repeat  s:=inputbox('Age...', 'What''s your age (5 <= integer <= 200):','');  if s='' then showmessage('You should enter an age!');   val(s,i,err);  if (err<>0) or (i<>trunc(i)) or (i<5) or (i>200) then  begin  showmessage('Invalid age value!');  continue;  end  else  break;   until false;   p.p_age:=trunc(i);   case p.p_age of   5..25: showmessage('You''re still young!');   26..50: showmessage('You''re in the middle of the time''s sea!');   51..200: showmessage('You lived happy golden eras!');   end;   repeat  s:=inputbox('From...', 'Where are you from (max 25 letters):','');  if s='' then showmessage('You should enter a name!');  until s<>'';   p.p_nationality:=s;   showmessage(p.p_nationality+' is a nice place!');   form1:=tform1.Create(nil);   with form1 do  begin    with p do    begin       Edit1.text:=p_name;      edit2.Text:=inttostr(p_age);      edit3.Text:=p_nationality;     end;   end;   form1.showmodal;   FreeAndNil(form1); end.  

pascal111:
برنامج غير كامل لاستخدام قيم مُعرّفة بنوع القوائم.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project1; {$mode objfpc}{$H+} uses   {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Classes, Dialogs, sysutils, forms, LCLType, interfaces  { you can add units after this }; type   deepness = ( depthless = 1, deep, very_deep); var   s, q:string; begin   repeat    s:=inputbox('Pass', 'Choose (1 to 3 or e for exit):'+lineending+lineending+  '1) Eyes  2) Glass  3) Space','');   case s of    '1':      begin      str(deepness(2),q);      showmessage(q);      end;    '2':      begin      str(deepness(1),q);      showmessage(q);      end;    '3':      begin      str(deepness(3),q);      showmessage(q);      end;  end;      until s='e';end.  

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version