Ho finalmente finito tutto il programma e penso che sia venuto abbastanza bene:
avrei solo una domanda, secondo voi si possono fare delle procedure\funzioni con parametri per rendere il tutto più efficiente?
program estrazione_lotto;
uses crt;
type
tabella = array[1..11,1..5] of integer;
nomi = array[1..11] of string[12];
super = array[1..6] of integer;
righe = array[1..6] of integer;
const
nomi_ruote : nomi = ('Nazionale', 'Bari','Cagliari',
'Firenze','Genova','Milano','Napoli','Palermo','Roma','Torino','Venezia');
righe_super : righe = (2,6,7,8,9,11);
var
tab:tabella;
numa,numb,numc,numd,nume,numf,ruota,band:integer;
tipo:char;
inizio:string;
sup:super;
procedure centra(scritta:string;y:integer);
var
x:integer;
begin
x:=((80-(length(scritta)))div 2);
gotoxy(x,y);
write(scritta);
end;
procedure estrazione;
var
a,b,pos,x: integer;
begin
randomize;
for a:=1 to 11 do
begin
tab[a,1]:=random(90)+1;
for b:=2 to 5 do
begin
repeat
x:=random(90)+1;
pos:=1;
while (tab[a,pos]<>x) and (pos < b) do
pos:=pos+1;
until (pos>=b);
tab[a,b]:=x
end;
end;
end;
procedure estrSuperEnalotto;
var
k,i,aux,x,pos:integer;
begin
sup[1]:=tab[2,1];
x:=0;
for k:=2 to 6 do
begin
i:=righe_super[k];
pos:=1;
aux:=tab[i,1+x];
while (sup[pos]<>aux) and (pos<=k) do
pos:=pos+1;
if pos>k then
begin
sup[k]:=tab[i,1+x];
x:=0;
end;
if pos<=k then
begin
x:=x+1;
k:=k-1;
end;
end;
end;
procedure scrivi;
var
a,b,num,col:integer;
begin
centra('Estrazione del lotto',1);
num:=2;
col:=5;
for a:=1 to 11 do
begin
gotoxy(num,col);
write (nomi_ruote[a]:9);
Write(' ');
for b:=1 to 5 do
begin
write (tab[a,b]:5);
end;
col:=col+1;
end;
writeln;
writeln;
Writeln;
end;
procedure stampa_superenalotto;
var
b:integer;
begin
Writeln(' Estrazione SuperEnalotto : ');
writeln;
for b:=1 to 6 do
begin
write(sup[b]:5);
end;
end;
procedure cerca;
var a,b,cont,num:integer;
begin
gotoxy(2,20);
Write('Cerca un Numero: ');
readln(num);
cont:=0;
for a:=1 to 11 do
for b:=1 to 5 do
if num=tab[a,b] then
begin
Writeln(' Il numero si trova nella ruota numero ',a,' in posizione ', b,'');
cont:=1;
end;
If cont=0 then writeln(' Il numero non e'' presente in nessuna ruota');
end;
procedure elenco_citta;
begin
gotoxy(2,10);
writeln('1 = Nazionale');
Writeln(' 2 = Bari');
Writeln(' 3 = Caglairi');
Writeln(' 4 = Firenze');
Writeln(' 5 = Genova');
Writeln(' 6 = Milano');
Writeln(' 7 = Napoli');
Writeln(' 8 = Palermo');
Writeln(' 9 = Roma');
writeln(' 10 = Torino');
Writeln(' 11 = Venezia');
gotoxy(1,8);
end;
procedure gioca;
var
b,a,c:integer;
begin
writeln;
Writeln;
Writeln;
write(' Vuole giocare al lotto o al superenalotto? ');
readln(inizio);
if inizio=('lotto') then
begin
clrscr;
writeln;
centra('Estrazione del lotto',1);
gotoxy(2,4);
write('Vuole giocare un numero singolo, un ambo o un terno? ');
readln(tipo);
case tipo of
's' : begin
Write(' Inserisci il numero che vuoi puntare: ');
readln(numa);
elenco_citta;
Write(' Inserisci il nome (numero da 1 a 11) della ruota in cui vuoi giocare: ');
readln(ruota);
band:=0;
a:=ruota;
for b:=1 to 5 do
begin
if (numa=tab[a,b]) then band:=band+1;
end;
if band>=1 then
begin
if numa<>numb then
begin
clrscr;
textcolor(green);
centra(' Congratulazioni, hai vinto!',11);
centra('A breve ti verra'' visualizzata l''estrazione completa',13);
gotoxy(2,19);
end;
end
else if numa=numb then
begin
clrscr;
Textcolor(red);
centra('Non puoi puntare due numeri uguali!',11);
centra('A breve ti verra'' visualizzata l''estrazione completa',13);
gotoxy(2,19);
end;
If band<1 then
begin
if numa<>numb then
begin
clrscr;
Textcolor(red);
centra('Hai perso!',11);
centra('A breve ti verra'' visualizzata l''estrazione completa',13);
gotoxy(2,19);
end;
end
else if numa=numb then
begin
clrscr;
Textcolor(red);
centra('Non puoi puntare due numeri uguali!',11);
centra('A breve ti verra'' visualizzata l''estrazione completa',13);
gotoxy(2,19);
end;
end;
'a' : begin
Write(' Inserisci il primo numero che vuoi puntare: ');
readln(numa);
Write(' Inserisci il secondo numero che vuoi puntare: ');
elenco_citta;
Write(' Inserisci il nome (numero da 1 a 11) della ruota in cui vuoi giocare: ');
readln(ruota);
band:=0;
a:=ruota;
for b:=1 to 5 do
begin
if (numa=tab[a,b]) then band:=band+1;
if (numb=tab[a,b]) then band:=band+1;
end;
if band>=2 then
begin
if numa<>numb then
begin
clrscr;
textcolor(green);
centra(' Congratulazioni, hai vinto!',11);
centra('A breve ti verra'' visualizzata l''estrazione completa',13);
gotoxy(2,19);
end;
end
else if numa=numb then
begin
clrscr;
Textcolor(red);
centra('Non puoi puntare due numeri uguali!',11);
centra('A breve ti verra'' visualizzata l''estrazione completa',13);
gotoxy(2,19);
end;
If band<2 then
begin
if numa<>numb then
begin
clrscr;
Textcolor(red);
centra('Hai perso!',11);
centra('A breve ti verra'' visualizzata l''estrazione completa',13);
gotoxy(2,19);
end;
end
else if numa=numb then
begin
clrscr;
Textcolor(red);
centra('Non puoi puntare due numeri uguali!',11);
centra('A breve ti verra'' visualizzata l''estrazione completa',13);
gotoxy(2,19);
end;
end;
't': begin
Write(' Inserisci il primo numero che vuoi puntare: ');
readln(numa);
Write(' Inserisci il secondo numero che vuoi puntare: ');
readln(numb);
Write(' Inserisci il terzo numero che vuoi puntare: ');
readln(numc);
elenco_citta;
Write(' Inserisci il nome(numero da 1 a 11) della ruota in cui vuoi giocare: ');
readln(ruota);
band:=0;
a:=ruota;
for b:=1 to 5 do
begin
if (numa=tab[a,b]) then band:=band+1;
if (numb=tab[a,b]) then band:=band+1;
if (numc=tab[a,b]) then band:=band+1;
end;
if band=3 then
begin
if (numa<>numb) and (numa<>numc) then
begin
clrscr;
textcolor(green);
centra(' Congratulazioni, hai vinto!',11);
centra('A breve ti verra'' visualizzat l''estrazione completa',13);
gotoxy(2,19);
end;
end
else if (numa=numb) or (numc=numa) or (numb=numc) then
begin
clrscr;
Textcolor(red);
centra('Non puoi puntare numeri uguali!',11);
centra('A breve ti verra'' visualizzata l''estrazione completa',13);
gotoxy(2,19);
end;
If band<3 then
begin
if (numa<>numb) and (numb<>numc) then
begin
clrscr;
Textcolor(red);
centra('Hai perso!',11);
centra('A breve ti verra'' visualizzata l''estrazione completa',13);
gotoxy(2,19);
end;
end
else if (numa=numb) or (numb=numc) or (numa=numc) then
begin
clrscr;
Textcolor(red);
centra('Non puoi puntare numeri uguali!',11);
centra('A breve ti verra'' visualizzata l''estrazione completa',13);
gotoxy(2,19);
end;
end;
end;
end
else if inizio = ('superenalotto') then
begin
clrscr;
band:=0;
centra('Gioco del superenalotto',1);
gotoxy(2,4);
Writeln('INFO: Si vince solamente fancedo sei');
writeln;
Write(' Inserisci i sei numeri che vuoi giocare seprati da uno spazio: ');
Read(numa,numb,numc,numd,nume,numf);
for c:=1 to 6 do
begin
if (numa=sup[c]) then band:=band+1;
if (numb=sup[c]) then band:=band+1;
if (numc=sup[c]) then band:=band+1;
if (numd=sup[c]) then band:=band+1;
if (nume=sup[c]) then band:=band+1;
if (numf=sup[c]) then band:=band+1;
end;
if band<6 then
begin
clrscr;
Textcolor(red);
centra('Hai perso!',11);
centra('A breve ti verra'' visualizzata l''estrazione completa',13);
gotoxy(2,19);
end;
if band>=6 then
begin
clrscr;
Textcolor(green);
centra('Hai vinto!',11);
centra('A breve ti verra'' visualizzata l''estrazione completa',13);
gotoxy(2,19);
end;
end
else
Write(' Errore, devi scrivere lotto o superenalotto');
end;
procedure tuoi_dati;
begin
gotoxy(2,18);
if inizio = 'lotto' then begin
scrivi;
if tipo = ('a') then
begin
writeln(' I numeri che avevi puntato sono: ',numa,' e ',numb);
Writeln(' Hai puntato nella ruota di ', nomi_ruote[ruota]);
end
else if tipo = ('t') then
begin
writeln(' I numeri che avevi puntato sono: ',numa,', ',numb,' e ',numc);
Writeln(' Hai puntato nella ruota di ', nomi_ruote[ruota]);
end
else if tipo = ('s') then
begin
writeln(' Il numero che hai puntato e'': ',numa);
Writeln(' Hai puntato nella ruota di ', nomi_ruote[ruota]);
end;
end
else if inizio = 'superenalotto' then
begin
scrivi;
gotoxy(2,18);
stampa_superenalotto;
Writeln;
Writeln;
Write(' I numeri che hai puntato sono: ',numa,' ', numb,' ',numc,' ',numd,' ',nume,' ', numf);
Writeln;
Write(' Hai indovinato ', band,' numeri');
readln;
end;
end;
var scelta:string;
begin
repeat
clrscr;
estrazione;
estrSuperEnalotto;
centra('Estrazione del lotto',1);
gioca;
delay(5000);
textcolor(7);
clrscr;
writeln;
Writeln;
tuoi_dati;
textcolor(7);
Writeln;
Writeln;
Writeln;
Writeln;
Write(' Vuoi continuare?(si\no) ');
readln(scelta);
until scelta='no'
end.