Ver Mensaje Individual
  #2  
Antiguo 07-06-2012
Avatar de duilioisola
[duilioisola] duilioisola is offline
Miembro Premium
 
Registrado: ago 2007
Ubicación: Barcelona, España
Posts: 1.734
Reputación: 20
duilioisola Es un diamante en brutoduilioisola Es un diamante en brutoduilioisola Es un diamante en bruto
Creo que te falta tener un campo que te diga la dirección en que se está moviendo la pelota.
En tal caso, el incrementeo/decremento de tu posición dependerá de la dirección:
Algo así:

Código Delphi [-]
// valor de direcciones
// 1 2 3
// 4 * 8
// 5 6 7

// inicializo al centro de la pantalla, direccion 5 (derecha, abajo)
col := 40;
lin := 12;
direccion := 5
k := 0;
repeat
   case direccion of
      1 :
      begin
         dec(col);
         dec(lin);
      end
      2 :
      begin
         dec(lin);
      end
      3 :
      begin
         inc(col);
         dec(lin);
      end
      4 :
      begin
         dec(col);
      end
      5 :
      begin
         dec(col);
         inc(lin);
      end
      6 :
      begin
         inc(lin);
      end
      7 :
      begin
         inc(col);
         inc(lin);
      end
      8 :
      begin
         dec(col);
      end
   end // case

   // Ahora me toca ver si me pase de los limites y cambiar la direccion segun corresponda
   // Si voy hacia arriba
   if (direccion >= 1) and (direccion <= 3)
      // y me paso del limite
      if (lin = 0) then
      begin
         direccion := direccion + 4; // 1 --> 5, 2 --> 6, 3 --> 7
         line := 1;
      end;

   // Si voy hacia abajo
   if (direccion >= 5) and (direccion <= 7)
      // y me paso del limite
      if (lin > 25) then
      begin
         direccion := direccion - 4; // 5 --> 1, 6 --> 2, 7 --> 3
         lin := 24;
      end;

   // Si voy a izquierda
   if (direccion = 1) or (direccion = 4) or (direccion = 5)
      // y me paso del limite
      if (col = 0) then
      begin
         case direccion of
            1 : direccion := 3;
            4 : direccion := 8;
            5 : direccion := 7;
         end;
         col := 0;
      end;

   // Si voy a derecha
   if (direccion = 3) or (direccion = 8) or (direccion = 7)
      // y me paso del limite
      if (col = 81) then
      begin
         case direccion of
            3 : direccion := 1;
            8 : direccion := 4;
            7 : direccion := 5;
         end;
         col := 80;
      end;

   clrscr;
   GotoXY(col,lin);
   write('O')
until k = 300;
Responder Con Cita