program indovina;
uses
crt;
const
dim=10;
type
f=record
nome:array[1..dim] of string;
p:array[1..dim] of integer;
l:array[1..dim] of integer;
t:array[1..dim]of integer;
end;
files=file of f;
var
n,x,z,i,kkk:integer;
y,v,max,min:longint;
cl:files;
dat:f;
ww,ki:string[30];
procedure menu(var n:integer);
var
z:char;
x,i:integer;
begin
i:=random(4)+5;
gotoxy(5,5);
write('[ ] Livello 1 [1-100]');
gotoxy(5,6);
write('[ ] Livello 2 [1-1000]');
gotoxy(5,7);
write('[ ] Livello 3 [1-10000]');
gotoxy(5,8);
write('[ ] Livello 4 [1-100000]');
gotoxy(6,i);
textcolor(2);
write('*');
z:=#27;
while(z<>#13)do
begin
repeat
z:=readkey;
until
(z=#80) or (z=#72) or (z=#13);
if(z=#80) and (wherey<>8)then
begin
textcolor(2);
gotoxy(6,i);
write(' ');
gotoxy(6,i+1);
write('*');
i:=i+1;
end
else
if(z=#72) and (wherey<>5)then
begin
textcolor(2);
gotoxy(6,i);
write(' ');
gotoxy(6,i-1);
write('*');
i:=i-1;
end
end;
x:=wherey;
n:=x-4;
textcolor(15);
end;
function livello(n:integer):longint;
begin
case n of
1:livello:=random(100)+1;
2:livello:=random(1000)+1;
3:livello:=random(10000)+1;
4:livello:=random(100000)+1;
end;
end;
procedure control(y:longint; var x,n:integer; var a,max,min:longint);
begin
writeln('Livello ',n,' Per uscire inserire 0 ');
writeln('Numero consigliato::',(max+min)div 2,' max ',max,' min ',min);
writeln('Inserire il numero');
repeat
readln(a);
until
(a>=0);
if (a<>y)and(a<>0) then
begin
if a<y then
begin
if(y-a<y-max) and (a>min)then
max:=a
else
min:=a;
writeln('Il numero inserito e'' maggiore');
end
else begin
if(a-y<max-y) and (a>min)then
max:=a
else
min:=a;
writeln('Il numero inserito e'' minore');
end;
x:=x+1;
end
else if(a<>0) then
writeln('Hai indovinato il numero in ',x,' tentativi');
if a<>0 then
delay(1000);
end;
function punteggio(n,x:integer):integer;
begin
punteggio:=(n*10)-x;
end;
procedure menup(var n:integer);
begin
writeln('1:Gioca');
writeln('2:Classifica');
writeln('3:Elimina Classifica');
writeln('0:Uscita');
repeat
writeln('Scelta:');
readln(n);
until
(n>=0) and (n<=3);
end;
procedure ordina(var s:string);
begin
while(length(s)<30) do
s:=s+' ';
end;
begin{main}
randomize;
kkk:=0;
assign(cl,'classifica.dat');
//rewrite(cl);
reset(cl);
ww:=' ';
textcolor(15);
repeat
clrscr;
menup(z);
case z of
1:begin
writeln('Inserire il tuo nome');
readln(ww);
ordina(ww);
clrscr;
textcolor(15);
menu(n);
y:=livello(n);
case n of
1:max:=100;
2:max:=1000;
3:max:=10000;
4:max:=100000;
end;
min:=0;
x:=0;
repeat
clrscr;
writeln('0:Arrendersi');
control(y,x,n,v,max,min);
until
(v=y) or (v=0);
clrscr;
textcolor(4);
if v<>0 then
begin
v:=punteggio(n,x);
writeln('Il tuo punteggio e'' ',v);
if kkk=0 then
begin
seek(cl,0);
read(cl,dat);
kkk:=1;
end;
repeat
z:=0;
for i:=1 to dim-1 do
begin
if dat.p[i]<dat.p[i+1] then
begin
z:=dat.p[i];
dat.p[i]:=dat.p[i+1];
dat.p[i+1]:=z;
ki:=dat.nome[i];
dat.nome[i]:=dat.nome[i+1];
dat.nome[i+1]:=ki;
z:=dat.l[i];
dat.l[i]:=dat.l[i+1];
dat.l[i+1]:=z;
z:=dat.t[i];
dat.t[i]:=dat.t[i+1];
dat.t[i+1]:=z;
z:=1;
end;
end;
until
z=0;
for z:=1 to dim do
if v>dat.p[z] then
begin
for i:=dim downto z+1 do
begin
dat.nome[i]:=dat.nome[i-1];
dat.p[i]:=dat.p[i-1];
dat.l[i]:=dat.l[i-1];
dat.t[i]:=dat.t[i-1];
end;
dat.nome[z]:=ww;
dat.p[z]:=v;
dat.l[z]:=n;
dat.t[z]:=x;
break;
end;
rewrite(cl);
write(cl,dat);
end
else
writeln('Non hai indovinato il numero x=',y);
textcolor(15);
readln;
end;
2:begin
clrscr;
writeln('Classifica Top 10');
writeln;
writeln;
if kkk=0 then
begin
seek(cl,0);
read(cl,dat);
kkk:=1;
end;
repeat
z:=0;
for i:=1 to dim-1 do
begin
if dat.p[i]<dat.p[i+1] then
begin
z:=dat.p[i];
dat.p[i]:=dat.p[i+1];
dat.p[i+1]:=z;
ki:=dat.nome[i];
dat.nome[i]:=dat.nome[i+1];
dat.nome[i+1]:=ki;
z:=dat.l[i];
dat.l[i]:=dat.l[i+1];
dat.l[i+1]:=z;
z:=dat.t[i];
dat.t[i]:=dat.t[i+1];
dat.t[i+1]:=z;
z:=1;
end;
end;
until
z=0;
writeln(' Nome Giocatore Punteggio Livello Tentativi');
for z:=1 to dim do
if dat.nome[z]<>' ' then
begin
if ww=dat.nome[z] then
textcolor(2)
else
textcolor(15);
writeln(' - ',dat.nome[z],dat.p[z],' ',dat.l[z],' ',dat.t[z]);
textcolor(15);
end;
readln;
end;
3:begin
rewrite(cl);
for z:=1 to dim do
begin
dat.nome[z]:=' ';
dat.p[z]:=-maxint;
dat.l[z]:=0;
dat.t[z]:=0;
end;
write(cl,dat);
writeln('Classifica Cancellata');
readln;
end;
end;
until
z=0;
end.