Dev - C++ - Nesecito convertir de codigo Pascal a C++

 
Vista:

Nesecito convertir de codigo Pascal a C++

Publicado por Fabricio (1 intervención) el 21/07/2015 09:54:34
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
uses graph, crt;
  (* Cambiar por "uses wincrt, ..." bajo Windows *)
 
const
 
  (* Posiciones X e Y iniciales de ambos jugadores *)
  POS_X_INI_1 = 150;
  POS_X_INI_2 = 170;
  POS_Y_INI_1 = 100;
  POS_Y_INI_2 = 100;
 
  INC_X_INI_1 = -1;
  INC_X_INI_2 =  1;
  INC_Y_INI_1 =  0;
  INC_Y_INI_2 =  0;
 
  (* Pausa en milisegundos entre un "fotograma" y otro *)
  PAUSA = 150;
 
  (* Teclas predefinidas para cada jugador *)
  TEC_ARRIBA_1 = 'E';
  TEC_ABAJO_1  = 'X';
  TEC_IZQDA_1  = 'S';
  TEC_DCHA_1   = 'D';
 
  TEC_ARRIBA_2 = '8';
  TEC_ABAJO_2  = '2';
  TEC_IZQDA_2  = '4';
  TEC_DCHA_2   = '6';
 
 
var
  posX1, posY1, posX2, posY2: integer;  (* Posiciones actuales *)
  incX1, incY1, incX2, incY2: integer;  (* Incremento de la posicion *)
  futX1, futY1, futX2, futY2: integer;  (* Posiciones futuras *)
 
  (* Si ha chocado alguna moto *)
  chocado: boolean;
 
  (* La tecla pulsada *)
  tecla:char;
 
 
 
var
  gd,gm, error : integer;
 
 
begin
  gd := D8bit;
  gm := m320x200;
  (* Si falla bajo Windows, probar gd:=0; gm:=0; *)
  initgraph(gd, gm, '');
 
                               (* Intentamos entrar a modo grafico *)
  error := graphResult;
  if error <> grOk then
    begin
    writeLn('No se pudo entrar a modo grafico');
    writeLn('Error encontrado: '+ graphErrorMsg(error) );
    halt(1);
    end;
 
                                (* Si todo ha ido bien: empezamos *)
 
            (* Rectangulo amarillo alrededor *)
  setcolor(14);
  rectangle(0,0, 319, 199);
 
 
            (* Valores iniciales *)
  posX1 := POS_X_INI_1;
  posX2 := POS_X_INI_2;
  posY1 := POS_Y_INI_1;
  posY2 := POS_Y_INI_2;
 
  incX1 := INC_X_INI_1;
  incX2 := INC_X_INI_2;
  incY1 := INC_Y_INI_1;
  incY2 := INC_Y_INI_2;
 
 
            (* Parte repetitiva: *)
  repeat
    chocado := FALSE;
 
    (* Compruebo si alguna va a colisionar *)
    futX1 := posX1 + incX1;
    futX2 := posX2 + incX2;
    futY1 := posY1 + incY1;
    futY2 := posY2 + incY2;
 
    if (getpixel(futX1, futY1) <> 0) then
      begin
      SetColor(13);
      OutTextXY( 100, 90,
        'La moto 1 ha chocado!');
      chocado := TRUE;
      end;
 
 
    if (getpixel(futX2, futY2) <> 0) then
      begin
      SetColor(12);
      OutTextXY( 100, 110,
        'La moto 2 ha chocado!');
      chocado := TRUE;
      end;
 
    if chocado then break;
 
 
 
    (* Si ninguna ha colisionado, avanzan *)
    setColor(13);
    line (posX1, posY1, futX1, futY1);
    posX1 := futX1;  posY1 := futY1;
 
    setColor(12);
    line (posX2, posY2, futX2, futY2);
    posX2 := futX2;  posY2 := futY2;
 
 
    (* Compruebo si se ha pulsado alguna tecla *)
    if  keypressed then
        begin
        tecla := upcase(readkey);
 
        case tecla of
          TEC_ARRIBA_1:
            begin incX1 :=  0; incY1 := -1;  end;
          TEC_ABAJO_1:
            begin incX1 :=  0; incY1 :=  1;  end;
          TEC_IZQDA_1:
            begin incX1 := -1; incY1 :=  0;  end;
          TEC_DCHA_1:
            begin incX1 :=  1; incY1 :=  0;  end;
 
          TEC_ARRIBA_2:
            begin incX2 :=  0; incY2 := -1;  end;
          TEC_ABAJO_2:
            begin incX2 :=  0; incY2 :=  1;  end;
          TEC_IZQDA_2:
            begin incX2 := -1; incY2 :=  0;  end;
          TEC_DCHA_2:
            begin incX2 :=  1; incY2 :=  0;  end;
  end;
    end;
 
    (* Pequea pausa antes de seguir *)
    delay ( PAUSA );
 
  until FALSE;   (* Repetimos indefininamente *)
                 (* (la condicin de salida la comprobamos "dentro") *)
 
  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

Nesecito convertir de codigo Pascal a C++

Publicado por José Luis (4 intervenciones) el 08/08/2015 00:00:11
Cambia las parejas begin-end por { }
Cambia el case por una instrucción switch
Cambia los writeln por printf
Encierra las condiciones de los if entre paréntesis


Y además, ten en cuenta que la palabra "nesecito" no existe en español, se dice "necesito", que viene de "necesidad" (porque "nesesidad" tampoco existe).
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