program GiocoNumeri;
uses crt;
var a,b,c,z,risp1,risp2,risp3,risp4,rispPos: integer;
begin
randomize;
repeat
repeat
clrscr;
textcolor(lightgreen);
gotoxy(6,2);
writeln('Semplice gioco che coniste nell''indovinare il numero che pensa il PC');
textcolor(lightmagenta);
writeln;
writeln;
write('Scegli il livello (1=Numeri da 1 a 10, 2=Numeri da 1 a 20, 3=Numeri da 1 a 30) =');
readln(risp1);
if risp1 > 3 then
begin
textcolor(lightred);
write('Errore di inserimento dati!!! Scegliere un valore compreso tra 1 e 3');
end;
until
risp1 <= 3;
writeln;
write('Scegli il numero di tentativi di risposta che puoi dare al massimo=');
readln(risp2);
writeln;
for z:= 1 to 80 do write(char(205));
risp3:=risp2+1;
if risp1 = 1 then
begin
a:=random(10);
end;
if risp1 = 2 then
begin
a:=random(20);
end;
if risp1 = 3 then
begin
a:=random(30);
end;
writeln;
c:=1;
repeat
begin
writeln;
writeln('Scrivi il numero che tu presupponi io pensi');
readln(b);
if b > a then
begin
textcolor(lightred);
writeln('Numero troppo grande');
sound(4000);
delay(200);
sound(3000);
delay(150);
sound(2000);
delay(100);
nosound;
textcolor(lightmagenta);
end;
if a > b then
begin
textcolor(lightred);
writeln('Numero troppo piccolo');
sound(2000);
delay(100);
sound(3000);
delay(150);
sound(4000);
delay(200);
nosound;
textcolor(lightmagenta);
end;
if a = b then
begin
rispPos:=1;
textcolor(lightgreen);
writeln('Hai indovinato bravo');
sound(2000);
delay(100);
sound(3000);
delay(150);
sound(4000);
delay(200);
nosound;
end;
c:=c+1;
end;
until
(c = risp3) or (rispPos = 1);
writeln;
textcolor(lightblue);
writeln('Il numero che io avevo pensato era ',a);
textcolor(yellow);
writeln;
writeln;
writeln;
write('Premere 1 per continuare, 0 per uscire=');
readln(risp4);
until risp4=0
end.