home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / mathmatt.zip / MATHMATT.PAS < prev   
Pascal/Delphi Source File  |  1988-03-24  |  9KB  |  494 lines

  1. {$I+,K+,R+}
  2. program mattmath(input,output);
  3.  
  4. var
  5.  
  6. score,num1,num2,answer,WrongCount:byte;
  7. DoSound:boolean;
  8. WrongNum1:array[1..10] of byte;
  9. WrongNum2:array[1..10] of byte;
  10. WrongOp:array[1..10] of byte;
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19. procedure Setup;
  20.  
  21. var UseSound:char;
  22. begin
  23.      GraphColorMode;
  24.      gotoXY(4,15);
  25.      write ('Do you want to include sound? (Y/N)');
  26.      read (UseSound);
  27.      if UseSound='y' then
  28.         UseSound:='Y';
  29.      if UseSound='Y' then
  30.      begin
  31.         DoSound:=TRUE;
  32.       end
  33.      else
  34.      begin
  35.          DoSound:=FALSE;
  36.      end;
  37.      ClrScr;
  38. end;
  39.  
  40.  
  41. procedure hesitation;
  42. var x:integer;
  43. begin
  44.      for x:=1 to 2500 do
  45.          begin
  46.          end;
  47. end;
  48.  
  49. procedure BigWait;
  50. var x:integer;
  51. begin
  52.      for x:=1 to 30000 do
  53.          begin
  54.          end;
  55.  
  56. end;
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. procedure stars;
  64.  
  65. var
  66.  
  67. Reps,row:integer;
  68. col,color:byte;
  69.  
  70. begin
  71.      for Reps:=1 to 1000 do
  72.          begin
  73.               Row:=random(320);
  74.               Col:=random(200);
  75.               Color:=random(5);
  76.               Plot(Row,Col,Color);
  77.           end;
  78. end;
  79.  
  80.  
  81.  
  82.  
  83. procedure title;
  84.   var
  85.  Col,Color:byte;
  86.  row,Blip,Reps,x:integer; {repetitions & screen coordinates}
  87.  
  88. begin
  89. x:=0;
  90. repeat                             {begin procedure}
  91. for Reps:=1 to 2000 do
  92.   begin                           {begin for loop}
  93.       Row:=random(320);
  94.       Col:=random(200);
  95.       Color:=random(5);
  96.       Plot(Row,Col,Color);
  97.       case Reps of
  98.           100:begin
  99.                   GotoXY(18,15);
  100.                   write('MATT');
  101.                   if DoSound then
  102.                      begin
  103.                           sound(440);
  104.                           delay(20);
  105.                       end;
  106.              end;
  107.           250:begin
  108.                  GotoXY(18,15);
  109.                  write('MATH');
  110.                  if DoSound then
  111.                  begin
  112.                       sound(660);
  113.                       delay(20);
  114.                  end;
  115.             end;
  116.           500:begin
  117.                  GotoXY(18,15);
  118.                  write('MATT');
  119.                  if DoSound then
  120.                  begin
  121.                       sound(260);
  122.                       delay(20);
  123.                  end;
  124.                  end;
  125.  
  126.           750:begin
  127.                  GotoXY(18,15);
  128.                  write('MATH');
  129.                  if DoSound then
  130.                  begin
  131.                       sound(1000);
  132.                       delay(20);
  133.                   end;
  134.                  end;
  135.           1000:begin
  136.                  GotoXY(18,15);
  137.                  write('MATT');
  138.                  if DoSound then
  139.                  begin
  140.                       sound(880);
  141.                       delay(20);
  142.                    end;
  143.                  end;
  144.           1250:begin
  145.                  GotoXY(18,15);
  146.                  write('MATH');
  147.                  if DoSound then
  148.                  begin
  149.                       sound(360);
  150.                       delay(20);
  151.                    end;
  152.                  end;
  153.           1500:begin
  154.                  GotoXY(18,15);
  155.                  write('MATT');
  156.                  if DoSound then
  157.                  begin
  158.                       sound(500);
  159.                       delay(20);
  160.                   end;
  161.                  end;
  162.           1750:begin
  163.                   GotoXY(18,15);
  164.                   write('MATT');
  165.                   if DoSound then
  166.                   begin
  167.                        sound(750);
  168.                        delay(20);
  169.                     end;
  170.                   end;
  171.                   end;
  172.          NoSound;
  173.    end;
  174.  
  175.                   GotoXY(15,15);
  176.                   write('         ');
  177.  
  178.   x:=x+1;
  179.   until x=2;
  180.   end;                            {end procedure}
  181.  
  182.  
  183. procedure GoodNoise;
  184. var pitch:integer;
  185. begin
  186. if DoSound then
  187. begin
  188.      for pitch:=440 to 1100 do
  189.      begin
  190.      sound(pitch);
  191.      delay(1);
  192.      end;
  193. NoSound;
  194. end;
  195. end;
  196.  
  197. procedure BadNoise;
  198. var pitch:integer;
  199. begin
  200. if DoSound then
  201. begin
  202.      for pitch:=440 downto 1 do
  203.      begin
  204.       sound(pitch);
  205.       delay(1);
  206.      end;
  207. NoSound;
  208. end;
  209. end;
  210.  
  211.  
  212.  
  213. procedure conclusion;
  214.  
  215. var pitch,counter,fore,x:integer;
  216. sign:char;
  217.  
  218. begin
  219.      gotoxy(15,15);
  220.      if score < 5 then
  221.         writeln('Keep Trying!!');
  222.      if score >5 then
  223.         writeln('Good Job!');
  224.      if score >=8 then
  225.         writeln('        In fact, EXCELLENT JOB!!');
  226.      if score =10 then
  227.      begin     {begin perfect score routine}
  228.      BigWait;
  229.      for fore:=1 to 15 do
  230.      begin
  231.          GotoXY(12,fore);
  232.          TextColor(fore);
  233.  
  234.         write('PERFECTAMUNDO!!!');
  235.         if DoSound then
  236.         begin
  237.            for pitch:=440 to 1000 do
  238.                begin
  239.                     sound(pitch);
  240.                     delay(1);
  241.                end;
  242.             for pitch:=1000 downto 440 do
  243.                 begin
  244.                      sound(pitch);
  245.                      delay(1);
  246.                 end;
  247.              end;
  248.           end; {end perfect score routine}
  249.           NoSound;
  250.       end;
  251.  
  252.       if WrongCount>0 then
  253.       begin
  254.            for x:=1 to 8 do
  255.                BigWait;
  256.  
  257.            GotoXY(2,5);
  258.            writeln('   These are the ones to practice:');
  259.            writeln;
  260.            for x:=1 to WrongCount do
  261.                begin
  262.                     if WrongOp[x]=1 then   {establish sign for wrong listing}
  263.                                     begin
  264.                                          sign:='+';
  265.                                          end
  266.                                          else
  267.                                          begin
  268.                                          sign:='-'
  269.                                       end;
  270.  
  271.  
  272.           writeln('                 ',WrongNum1[x],Sign,WrongNum2[x]);
  273.           writeln;
  274.       end;
  275. end;
  276. end;
  277.  
  278. procedure Storeit(var Op:byte);
  279.  
  280. begin
  281.      WrongCount:=WrongCount+1;
  282.      WrongNum1[WrongCount]:=Num1;
  283.      WrongNum2[WrongCount]:=Num2;
  284.      WrongOp[WrongCount]:=Op;
  285. end;
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298. procedure Fixit (var Op:byte);
  299. var x:byte;
  300.  
  301. begin
  302.      if Op=1 then
  303.      begin
  304.      GotoXY(10,11);
  305.         write('If you add ',Num1,' and ',Num2);
  306.       GotoXY(10,12);
  307.         writeln('Then the answer is ',Num1+Num2);
  308.         for x:=1 to 35 do
  309.             BigWait;
  310.      end
  311.      else
  312.      begin
  313.      GotoXY(5,12);
  314.        writeln('Actually, ',Num1,' take away ',Num2,' is ',Num1-Num2, '! ');
  315.        for x:=1 to 35 do
  316.        BigWait;
  317.      end;
  318.      Storeit(Op);
  319. end;
  320.  
  321.  
  322.  
  323.  
  324. procedure question;
  325.  
  326. const
  327.      MaxRow=23;
  328.      MidRow=15;
  329.      MidCol=20;
  330.  
  331. var
  332.  Row,Counter,Op,x:byte;
  333.  strlen:string[3];
  334.  
  335.  
  336. begin
  337. score:=0;
  338. for counter:=1 to 10 do
  339. begin
  340.  
  341. GotoXY(1,2);
  342. writeln('Question Number:',Counter);
  343.  
  344. writeln('Score:',Score);
  345.  
  346.  Num1:=random(16);
  347.  while (Num1=0) or (Num1<7) do
  348.        Num1:=random(16);
  349.  
  350.  Num2:=random(Num1);
  351.  while Num2=0 do
  352.        Num2:=random(Num1);
  353.  
  354.  
  355.  Op:=random(3);
  356.  
  357.  if Op=0 then
  358.     Op:=1;
  359.  
  360.  if Op=1 then
  361.  begin
  362.     GotoXY(17,25);
  363.     write('ADDITION');
  364.     end
  365.    else
  366.      begin
  367.      GotoXY(15,25);
  368.      write('SUBTRACTION');
  369.      end;
  370.  
  371.  
  372.  
  373.  for Row:=1 to MidRow do            {get first number}
  374.      begin
  375.           GotoXY(MidCol,Row);
  376.           write(Num1:2);
  377.           if Row <> MidRow then
  378.              hesitation;
  379.              GotoXY(MidCol,Row-1);
  380.                   write('  ');
  381.              end;
  382.  for Row:=MaxRow downto MidRow+1 do {get second number}
  383.      begin
  384.           GotoXY(MidCol,Row);
  385.           Write(Num2:2);
  386.           if Row<>MidRow-1 then
  387.              hesitation;
  388.              GotoXY(MidCol,Row+1);
  389.              write('  ');
  390.              end;
  391.  
  392.    GotoXY(MidCol,Row+1);
  393.    write('__');
  394.  
  395. if ( (Op=1) and (Num1+Num2<10)) or ((Op=2) and (Num1-Num2<10)) then
  396.      begin
  397.          GotoXY(MidCol+1,Row+2);
  398.          readln(answer);
  399.        end
  400.  
  401.    else
  402.        begin
  403.           GotoXY(MidCol,Row+2);
  404.           readln(answer);
  405.         end;
  406.  
  407. str(answer,strlen);
  408. if length(strlen)>1 then
  409.    begin
  410.    GotoXY(MidCol,Row+2);
  411.    write(answer,' ');
  412.    end;
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421. if Op=1 then  {right answer test -- addition}
  422.    begin
  423.         if answer=Num1+Num2 then
  424.         begin
  425.              Score:=Score+1;
  426.              GotoXY(17,22);
  427.              write('RIGHT!!!');
  428.              GoodNoise;
  429.              for x:=1 to 5 do
  430.              BigWait;
  431.         end
  432.         else
  433.         begin
  434.             GotoXY(19,22);
  435.             write('SORRY!');
  436.             BadNoise;
  437.             for x:=1 to 5 do
  438.             BigWait;
  439.             Fixit(Op);
  440.         end;
  441.     end;
  442.  
  443.  if Op=2 then {Right answer test --Subtraction}
  444.  begin
  445.       if (answer=Num1-Num2) then
  446.       begin
  447.            Score:=Score+1;
  448.            GotoXY(15,22);
  449.            write('TERRIFIC!!');
  450.            GoodNoise;
  451.            for x:=1 to 5 do
  452.            BigWait;
  453.       end
  454.       else
  455.       begin
  456.           GotoXY(10,25);
  457.           write('NOPE! TRY THE NEXT ONE!');
  458.           BadNoise;
  459.           for x:=1 to 5 do
  460.           BigWait;
  461.           Fixit(Op);
  462.       end;
  463.  end;
  464.  
  465.  GraphColorMode;
  466.  Stars;
  467.  end; {end of counter loop}
  468.  
  469.  
  470. end;  {end of question/answer loop}
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487. begin
  488.      Setup;
  489.      GraphColorMode;
  490.      Title;
  491.      WrongCount:=0;
  492.      Question;
  493.      Conclusion;
  494. end.