Pascal/Turbo Pascal - Proyecto - juego (DUDA)

 
Vista:
sin imagen de perfil

Proyecto - juego (DUDA)

Publicado por doug (3 intervenciones) el 09/04/2016 08:22:12
Antes que nada quiero aclarar que no es todo el programa si no lo que llevo adelantado, es decir que es solo una parte no lo tengo listo.
Estoy programando un juego que es algo asi como un mapa con coordenadas el cual tienes minas (M) el cual las decreta el usuario, la maxima cantidad de columnas y filas es 15x15 por lo tanto las maximas minas son 15, entonces diseñando el programa tengo que poner las minas en orden aleatorio, las coordenadas x,y tienen que ser aleatorias, usé el random pero hay un detalle hay ocasiones que salen coordenadas repetidas como por ejemplo:
son 5 minas
y sale lo siguiente:
13 5
5 3
4 5
3 2
3 2 ahi se repite
quisiera saber como arreglo eso para que no se repitan las coordenadas! Saludos y gracias
OJO: Tengo prohibido el uso de arrays!
aqui el cod
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
program juego;
var
 X, Y, M, cont, a, b, mx, my :integer;
 SX, SY, mostrar,S3:string;
begin
randomize;
 writeln('Inserte el numero de filas(x) (maximo 15)'); readln(X);
 if (x>0) and (x<=15) then
  begin
  writeln('Inserte el numero de columnas(y) (maximo 15).'); readln(Y);
  end;
  if (x>15) then
   writeln('Numero max. de filas excedido.');
  if (y>15) then
   writeln('Numero max. de columnas excedido.');
   if (y>0) and (y<=15) then
   begin
    writeln('Inserte el numero de minas.'); readln(M);
    end;
    if (x>y) then
     begin
     if (m>x) then
     writeln('Cantidad max de minas excedida.');
     end;
    if (y>x) then
     begin
      if (m>y) then
      writeln('Cantidad max de minas excedida.');
     end;
      if (x=y) then
       begin
        if (m>x) or (m>y) then
        writeln('Cantidad max de minas excedida.');
        end;
    if (x<0) or (y<0) or (m<0) then
    begin
    writeln('No se admiten numeros negativos.');
    end;
    if (x>0) and (y>0) and (m>0) then
    begin
     if ((x>y) and (m<=x)) or ((y>x) and (m<=y))or ((x=y) and (m<=x) or (m<=y)) then
      begin
       for cont:=1 to m do
        begin
        sx:=''; sy:=''; mostrar:='';
        mx:=random(x)+1; my:=random(y)+1;
        str(mx,sx); str(my,sy);
        mostrar:=sx+' '+sy;
        writeln;
            writeln(mostrar);
         end;
        end;
      end;
readln;
end.
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

Proyecto - juego (DUDA)

Publicado por ramon (2158 intervenciones) el 12/04/2016 13:39:51
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
{Mira a ver si ayuda }
 
program juego;
  uses
     crt;
  var
     X, Y, M, cont, a, b, mx, my : integer;
     SX, SY : string[2];
     mostrar,S3:string;
 
    function entrada_datos(var x1, y1, m1 : integer) : boolean;
    var
      i, u : integer;
    begin
       entrada_datos := false;
       write('   Inserte el numero de filas(x) (maximo 15)    : ');
       readln(x1);
       if ((x1 > 15) and (x1 < 1)) then
       begin
          writeln('Numero max. de filas excedido. O Filas  Nulas');
       end
     else
       begin
       write('   Inserte el numero de columnas(y) (maximo 15) : ');
       readln(y1);
       if ((y1 > 15) and (y1 < 1)) then
       begin
         writeln('Numero max. de columnas excedido. O Columnas  Nulas');
       end
    else
       begin
          write('   Inserte el numero de minas. Maximo ',x1,' : ');
          readln(m1);
          if (m1 < x1) and (m1 > 0) then
          begin
             mostrar := ' ';
             sx := ' ';
             sy := ' ';
             entrada_datos := true;
          end;
        end;
      end;
    end;
 
    function numerorepetido(z1, z2 : integer) : boolean;
    var
      valor, toma : string[5];
      v1, v2 : string[2];
      r, a, lo : integer;
    begin
       str(z1,v1);
       str(z2,v2);
       lo := 0;
       valor := v1 + 'x' + v2;
       lo := length(v1) + 1 + length(v2);
       valor[0] := chr(lo);
       numerorepetido := false;
       if length(mostrar) > 5 then
       begin
          for lo := 1 to length(mostrar) do
          if mostrar[lo] = #0 then
          begin
             r := 1;
             for a := lo - 1 downto 1 do
             if mostrar[a] <> #0 then
             begin
             insert(mostrar[a],toma,1);
             r := r + 1;
             end
           else
              begin
                toma[0] := chr(r - 1);
                break;
              end;
          end;
       end;
    end;
 
 
   procedure genera_coordenadas(c : integer; var mmk : string);
   var
     pp, r, h : integer;
     corx, cory : string[2];
     xn1, yn1 : integer;
     dato : string[5];
   begin
      h := 0;
      r := 1;
      pp := 0;
      repeat
          xn1 := random(x + y) + 1;
          yn1 := random(x + y) + 1;
          if numerorepetido(xn1, yn1) = false then
          begin
             dato := ' ';
             str(xn1,corx);
             str(yn1,cory);
             dato := corx + 'x' + cory;
             dato[0] := chr(length(corx) + 1 + length(cory));
             r := r + length(dato) + 1;
             insert(dato,mmk,(r - length(dato) + 1));
             mmk[0] := chr(r);
             dato := ' ';
             h := h + 1;
          end;
          pp := pp + 1;
      until (h > m - 1) or (pp > (x * y));
   end;
 
   procedure ponminas_en_cordenadas(m : string);
   var
     t, i : integer;
     da1, da2 : string[2];
     erro, c : integer;
     x1, y1 : integer;
   begin
     t := 1;
     c := 1;
     repeat
         if m[t] <> 'x' then
         begin
            if m[t] <> ' ' then
            begin
               da1[c] := m[t];
               da1[0] := chr(c);
               c := c + 1;
            end;
         end;
         if m[t] = 'x' then
         begin
            c := 1;
            for i := 1 to 3 do
            begin
               if m[t + i] <> #0 then
               begin
                  if m[t + i] <> ' ' then
                  begin
                     da2[c] := m[t + i];
                     da2[0] := chr(c);
                     c := c + 1;
                  end;
               end;
                if (da1 <> ' ') and (da2 <> ' ') then
                begin
                 val(da1,x1,erro);
                 if erro <> 0 then
                 begin
                    delete(da1,erro,1);
                    val(da1,x1,erro);
                 end;
                 val(da2,y1,erro);
                 if erro <> 0 then
                 begin
                    delete(da2,erro,1);
                    val(da2,y1,erro);
                 end;
                 gotoxy(x1,y1);write('*');
                 da1 := ' ';
                 da2 := ' ';
               end;
            end;
              t := t + c;
              c := 1;
         end;
           t := t + 1;
     until t > length(m);
 
   end;
 
 
 
   begin
      clrscr;
      randomize;
      if entrada_datos(x, y, m) = true then
      begin
         mostrar := ' ';
         genera_coordenadas(m,mostrar);
         writeln;
         clrscr;
         ponminas_en_cordenadas(mostrar);
         readln;
      end;
   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
sin imagen de perfil

Proyecto - juego (DUDA)

Publicado por doug (3 intervenciones) el 13/04/2016 09:11:37
hola Ramón! he probado tu código pero cuando ingreso el numero de minas y le doy a enter no me sale mas nada, le doy a enter una vez y me sale vacio le doy otra vez y se me cierra. que puedo hacer?
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

Proyecto - juego (DUDA)

Publicado por ramon (2158 intervenciones) el 13/04/2016 13:00:22
Mira entra 15 15 y 5 en las entradas e privado y funciona bien pero dime que pascal empleas
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
sin imagen de perfil

Proyecto - juego (DUDA)

Publicado por doug (3 intervenciones) el 14/04/2016 01:52:44
dev pascal!
Lo que necesito es que el usuario meta las coordenadas X y Y, y luego la cantidad de minas y me generen las coordenadas segun la cantidad de minas (si son 5 minas 5 coordenadas,y así) pero que no se repitan. Me di cuenta que usar el ''for'' está mal porque no las podría guardar cada una en un string. Así que que me podrías recomendar? saludos
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