program ejer72;
uses crt;
const
min=1;
max=4;
type
tRango=1..6;
tJuego=array[min..max] of tRango;
var
maquina,jugador:tJuego;
ganador:boolean;
intentos, estanbien:byte;
function Repetidos (mac:tJuego):boolean;
var
aux:boolean;
begin
aux:=false;
if (mac[1]=mac[2]) or (mac[1]=mac[3]) or (mac[1]=mac[4]) or
(mac[2]=mac[4]) or (mac[3]=mac[4]) or (mac[3]=mac[2]) or
(mac[1]=mac[2]) and (mac[3]=mac[4]) and (mac[1]=mac[3]) and (mac[2]=mac[4]) then
aux:=true;
Repetidos:=aux;
end;
procedure Generar(var clave:tJuego);
var
i:tRango;
begin
randomize();
for i:=1 to max do
begin
clave[i]:=random(6);
end;
end;
procedure Intento(var partida:tJuego);
var
i:tRango;
begin
for i:=1 to max do
begin
write('Numero ', i,':' );
readln(partida[i]);
end;
end;
procedure Hundidos(a,b:tJuego;var bien:byte);
var
i:tRango;
aux:byte;
begin
aux:=0;
for i:=1 to max do
if (a[i]=b[i]) then
begin
aux:=aux+1;
writeln('La posición ',i,' es correcta.');
end;
writeln('Tienes ', aux, ' ahorcados. ');
bien:=aux;
end;
procedure Tocados(c,d:tJuego);
var
i,j,tocado,buscado:byte;
begin
tocado:=0;
for i:=1 to max do
begin
buscado:=d[i];
for j:=1 to max do
if (buscado=c[j]) and (i<>j) then
tocado:=tocado+1;
end;
writeln('Tienes ', tocado,' a punto de guillotina. ');
end;
begin
clrscr;
ganador:=false;
intentos:=0;
writeln('============================');
writeln('|| JUEGO DEL MASTER MIND ||');
writeln('============================');
writeln;
writeln('Este juego consiste en adivinar los 4 números que genera el ordenador');
writeln('aleatoriamente. Se le irá diciendo cuáles han sido descubiertos y cuantos');
writeln('están en la lista, pero mal ordenados.');
writeln('Los números que podrá introducir son: 0,1,2,3,4 y 5.');
writeln('A continuación la máquina creará su lista...');
Generar(maquina);
while Repetidos(maquina) do
Generar(maquina);
writeln('EL JUEGO HA COMENZADO...');
writeln('* * * *');
writeln('Adivine qué numeros esconden estos asteriscos...');
while (not ganador) and (intentos<6) do
begin
Intento(jugador);
writeln;
intentos:=intentos+1;
Hundidos(maquina,jugador,estanbien);
if (estanbien=4) then
begin
ganador:=true;
writeln('Los ha descuebierto todos.');
end
else
Tocados(maquina,jugador);
writeln;
writeln('Le quedan ',6-intentos, ' intentos.');
writeln;
end;
writeln;
if ganador then
writeln('Enhorabuena, ha ganado.')
else
writeln('Lo siento, intentelo de nuevo. ');
readln;
end.