Pascal/Turbo Pascal - Como mover ficha en juego de tablero

 
Vista:
sin imagen de perfil

Como mover ficha en juego de tablero

Publicado por Jose (1 intervención) el 14/11/2014 16:48:57
Buenas tengo que hacer un juego de tablero y tengo una duda, para hacer el tablero me he basado en el código que encontré en este foro:

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
uses crt;
 
var
 
   i, j, k :   integer;
         c :   char;
 
begin
 
   c := #219;
   write(' ---------------- ');
   for i := 1 to 8 do begin
   writeln;
      if (i mod 2 <> 0) then
         for j := 1 to 4 do begin
            if (j = 1) then write('|');
            write(c, c, '  ');
            if (j = 4) then write('|');
         end
      else begin
         for k := 1 to 4 do begin
            if (k = 1) then write('|');
            write('  ', c, c);
            if (k = 4) then write('|');
         end;
      end;
   end;
   writeln;
   write(' ---------------- ');
   readkey;
end.

este código genera un tablero de damas de 8x8 en el que tanto las casillas negras como las blancas están formadas por caracteres (espacios para las negras y c para las blancas), mi duda es que no se como hacer para situar por ejemplo un caracter "Z" en la casilla inferior izquierda del tablero y poder moverlo a la siguiente casilla negra en diagonal (moverlo desde la posición origen a su casilla superior derecha) pulsando w.

Espero que puedan ayudarme con el problema, muchisimas gracias
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
sin imagen de perfil

Como mover ficha en juego de tablero

Publicado por DAVID (224 intervenciones) el 15/11/2014 18:35:27
Te dejo aquí una pequeña ayuda para que puedas seguir avanzando:

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
program ajedrez;
uses crt;
 
var
 
   i, j, k :   integer;
         c :   char;
  tecla: char;
 
begin
   clrscr;
   c := #219;
   write(' ---------------- ');
   for i := 1 to 8 do begin
   writeln;
      if (i mod 2 <> 0) then
         for j := 1 to 4 do begin
            if (j = 1) then write('|');
            write(c, c, '  ');
            if (j = 4) then write('|');
         end
      else begin
         for k := 1 to 4 do begin
            if (k = 1) then write('|');
            write('  ', c, c);
            if (k = 4) then
              write('|');
         end;
      end;
   end;
   writeln;
   write(' ---------------- ');
  gotoxy(2,9); write('P');
  repeat
    tecla:=readkey;
    case tecla of
      #72 : {tecla flecha arriba} 
        begin
              gotoxy(2,9); Write(' ');
              gotoxy(4,8); write('P');
            end;           end;
  Until tecla = #27; {tecla escape}
 
   readkey;
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

Como mover ficha en juego de tablero

Publicado por ramon (2158 intervenciones) el 16/11/2014 00:26:25
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
{A ver si este ejemplo  te sirve }
 
program damas;
  uses
    crt;
  const
     xini = (80 div 2) - 8;
     yini = (24 div 2) - 8;
     xmax = (xini + (8 * 2));
     ymax = (yini + (8 * 2));
  var
    pc1, pc2, x, y, i, t, p, n, m : integer;
    colores : array[1..8,1..8] of integer;
    trd : char;
 
 
  procedure tablero(xt, yt : integer);
  begin
     textcolor(15);
     textbackground(1);
         gotoxy(xt,yt);write('ÚÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ¿');
     gotoxy(xt,yt + 1);write('³ ³ ³ ³ ³ ³ ³ ³ ³');
     gotoxy(xt,yt + 2);write('ÃÄÅÄÅÄÅÄÅÄÅÄÅÄÅÄ´');
     gotoxy(xt,yt + 3);write('³ ³ ³ ³ ³ ³ ³ ³ ³');
     gotoxy(xt,yt + 4);write('ÃÄÅÄÅÄÅÄÅÄÅÄÅÄÅÄ´');
     gotoxy(xt,yt + 5);write('³ ³ ³ ³ ³ ³ ³ ³ ³');
     gotoxy(xt,yt + 6);write('ÃÄÅÄÅÄÅÄÅÄÅÄÅÄÅÄ´');
     gotoxy(xt,yt + 7);write('³ ³ ³ ³ ³ ³ ³ ³ ³');
     gotoxy(xt,yt + 8);write('ÃÄÅÄÅÄÅÄÅÄÅÄÅÄÅÄ´');
     gotoxy(xt,yt + 9);write('³ ³ ³ ³ ³ ³ ³ ³ ³');
    gotoxy(xt,yt + 10);write('ÃÄÅÄÅÄÅÄÅÄÅÄÅÄÅÄ´');
    gotoxy(xt,yt + 11);write('³ ³ ³ ³ ³ ³ ³ ³ ³');
    gotoxy(xt,yt + 12);write('ÃÄÅÄÅÄÅÄÅÄÅÄÅÄÅÄ´');
    gotoxy(xt,yt + 13);write('³ ³ ³ ³ ³ ³ ³ ³ ³');
    gotoxy(xt,yt + 14);write('ÃÄÅÄÅÄÅÄÅÄÅÄÅÄÅÄ´');
    gotoxy(xt,yt + 15);write('³ ³ ³ ³ ³ ³ ³ ³ ³');
    gotoxy(xt,yt + 16);write('ÀÄÁÄÁÄÁÄÁÄÁÄÁÄÁÄÙ');
    i := 0;
    t := 0;
    p := 0;
    m := 1;
    n := 1;
  repeat
   repeat
     if p mod 2 = 0 then
     begin
     colores[m,n] := 0;
     textcolor(colores[m,n]);
     m := m + 1;
     gotoxy(xt + (1 + i),yt + (t + 1));write('Û');
     colores[m,n] := 15;
     textcolor(colores[m,n]);
     m := m + 1;
     gotoxy(xt + (3 + i),yt + (t + 1));write('Û');
     end
  else
     begin
       colores[m,n] := 15;
       textcolor(colores[m,n]);
       m := m + 1;
       gotoxy(xt + (1 + i),yt + (t + 1));write('Û');
       colores[m,n] := 0;
       textcolor(colores[m,n]);
       m := m + 1;
       gotoxy(xt + (3 + i),yt + (t + 1));write('Û');
     end;
     i := i + 4;
   until i > 15;
   t := t + 2;
   i := 0;
   p := p + 1;
   m := 1;
   n := n + 1;
  until t > 15;
   textcolor(15);
  end;
 
  procedure ponfichas(xf, yf : integer);
  begin
      if colores[pc1,pc2] = 0 then
      begin
      textcolor(15);
      textbackground(0);
      end
   else
      textcolor(0);
      textbackground(15);
      gotoxy(xf, yf);write(chr(1));
      textbackground(0);
      textcolor(15);
  end;
 
  procedure dejacomoestava(x1,y1,c1,c2 : integer);
  begin
     if colores[c1,c2] = 15 then
     begin
        textcolor(15);
        gotoxy(x1,y1);write('Û');
     end
   else
      begin
         textcolor(0);
         gotoxy(x1,y1);write('Û');
      end;
  end;
 
  procedure mueve(var p1, p2, xl, yl : integer);
  var
     tecla : char;
  begin
      repeat
          tecla := readkey;
      until tecla in[#72,#80,#75,#77];
     case tecla of
  #72 : begin
          dejacomoestava(xl,yl,p1,p2);
          yl := yl - 2;
          if yl < yini then
          yl := yini + 1;
          pc2 := pc2 - 1;
          if pc2 < 1 then
          pc2 := 1;
        end;
  #80 : begin
          dejacomoestava(xl,yl,p1,p2);
          yl := yl + 2;
          if yl > ymax then
          yl := ymax - 1;
          pc2 := pc2 + 1;
          if pc2 > 8 then
          pc2 := 8;
        end;
  #75 : begin
          dejacomoestava(xl,yl,p1,p2);
          xl := xl - 2;
          if xl < xini then
          xl := xini + 1;
          pc1 := pc1 - 1;
          if pc1 < 1 then
          pc1 := 1;
        end;
  #77 : begin
           dejacomoestava(xl,yl,p1,p2);
           xl := xl + 2;
           if xl > xmax then
           xl := xmax - 1;
           pc1 := pc1 + 1;
           if pc1 > 8 then
           pc1 := 8;
        end;
     end;
       p1 := pc1;
       p2 := pc2;
  end;
 
  procedure iniciapartida;
  begin
     textbackground(0);
     textcolor(15);
     clrscr;
     tablero(xini,yini);
     x := xini + 1;
     y := yini + 1;
     pc1 := (x - xini);
     pc2 := (y - yini);
     ponfichas(x,y);
     gotoxy(10,ymax + 3);write('Termina Y sale Tecla [ESC] Mueven Flechas[ ',
     chr(24),chr(26),chr(27),chr(25),' ]');
  end;
 
   begin
    iniciapartida;
    repeat
       trd := readkey;
       if trd <> #27 then
       begin
       mueve(pc1,pc2,x,y);
       ponfichas(x,y);
       end;
    until trd = #27;
   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