Pascal/Turbo Pascal - Tablero en pascal !

 
Vista:

Tablero en pascal !

Publicado por Sabrina (9 intervenciones) el 09/07/2016 08:38:16
Hola! Hice este programa pero no puedo hacer que se dibuje el recorrido en el tablero.
Si alguien me puede ayudar seria genial.
necesito que la primera vez me marque la posicion inicial del robot con una 'X' y despues con una 'x' por cada casilla que pase hasta la posicion final, que tiene que marcar una 'X'.

No tengo idea de como ingresar el caracter en la casilla .

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
Program Robot(output,input);
Uses crt;
Const filas=20;
      columnas=20;
      simbolo: array [0..2] of char  = (' ', 'x', 'X');
Var H:integer;
    tablero:array[1..filas,1..columnas] of integer;
 
Procedure IndiquePOS;
VAR J,I:INTEGER;
Begin
WRITE('Ingrese la fila: ');
READLN(i);
write('Ingrese la columna: ');
readln(j);
END;
 
Procedure Baston;
var J,I,D,W:integer;
    secuencia:string[25];
    mando:array[1..25] of char;
 
Begin
writeln('');
writeln('                    (Arriba)');
writeln('                       N ');
writeln('         (Izquierda) O   E (Derecha)');
writeln('                       S ');
writeln('                    (Abajo)');writeln('');
writeln('Ingrese en MAYUSCULAS, la secuencia de movimiento: ');
read(secuencia);
mando:=secuencia;
for D:= 1 to 20 do
begin
    if mando[D]='E' then
    i:=i+1
    else
        if mando[D]='O' then
        i:=i-1;
end;
for W:= 1 to 20 do
begin
    if mando[W]='N' then
    j:=j+1
    else
    if mando[W]='S' then
    j:=j-1
end;
write('Fila: ',i);
writeln(' Columna: ',j);
end;
 
Procedure DibujarTablero;
var
    F, C: integer;
begin
    WriteLn;
    WriteLn('-------------------------------------------------------------');
    for F := 1 to 20 do
    begin
        Write('|');
        for C := 1 to 20 do
            Write(' '+simbolo[tablero[F,C]]+'|');
        WriteLn;
        WriteLn('-------------------------------------------------------------');
    end
end;
Begin
     Repeat
     Begin
          H:=H+1;
          IndiquePOS;
          DibujarTablero;
          Baston;
          DibujarTablero;
     end;
     until H=5 ;
     readkey;
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

Tablero en pascal !

Publicado por ramon (2158 intervenciones) el 09/07/2016 19:31:37
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
{Mira Esto}
 
 program robot;
 uses
    crt;
  const
 
      longordenmax = 25;
 
  type
    cuadros = array[1..20,1..20] of char;
    string25 = string[25];
 
 
   var
     tablero : cuadros;
     t, x, y : integer;
     mando : string25;
     posinix, posfinx, posiniy, posfiny : integer;
     origrnmodo : integer;
     tec : char;
     pri : boolean;
 
 
   procedure iniciatablero;
   begin
      fillchar(tablero,sizeof(tablero),chr(32));
      pri := true;
   end;
 
   procedure tablerorobot(txr, tyr : integer);
   var
     zx, zy : integer;
   begin
       gotoxy(txr + 2,tyr + 1);
         write('-----------------------------------------');
       for zy := 1 to 20 do
       begin
         gotoxy(txr + 2,tyr + (zy * 2) + 1);
         write('-----------------------------------------');
         for zx := 1 to 21 do
         begin
            gotoxy(txr + (zx * 2),tyr + (zy * 2));write('|');
         end;
 
       end;
   end;
 
   procedure presentatablero(x1, y1 : integer);
   var
      t1, t2 : integer;
   begin
      if y1 > 1 then
      begin
      gotoxy(x1 + 7,y1 - 1);write('   ****** El Tablero ******');
      end
   else
      begin
        gotoxy(x1,y1);write('   ****** El Tablero ******');
      end;
      writeln;
      for t1 := 1 to 20 do
        for t2 := 1 to 20 do
        begin
        gotoxy((x1 + 1) + (t2 * 2), (y1* 1) + (t1 * 2));write(tablero[t1,t2]);
        end;
   end;
 
   function cordenadasx(xcmax : integer) : boolean;
   begin
       if (xcmax < 20) or (xcmax > 1) then
       cordenadasx := true
    else
       cordenadasx := false;
   end;
 
 
    function cordenadasy(ycmax : integer) : boolean;
    begin
       if (ycmax < 20) or (ycmax > 1) then
       cordenadasy := true
    else
       cordenadasy := false;
   end;
 
   procedure ponposicionrobot(xr, yr : integer);
   begin
      if pri = true then
      tablero[yr,xr] := chr(88)
    else
      tablero[yr,xr] := chr(120);
   end;
 
   procedure entradacoryman(var x1, y1 : integer; var baston : string25);
   begin
      clrscr;
      writeln('   **** Entrada Cordenadas X E Y De Inicio Y Mando ****');
      writeln;
      write('  Posicion columnas : ');
      readln(x1);
      write('  Posicion filas    : ');
      readln(y1);
      write('  Mando : ');
      readln(baston);
      posinix := x1;
      posiniy := y1;
      posfinx := 0;
      posfiny := 0;
      tablero[y1,x1] := chr(88);
      clrscr;
   end;
 
 
   begin
      origrnmodo := lastmode;
      textmode(c80 + font8x8);
      clrscr;
      iniciatablero;
      entradacoryman(x,y,mando);
      if (cordenadasx(x) = true) and (cordenadasy(y) = true) then
      begin
      ponposicionrobot(x,y);
      for t := 1 to length(mando) do
      begin
   case mando[t] of
  'n','N' : y := y + 1;
  's','S' : y := y - 1;
  'e','E' : x := x + 1;
  'o','O' : x := x - 1;
     end;
       if (cordenadasx(x) = true) and (cordenadasy(y) = true) then
       begin
          tablero[y,x] := chr(120);
       end;
      end;
      posfinx := x;
      posfiny := y;
      presentatablero(10,3);
      gotoxy(1,46);write('   Posicion Inicial columna : ',posinix,
      '   fila ',posiniy,'   Posicion Final columna : ',posfinx,' fila ',posfiny);
      pri := false;
      tablerorobot(10,3);
 repeat
      tablero[y,x] := chr(88);
      tablerorobot(10,3);
      presentatablero(10,3);
      gotoxy(10,48);write('   Desea Entrar Mas Mandotos [S/N]');
    repeat
        tec := upcase(readkey);
    until tec in['S','N'];
    if tec = 'S' then
    begin
       gotoxy(1,46);clreol;
       gotoxy(10,48);clreol;
       tablerorobot(10,3);
       iniciatablero;
       x := posfinx;
       y := posfiny;
       gotoxy(1,46);write('  Mando : ');
       readln(mando);
       tablero[y,x] := chr(88);
       ponposicionrobot(x,y);
       posinix := x;
       posiniy := y;
       gotoxy(1,46);clreol;
       gotoxy(10,48);clreol;
      for t := 1 to length(mando) do
      begin
   case mando[t] of
  'n','N' : y := y + 1;
  's','S' : y := y - 1;
  'e','E' : x := x + 1;
  'o','O' : x := x - 1;
     end;
       if (cordenadasx(x) = true) and (cordenadasy(y) = true) then
       begin
          tablero[y,x] := chr(120);
       end;
      end;
      posfinx := x;
      posfiny := y;
      presentatablero(10,3);
      gotoxy(1,46);write('   Posicion Inicial columna : ',posinix,
      '   fila ',posiniy,'   Posicion Final columna : ',posfinx,' fila ',posfiny);
    end;
    until tec = 'N';
      end
   else
      writeln('  Fuera de cordenadas pulse una tecla');
      textmode(origrnmodo);
   end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar

Tablero en pascal !

Publicado por Sabrina (9 intervenciones) el 09/07/2016 21:32:05
Muchisimas gracias Ramon, me podrias explicar igual como fue que razonaste para hacerlo?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
-1
Comentar

Tablero en pascal !

Publicado por ramon (2158 intervenciones) el 10/07/2016 13:28:46
Seria largo explicar como razone para realizar lo pero te diré que la pantalla es fija osea sus posiciones mientras que el robot
cambia de posición por ello el movimiento lo realizo en el array que tiene las mismas dimensiones que la pantalla como
puedes comprobar.
Fíjate que limpio el array para poner las nuevas posiciones del robot, con ello puedo presentar las posiciones nuevas
sin que las otras aparezcan en pantalla.
Los valores se las posiciones las paso a un case y dependiendo del carácter entrado tomara una decisión diferente y
incrementara esa posición o la descremen tara dependiendo del carácter.
Compruebo que no se sale de los limites máximos ni mínimos antes de asignar el valor a las posiciones del robot.
Espero con esto te sirva lo demás repasarlo tu empleando un poquito de lógica.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

Tablero en pascal !

Publicado por Magali (9 intervenciones) el 11/07/2016 15:30:37
yo tengo el mismo problema a realizar, y necesito que SI SE MUESTRE EL RECORRIDO DEL ROBOT !
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
-1
Comentar

Tablero en pascal !

Publicado por ramon (2158 intervenciones) el 11/07/2016 23:42:05
Si se muestra el recorrido del robot en pantalla lo que no quedan registrados son todos los movimientos que este realice.
Pero los puedes guardar en otro array y con ello los tienes pero si muestra los recorridos por el tablero.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de micaela

Tablero en pascal !

Publicado por micaela (1 intervención) el 18/07/2016 22:36:51
Buenas Ramón, tengo un problema, cuando pongo el segundo mando el norte y sur andan mal, se invierten, sabes por que puede ser? besos.
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

Tablero en pascal !

Publicado por ramon (2158 intervenciones) el 19/07/2016 11:17:56
case mando[t] of

'n','N' : y := y + 1;

's','S' : y := y - 1;

'e','E' : x := x + 1;

'o','O' : x := x - 1;

end;

Cambia esto por esto

case mando[t] of

'n','N' : y := y - 1;

's','S' : y := y + 1;

'e','E' : x := x + 1;

'o','O' : x := x - 1;

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

Tablero en pascal !

Publicado por Nahuel (2 intervenciones) el 22/07/2016 01:12:24
Hola Sabrina, no me haces el favor de pasarme como te quedó terminado? Gracias!
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