Pascal/Turbo Pascal - juego de cartas

 
Vista:

juego de cartas

Publicado por franco sanguedolce (32 intervenciones) el 23/04/2013 21:24:27
hola gente, bueno se me presento un amigo a casa y me dio un desafio, programar el juego del truco,
la cuestion es que intentando programarlo se me plantea la situacion donde debo crear el mazo de cartas,

para lo cual use esto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Type
  cartas = array [1..40]
           Of string[3];
 
  players = Record
    c: array[1..3] Of string[5];
    puntos: byte;
  End;
 
Var
  i: byte;
  carta: cartas;
  num: array[1..10] Of string[2] = ('1','2','3','4','5','6','7','10','11','12');
  let: array[1..4] Of string[1] = ('e','b','o','c');
  jug: players;
  com: players;
 
 
 
Procedure inicializacartas;
 
Var i,j: byte;
Begin
  For i:=1 To 10 Do
    For j:=1 To 1 Do
      carta[i] := num[i]+let[j];
 
  For i:=11 To 20 Do
    For j:=2 To 2 Do
      carta[i] := num[i-10]+let[j];
 
  For i:=21 To 30 Do
    For j:=3 To 3 Do
      carta[i] := num[i-20]+let[j];
 
  For i:=31 To 40 Do
    For j:=4 To 4 Do
      carta[i] := num[i-30]+let[j];
End;


donde crea el mazo de cartas,

pero aqui esta la cuestion, como puedo hacer para que las cartas se repartan de manera aleatoria 3 para cada jugador( jugador y computadora) sin que se me repitan en la mano,

habia hecho algo asi

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
procedure repartecartas;
var i,j:byte;
    ran:byte;
begin
    randomize;
    for i:= 1 to 3 do
    begin
      ran:=random(40)+1;
        jug.c[i]:=carta[ran];
      end;
    for i:= 1 to 3 do
    begin
      ran:=random(40)+1;
        com.c[i]:=carta[ran];
    end;
    if (jug.c[1]=jug.c[2]) or (jug.c[2]=jug.c[3]) or (jug.c[1]=com.c[1])
    or (jug.c[1]=com.c[2]) or (jug.c[1]=com.c[3]) or (jug.c[2]=com.c[1])
    or (jug.c[2]=com.c[2]) or (jug.c[2]=com.c[3]) or (jug.c[3]=com.c[1])
    or (jug.c[3]=com.c[2]) or (jug.c[3]=com.c[3]) or (com.c[1]=com.c[2])
    or (com.c[2]=com.c[3]) then
    repartecartas;
end;


como veran puse en las condiciones que si alguna carta en mano de los jugadores era igual se volviera a empezar,

pero aun asi, se repiten cartas,

como resuelvo esto??
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

juego de cartas

Publicado por ramon (2158 intervenciones) el 25/04/2013 21:23:07
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
{A ver si esto te ayuda}
 
program cartas;
 uses
    crt;
 
 
  type
    cartasjugador = array[1..10] of string[6];
 
 
  const
      barajacarta : array[1..40] of string[6] = (
      'CPAS1','CPOP2','CPOP3','CPOP4','CPOP5','CPOP6','CPOP7',
      'CPST8','CPCB9','CPRI10',
      'ORAS1','ORRS2','ORRS3','ORRS4','ORRS5','ORRS6','ORRS7',
      'ORST8','ORCB9','ORRI10',
      'ESAS1','ESRS2','ESRS3','ESRS4','ESRS5','ESRS6','ESRS7',
      'ESST8','ESCB9','ESRI10',
      'BTAS1','BTRS2','BTRS3','BTRS4','BTRS5','BTRS6','BTRS7',
      'BTST8','BTCB9','BTRI10');
 
 
    var
    jugador : array[1..4] of cartasjugador;
    jug, cont : integer;
    num : word;
    salir, repart : boolean;
 
 
  procedure repartecartas;
  begin
     randomize;
     repart := false;
     cont := 1;
     jug := 1;
   repeat
       num := random(40) + 1;
       if barajacarta[num] <> '0' then
       begin
          jugador[cont,jug] := barajacarta[num];
          barajacarta[num]  := '0';
          jug := jug + 1;
          if jug > 10 then
          begin
             jug := 1;
             cont := cont + 1;
             if cont > 4 then
             repart := true;
          end;
       end;
   until repart = true;
  end;
 
  procedure quitacarta(x, y, jg, cr : integer);
  begin
     jugador[jg,cr] := ' ';
     gotoxy(x,y);write('      ');
  end;
 
  procedure presentacarta(x, y, jg, cr : integer);
  begin
     gotoxy(10 + (jg * 8),19);write(jugador[jg,cr]);
     quitacarta(x,y,jg,cr);
  end;
 
  procedure recojecartas;
  begin
      gotoxy(10,19);clreol;
  end;
 
  function finalpartida : boolean;
  var
    n, l, t : integer;
  begin
     finalpartida := false;
     n := 0;
     for l := 1 to 4 do
     begin
       for t := 1 to 10 do
       begin
       if jugador[l,t] = ' ' then
       n := n + 1;
       if n > 10 then
       break;
       end;
     end;
       if n > 10 then
       begin
       writeln;
       writeln('  Partida Finalizada Gana Jugador Num : ',l);
       writeln('  Pulse Enter');
       readln;
       finalpartida := true;
      end;
  end;
 
  procedure presenta_cartas;
  var
     u : integer;
  begin
    gotoxy(2,2);write('Jug. Num. 1');
    for u := 1 to 10 do
    begin
    gotoxy(4,2 + u);write(jugador[1,u]);
    end;
    gotoxy(19,2);write('Jug. Num. 2');
    for u := 1 to 10 do
    begin
    gotoxy(21,2 + u);write(jugador[2,u]);
    end;
    gotoxy(36,2);write('Jug. Num. 3');
    for u := 1 to 10 do
    begin
    gotoxy(38,2 + u);write(jugador[3,u]);
    end;
    gotoxy(52,2);write('Jug. Num. 4');
    for u := 1 to 10 do
    begin
    gotoxy(54,2 + u);write(jugador[4,u]);
    end;
  end;
 
  function estriunfo : string;
  var
    nt : word;
    triu : string[12];
  begin
     estriunfo := ' ';
     randomize;
     nt := random(4) + 1;
   case nt of
 1 : triu := 'Copas';
 2 : triu := 'Oros';
 3 : triu := 'Espadas';
 4 : triu := 'Vastos';
   end;
   estriunfo := copy(triu,1,length(triu));
  end;
 
  procedure jugamos;
  var
    inici : word;
    carta : string[6];
    cc, c, pos, qui : integer;
  begin
     pos := 4;
     randomize;
     inici := random(4) + 1;
     gotoxy(10,22);write(' El Triunfo Es : ',estriunfo);
     gotoxy(10,23);write(' Inicia El Juego El Num [',inici,']');
     gotoxy(10,24);write(' Sige Por La Derecha De La Pantalla');
     cc := 1;
   repeat
       gotoxy(42,23);write('Carta = ');
       gotoxy(50,23);readln(carta);
       for c := 1 to length(carta) do
       carta[c] := upcase(carta[c]);
       for qui := 1 to 10 do
       if jugador[inici,qui] = carta then
       begin
           case inici of
         1 : pos := 4;
         2 : pos := 21;
         3 : pos := 38;
         4 : pos := 54;
          end;
           presentacarta(pos,2 + qui,inici,qui);
           inici := inici + 1;
           cc := cc + 1;
           if inici > 4 then
           begin
           inici := 1;
           end;
           if cc > 4 then
           begin
           recojecartas;
           cc := 1;
           end;
           gotoxy(10,23);clreol;
           gotoxy(10,23);write(' Sigiente El Juego El Num [',inici,']');
       end;
   until (finalpartida = true) or (carta = ' ');
  end;
 
 
 
  begin
     clrscr;
     repartecartas;
     presenta_cartas;
     jugamos;
  end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar