Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Indovina il numero aggiornata... - zindovina.pas

zindovina.pas

Caricato da:
Scarica il programma completo

  1. program indovina;
  2. uses
  3.     crt;
  4. const
  5.      dim=10;
  6. type
  7.     f=record
  8.                 nome:array[1..dim] of string;
  9.                 p:array[1..dim] of integer;
  10.                 l:array[1..dim] of integer;
  11.                 t:array[1..dim]of integer;
  12.     end;
  13.     files=file of f;
  14. var
  15.     n,x,z,i,kkk:integer;
  16.     y,v,max,min:longint;
  17.     cl:files;
  18.     dat:f;
  19.     ww,ki:string[30];
  20. procedure menu(var n:integer);
  21. var
  22.     z:char;
  23.     x,i:integer;
  24. begin
  25.     i:=random(4)+5;
  26.     gotoxy(5,5);
  27.     write('[ ] Livello 1 [1-100]');
  28.     gotoxy(5,6);
  29.     write('[ ] Livello 2 [1-1000]');
  30.     gotoxy(5,7);
  31.     write('[ ] Livello 3 [1-10000]');
  32.     gotoxy(5,8);
  33.     write('[ ] Livello 4 [1-100000]');
  34.     gotoxy(6,i);
  35.     textcolor(2);
  36.     write('*');
  37.     z:=#27;
  38.     while(z<>#13)do
  39.     begin
  40.         repeat
  41.             z:=readkey;
  42.         until
  43.             (z=#80) or (z=#72) or (z=#13);
  44.         if(z=#80) and (wherey<>8)then
  45.         begin
  46.             textcolor(2);
  47.             gotoxy(6,i);
  48.             write(' ');
  49.             gotoxy(6,i+1);
  50.             write('*');
  51.             i:=i+1;
  52.         end
  53.         else
  54.             if(z=#72) and (wherey<>5)then
  55.             begin
  56.                 textcolor(2);
  57.                 gotoxy(6,i);
  58.                 write(' ');
  59.                 gotoxy(6,i-1);
  60.                 write('*');
  61.                 i:=i-1;
  62.         end
  63.     end;
  64.     x:=wherey;
  65.     n:=x-4;
  66.     textcolor(15);
  67. end;
  68. function livello(n:integer):longint;
  69. begin
  70.     case n of
  71.         1:livello:=random(100)+1;
  72.         2:livello:=random(1000)+1;
  73.         3:livello:=random(10000)+1;
  74.         4:livello:=random(100000)+1;
  75.     end;
  76. end;
  77. procedure control(y:longint; var x,n:integer; var a,max,min:longint);
  78. begin
  79.     writeln('Livello ',n,' Per uscire inserire 0 ');
  80.     writeln('Numero consigliato::',(max+min)div 2,'       max ',max,'   min ',min);
  81.     writeln('Inserire il numero');
  82.     repeat
  83.         readln(a);
  84.     until
  85.         (a>=0);
  86.     if (a<>y)and(a<>0) then
  87.     begin
  88.         if a<y then
  89.         begin
  90.             if(y-a<y-max) and (a>min)then
  91.                 max:=a
  92.             else
  93.                 min:=a;
  94.             writeln('Il numero inserito e'' maggiore');
  95.         end
  96.         else begin
  97.             if(a-y<max-y) and (a>min)then
  98.                 max:=a
  99.             else
  100.                 min:=a;
  101.             writeln('Il numero inserito e'' minore');
  102.         end;
  103.         x:=x+1;
  104.     end
  105.     else if(a<>0) then
  106.         writeln('Hai indovinato il numero in ',x,' tentativi');
  107.     if a<>0 then
  108.         delay(1000);
  109. end;
  110. function punteggio(n,x:integer):integer;
  111. begin
  112.     punteggio:=(n*10)-x;
  113. end;
  114. procedure menup(var n:integer);
  115. begin
  116.      writeln('1:Gioca');
  117.      writeln('2:Classifica');
  118.      writeln('3:Elimina Classifica');
  119.      writeln('0:Uscita');
  120.      repeat
  121.            writeln('Scelta:');
  122.            readln(n);
  123.      until
  124.           (n>=0) and (n<=3);
  125. end;
  126. procedure ordina(var s:string);
  127. begin
  128.      while(length(s)<30) do
  129.                          s:=s+' ';
  130. end;
  131. begin{main}
  132.     randomize;
  133.     kkk:=0;
  134.     assign(cl,'classifica.dat');
  135.     //rewrite(cl);
  136.     reset(cl);
  137.     ww:=' ';
  138.     textcolor(15);
  139.     repeat
  140.           clrscr;
  141.           menup(z);
  142.           case z of
  143.                1:begin
  144.                       writeln('Inserire il tuo nome');
  145.                       readln(ww);
  146.                       ordina(ww);
  147.                       clrscr;
  148.                       textcolor(15);
  149.                       menu(n);
  150.                       y:=livello(n);
  151.                       case n of
  152.                                    1:max:=100;
  153.                                    2:max:=1000;
  154.                                    3:max:=10000;
  155.                                    4:max:=100000;
  156.                       end;
  157.                       min:=0;
  158.                       x:=0;
  159.                       repeat
  160.                             clrscr;
  161.                             writeln('0:Arrendersi');
  162.                             control(y,x,n,v,max,min);
  163.                       until
  164.                              (v=y) or (v=0);
  165.                       clrscr;
  166.                       textcolor(4);
  167.                       if v<>0 then
  168.                          begin
  169.                             v:=punteggio(n,x);
  170.                                 writeln('Il tuo punteggio e'' ',v);
  171.                             if kkk=0 then
  172.                             begin
  173.                             seek(cl,0);
  174.                             read(cl,dat);
  175.                             kkk:=1;
  176.                             end;
  177.                             repeat
  178.                                   z:=0;
  179.                                   for i:=1 to dim-1 do
  180.                                   begin
  181.                                        if dat.p[i]<dat.p[i+1] then
  182.                                        begin
  183.                                             z:=dat.p[i];
  184.                                             dat.p[i]:=dat.p[i+1];
  185.                                             dat.p[i+1]:=z;
  186.                                             ki:=dat.nome[i];
  187.                                             dat.nome[i]:=dat.nome[i+1];
  188.                                             dat.nome[i+1]:=ki;
  189.                                             z:=dat.l[i];
  190.                                             dat.l[i]:=dat.l[i+1];
  191.                                             dat.l[i+1]:=z;
  192.                                             z:=dat.t[i];
  193.                                             dat.t[i]:=dat.t[i+1];
  194.                                             dat.t[i+1]:=z;
  195.                                             z:=1;
  196.                                       end;
  197.                                   end;
  198.                             until
  199.                                  z=0;
  200.                             for z:=1 to dim do
  201.                                 if v>dat.p[z] then
  202.                                 begin
  203.                                      for i:=dim downto z+1 do
  204.                                      begin
  205.                                          dat.nome[i]:=dat.nome[i-1];
  206.                                          dat.p[i]:=dat.p[i-1];
  207.                                          dat.l[i]:=dat.l[i-1];
  208.                                          dat.t[i]:=dat.t[i-1];
  209.  
  210.                                      end;
  211.                                      dat.nome[z]:=ww;
  212.                                      dat.p[z]:=v;
  213.                                      dat.l[z]:=n;
  214.                                      dat.t[z]:=x;
  215.                                      break;
  216.                                 end;
  217.  
  218.                             rewrite(cl);
  219.                             write(cl,dat);
  220.                          end
  221.                       else
  222.                                writeln('Non hai indovinato il numero x=',y);
  223.                       textcolor(15);
  224.                       readln;
  225.                end;
  226.                2:begin
  227.                      clrscr;
  228.                      writeln('Classifica Top 10');
  229.                      writeln;
  230.                      writeln;
  231.                      if kkk=0 then
  232.                      begin
  233.                      seek(cl,0);
  234.                      read(cl,dat);
  235.                      kkk:=1;
  236.                      end;
  237.                             repeat
  238.                                   z:=0;
  239.                                   for i:=1 to dim-1 do
  240.                                   begin
  241.                                        if dat.p[i]<dat.p[i+1] then
  242.                                        begin
  243.                                             z:=dat.p[i];
  244.                                             dat.p[i]:=dat.p[i+1];
  245.                                             dat.p[i+1]:=z;
  246.                                             ki:=dat.nome[i];
  247.                                             dat.nome[i]:=dat.nome[i+1];
  248.                                             dat.nome[i+1]:=ki;
  249.                                             z:=dat.l[i];
  250.                                             dat.l[i]:=dat.l[i+1];
  251.                                             dat.l[i+1]:=z;
  252.                                             z:=dat.t[i];
  253.                                             dat.t[i]:=dat.t[i+1];
  254.                                             dat.t[i+1]:=z;
  255.                                             z:=1;
  256.                                       end;
  257.                                   end;
  258.                             until
  259.                                  z=0;
  260.                      writeln('    Nome Giocatore                Punteggio       Livello      Tentativi');
  261.                      for z:=1 to dim do
  262.                          if dat.nome[z]<>' ' then
  263.                             begin
  264.                                  if ww=dat.nome[z] then
  265.                                     textcolor(2)
  266.                                  else
  267.                                      textcolor(15);
  268.                                  writeln(' -  ',dat.nome[z],dat.p[z],'               ',dat.l[z],'            ',dat.t[z]);
  269.                                  textcolor(15);
  270.                             end;
  271.                      readln;
  272.                end;
  273.                3:begin
  274.                      rewrite(cl);
  275.                      for z:=1 to dim do
  276.                      begin
  277.                           dat.nome[z]:=' ';
  278.                           dat.p[z]:=-maxint;
  279.                           dat.l[z]:=0;
  280.                           dat.t[z]:=0;
  281.                      end;
  282.                      write(cl,dat);
  283.                      writeln('Classifica Cancellata');
  284.                      readln;
  285.                end;
  286.           end;
  287.     until
  288.          z=0;
  289. end.