program Truco;
uses CRT;
(***************************************************************************)
type
TNaipe = record
Palo : (Espada,Basto,Oro,Copa);
Nro : Byte;
Dib : char;
end;
TBaraja = array [1..40] of TNaipe;
(***************************************************************************)
Var
Espad : TNaipe;
Baraja : TBaraja;
Ch : char;
I : integer;
(***************************************************************************)
procedure RandomCarta(var Naipe : Tnaipe);
var
I : Integer;
J : Integer;
begin
I := Random(4)+1;
J := Random(12)+1;
If (J=8) or (J=9) Then J := Random(12)+1; {¿y si sale otra vez 8 o 9 ?no lo controlas y tienes que controlarlo, ojo}
Naipe.Nro := J;
Case I of
1: begin
Naipe.Palo := Espada;
Naipe.Dib := #6;
end;
2: begin
Naipe.Palo := Basto;
Naipe.Dib := #3;
end;
3: begin
Naipe.Palo :=Oro;
Naipe.Dib := #4;
end;
4: begin
Naipe.Palo :=Copa;
Naipe.Dib := #5;
end;
end;
end;
function SinRepetir(N:Integer; Naipe:TNaipe; Maso:TBaraja ) : boolean;
var I : Integer;
begin
for I := 1 to N do
begin
if(Maso.Nro=Naipe.Nro)
and (Ord(Maso.Palo)=Ord(Naipe.Palo))
then SinRepetir := False
else SinRepetir := True
end;
end;
procedure RandomBaraja(var Maso : TBaraja);
var
I : integer;
Carta : TNaipe;
begin
for I := 1 to 40 do
begin
RandomCarta(Carta);
If SinRepetir(I,Carta,Maso)
then Maso := Carta
else RandomCarta(Carta); {aqui si se da otra repeticion no va a controlarla ¿que tal un "repeat RandomCarta(Carta) until SinRepetir(I,Carta,Maso)"? }
end;
end;
(***************************************************************************)
Begin
TextMode(3);
ClrScr;
Randomize;
RandomBaraja(Baraja);
TextColor(4);
for I := 1 to 40 do
begin
WriteLn(' ',Baraja.Nro:5,' ',Baraja.Dib);
if I = 20 Then
begin
window(40,1,70,25);
WriteLn(' ',Baraja.Nro:5,' ',Baraja.Dib)
end;
end;
ReadKey;
End.