domingo, 18 de marzo de 2012

Hacemos proyectos en Adagraph, Juegos y Proyectos de Progra

Contactanos en Cochabamba Bolivia al telefono 76404338.
Proyectos de la universidad, para programación,usando Ada, Adagraph y otros lenguajes de programación.
Te salvamos y colaboramos de una buena manera, no dudes en pedir ayuda.

lunes, 29 de agosto de 2011

Primitivas para la manipulacion de Estructuras Dinamicas - Cadenas



 -- Primitivas para la  manipulacion de Estructuras Dinamicas utilizando de ejemplo el tipo de dato cajero:

type T_Cajero;
   type Ptr_Cajero is access T_Cajero;
   type T_Cajero is
      record
         Codigo_Cajero     : Integer          := 0; 
         Nombre            : String (1 .. 30) := (others => ' '); 
         Tam_Nombre        : Natural:=0;           
         Apellido          : String(1..30):=(OTHERS=> ' ');
         Tam_Apellido      : Natural:=0;
         Carnet            : String(1..30):=(OTHERS=> ' ');
         Tam_Carnet        : Natural:=0;
       Telefono          : String(1..30):=(OTHERS=> ' ');
         Tam_Telefono      : Natural:=0;
       Email             : String(1..30):=(OTHERS=> ' ');
         Tam_Email       : Natural:=0;
       Codigo_Horario    : Integer:= 0; 
         Siguiente         : Ptr_Cajero   := null;
      end record;
------------------------------------------

   procedure Insertar_Inicio (
         Cad_Cajero : in out Ptr_Cajero;
         Elem           : in out Ptr_Cajero  )IS
   BEGIN
      IF (Elem = NULL)
            THEN
         PUT_LINE("Error al Insertar Inicio: No hay nada q insertar");
      ELSE
         Elem.All.Siguiente := Cad_Cajero;
         Cad_Cajero := Elem;
         Elem :=NULL;
      END IF;
      RETURN;
   END Insertar_Inicio ;


   procedure Insertar_Final (
         Cad_Cajero : in out Ptr_Cajero;
         Elem           : in out Ptr_Cajero  )IS
   Tmp : Ptr_Cajero := null;
   BEGIN
      IF (Elem = NULL)
            THEN
      PUT_LINE("Error al Insertar al Final: No hay nada q insertar");
      RETURN;
      END IF;

      IF (Cad_Cajero = NULL)
            THEN
         Cad_Cajero := Elem;
      ELSE
         Tmp := Cad_Cajero;
         LOOP
            EXIT WHEN Tmp.All.Siguiente =NULL;
            Tmp := Tmp.All.Siguiente;
         END LOOP;
         Tmp.all.Siguiente := Elem;
      END IF;
      Elem :=NULL;
      RETURN;
   END Insertar_Final ;


   procedure Eliminar_Inicio (
         Cad_Cajero : in out Ptr_Cajero;
         Elem           : in out Ptr_Cajero  )IS
   BEGIN
      IF (Cad_Cajero = NULL)
            THEN
            PUT_LINE("Hostias! La cadena esta vacia!");
         RETURN;
      END IF;
      Elem := Cad_Cajero;
      Cad_Cajero := Cad_Cajero.All.Siguiente;
      Elem.All.Siguiente :=NULL;
      RETURN;
   END Eliminar_Inicio ;


   procedure Eliminar_Final (
         Cad_Cajero : in out Ptr_Cajero;
         Elem           : in out Ptr_Cajero  )IS
   Tmp: Ptr_Cajero;
   BEGIN
   IF (Cad_Cajero = NULL)
            THEN
            raise  Cadena_Vacia ;
        RETURN;
   END IF;

   IF (Cad_Cajero.All.Siguiente = NULL)
            THEN
         Elem := Cad_Cajero;
         Cad_Cajero := NULL;
         RETURN;
   END IF;
      Tmp:=Cad_Cajero;
      LOOP
      -- Nos detenemos en el penultimo elemento
         EXIT WHEN Tmp.All.Siguiente.All.Siguiente = NULL;
         Tmp:= Tmp.All.Siguiente;
      END LOOP;
      Elem := Tmp.All.Siguiente;
      Tmp.All.Siguiente :=NULL;
      RETURN;
   END Eliminar_Final ;


   procedure Recorrer (
         Cad_Cajero : in     Ptr_Cajero )IS
   Tmp: Ptr_Cajero := null;
   BEGIN
      IF ( Cad_Cajero = NULL)
            THEN
         raise  Cadena_Vacia ;
         RETURN;
      END IF;
     
      Tmp:=  Cad_Cajero ;
      LOOP
         EXIT WHEN Tmp=NULL;
         Mostrar_Cajero(Tmp.All);
         Tmp := Tmp.All.Siguiente;
      END LOOP;
      RETURN;
   END Recorrer ;


   procedure Buscar_Codigo (
         Cad_Cajero : in     Ptr_Cajero;
         Codigo         : in     Integer;       
         Elem           :    out Ptr_Cajero  )IS

    Tmp : Ptr_Cajero := null; 
    begin
      if (Cad_Cajero=null) then
         raise  Cadena_Vacia ;
      else
         Tmp:=Cad_Cajero;
         loop
            exit when Tmp=null;
            exit when Tmp.All.Codigo_Cajero = Codigo;
            Tmp:=Tmp.All.Siguiente;
         end loop;
         if (Tmp=null) then
              raise Elemento_No_Encontrado;
         else
            Elem:=Tmp;
         end if;
      end if;

   END Buscar_Codigo ;

Ada- Accediendo a archivos secuenciales

  -- Primitivas para la manipulacion de Archivos secuenciales

   procedure Leer_TipoDeDato (
         Cad_TipoDeDato : in out Ptr_TipoDeDato )IS
 
      File : TipoDeDato_Seq.File_Type; 
      Tmp : Ptr_TipoDeDato          := null; 
   begin

      begin
         Open(
            File => File,           
            Mode => In_File,        
            Name => "LasAxilasSonDeliciosas.sec"
            );

      exception
         when Ada.Io_Exceptions.Name_Error =>
            Put_Line("FELICIDADES QUERIDO USUARIO ! ACABA DE INICIALIZAR EL PROGRAMA");
            return;
      end;

      loop
         exit when End_Of_File(File => File);
         Tmp:=new T_TipoDeDato;
         Read(File, Tmp.All);
         Tmp.All.Siguiente:=null;
         Insertar_Final(Cad_TipoDeDato,Tmp);
      end loop;
      Close(File => File);
   END Leer_TipoDeDato ;


   procedure Guardar_TipoDeDato (
         Cad_TipoDeDato : in     Ptr_TipoDeDato )IS
    File : TipoDeDato_Seq.File_Type; 
    Tmp  : Ptr_TipoDeDato; 
   begin
      Tmp:=Cad_TipoDeDato; --cabeza
      Create(File, Out_File,"LasAxilasSonDeliciosas.sec");
      loop
         exit when Tmp=null;
         Write (File,Tmp.All);
         Tmp:=Tmp.All.Siguiente;
      end loop;
      Close(File => File);
  
   END Guardar_TipoDeDato ;
 

sábado, 30 de abril de 2011

Juego del Avioncito Matador

 -------------------------------
--Juego del Avioncito Matador--
-------------------------------
--Posterior a la Segunda Guerra Mundial, los judios, aprovechando
--que Hitler esta muerto, vuelven a fortalecerse y armarse.
--Usted como buen nazi, debera darles su merecido y evitar que se multipliquen
--atacando a los inocentes hogares de Alemania.



with Adagraph;
use Adagraph;
with Ada.Numerics.Discrete_Random;
use Ada.Numerics;

-------------------------------
--Juego del Avioncito Matador--
-------------------------------
--Posterior a la Segunda Guerra Mundial, los judios, aprovechando
--que Hitler esta muerto, vuelven a fortalecerse y armarse.
--Usted como buen nazi, debera darles su merecido y evitar que se multipliquen
--atacando a los inocentes hogares de Alemania.

--Mover con Left, Right, disparar con letra ´n´.

procedure Avioncitomatador is

   X_Max, 
   Y_Max : Integer := 0; 

   X_Char, 
   Y_Char : Integer := 0; 

   Tecla                : Character;
   Dir                  : Character           := Vk_Left; 
   Nrovidas             : Integer             := 3; 
   NroMatanzas          : Integer             := 0;
   NroCaidas            : Integer             := 0;
   Nivel                : Integer             := 1;
     
   X_Avioncito, 
   Y_Avioncito : Integer := 40  ;

  
   X_Bicho1 : Integer := 40; 
   Y_Bicho1 : Integer := 1030; 

   X_Bicho2 : Integer := 70; 
   Y_Bicho2 : Integer := 1010; 

   X_Bicho3 : Integer := 20; 
   Y_Bicho3 : Integer := 1010; 

   X_Bicho4 : Integer := 45; 
   Y_Bicho4 : Integer := 1010; 

   X_Bicho5 : Integer := 330; 
   Y_Bicho5 : Integer := 1010; 

  
-- Setea el valor de nivel de dificultad, nro de matanzas necesarias para ganar
   Nivel_de_Dificultad : Integer := 10;
 
   MetralletaVisible  : Boolean := False; 

   Gano  : Boolean := False; 
   Salir : Boolean := False;
  
   SalirCualquierMomento : Boolean := False;

   procedure Ventana is
   begin
      Get_Max_Size(X_Max, Y_Max);
      Create_Graph_Window(
         X_Max  ,
         Y_Max ,
         X_Char  ,
         Y_Char );

   end Ventana ;

   procedure Dibujar_Edificios is
   begin
      Draw_Box(0, 0, 40, 35 , White,True);
      Draw_Box(40, 0, 75, 55 , Red,True);
      Draw_Box(75, 0, 90, 70 , Green,True);
      Draw_Box(90, 0, 240, 55 , White,True);

      Draw_Box(130, 30, 190, 35 , Red,True);
     
      Draw_Box(130, 30, 135, 50 , Red,True);
      Draw_Box(185, 30, 190, 10 , Red,True);

      Draw_Box(155, 10, 160, 50 , Red,True);
      Draw_Box(155, 10, 135, 15 , Red,True);
      Draw_Box(155, 50, 190, 45 , Red,True);


      Draw_Box(240, 0, 300, 20 , Blue,True);
      Draw_Box(300, 0, 340, 45 , Yellow,True);
      Draw_Box(340, 0, 440, 20 , Light_Blue,True);
      Draw_Box(440, 0, 467, 36 , Red,True);
      Draw_Box(467, 0, 600, 44 , Magenta,True);
      Draw_Box(600, 0, 640, 58 , Green,True);
      Draw_Box(640, 0, 670, 39 , Brown,True);
      Draw_Box(670, 0, 800, 60 , Light_Gray,True);
     
     
   end  Dibujar_Edificios;

   procedure Inicializar is
   begin
      Ventana;
      X_Avioncito:=30;
      Y_Avioncito:=80;
   Dibujar_Edificios;
   end Inicializar;


   function Generar_Numero_Aleatorio (
         Minvalue : Integer;
         Maxvalue : Integer  )
     return Integer is
      subtype Random_Type is Integer range Minvalue .. Maxvalue;
      package Random_Pack is new Ada.Numerics.Discrete_Random (
         Random_Type);
      G : Random_Pack.Generator; 
   begin
      Random_Pack.Reset (G);
      return Random_Pack.Random (G);

   end Generar_Numero_Aleatorio;



   procedure Mostrar_Cuadro is
   begin

      if (Gano=True) then
         Draw_Box((X_Max/2)-150,(Y_Max/2)+80,(X_Max/2)+150,(Y_Max/2)-80,
            Blue,True);
         Display_Text((X_Max/2)-(X_Char*6)-80,(Y_Max/2)+(Y_Char*3),
            "OH SI!! GANASTE MATADOR!!!",Yellow);
         Display_Text((X_Max/2)-(X_Char*6)-107,(Y_Max/2)+(Y_Char*3) - 20,
            "  LOGRASTE MATAR A TODOS ESOS JUDIOS!",Yellow);
         Display_Text((X_Max/2)-(X_Char*15),(Y_Max/2)-Y_Char,
            "PRESIONA TECLA 's' PARA SALIR",Yellow);
      end if;

      if (Gano=False) then
         Draw_Box((X_Max/2)-150,(Y_Max/2)+80,(X_Max/2)+150,(Y_Max/2)-80,
            White,True);
         Display_Text((X_Max/2)-(X_Char*6)-70,(Y_Max/2)+(Y_Char*3),
            "DIOS SANTO! PERDISTE AVIONCITO!!!",Red);
         if (NroVidas = 0) then
         Display_Text((X_Max/2)-(X_Char*6)-80,(Y_Max/2)+(Y_Char*3) - 20,
            "  TE MATARON POR COBARDE!!",Red);
         end if;
       
        if (NroVidas > 0) then
         Display_Text((X_Max/2)-(X_Char*6)-110,(Y_Max/2)+(Y_Char*3) - 20,
            " DESTRUYERON LOS HOGARES DE TU CIUDAD!",Red);
         end if;
     
           Display_Text((X_Max/2)-(X_Char*15) -20,(Y_Max/2)-Y_Char,
            "PRESIONA TECLA 's'  PARA SALIR",Red);
      end if;

   end Mostrar_Cuadro;

 procedure ReiniciarEnemigo1  is
    begin
     Draw_Box(0, 80, 1200, 900, Black, True);
     X_Bicho1 := Generar_Numero_Aleatorio (
         Minvalue => 5, 
         Maxvalue => 200);
     Y_Bicho1 := 600;
   end ReiniciarEnemigo1;

procedure ReiniciarEnemigo2  is
    begin
     Draw_Box(0, 80, 1200, 900, Black, True);
     X_Bicho2 := Generar_Numero_Aleatorio (
         Minvalue => 4, 
         Maxvalue => 200);
       Y_Bicho2 := 800;
   end ReiniciarEnemigo2;

procedure ReiniciarEnemigo3  is
    begin
     Draw_Box(0, 80, 1200, 900, Black, True);
     X_Bicho3 := Generar_Numero_Aleatorio (
         Minvalue => 20,
         Maxvalue => 200);
     Y_Bicho3 := 1000;
     
    end Reiniciarenemigo3;
   
procedure ReiniciarEnemigo4  is
    begin
     Draw_Box(0, 80, 1200, 900, Black, True);
      X_Bicho4 := Generar_Numero_Aleatorio (
         Minvalue => 10,
         Maxvalue => 200);
      Y_Bicho4 := 750;
    
    end Reiniciarenemigo4;
   
procedure ReiniciarEnemigo5  is
    begin
    Draw_Box(0, 80, 1200, 900, Black, True);
    X_Bicho5 := Generar_Numero_Aleatorio (
         Minvalue => 50,
         Maxvalue => 200);

      Y_Bicho5 := 1300;
   end ReiniciarEnemigo5;



   procedure Dibujar_Vidas is
   begin
     Display_Text(450,400,"Numero de Vidas: " & Integer'Image(Nrovidas) ,
         Green);
   end  Dibujar_Vidas;
  
   procedure Dibujar_Nivel is
   begin
     Display_Text(450,420,"Nivel: " & Integer'Image(Nivel) ,
         Green);
   end  Dibujar_Nivel;



   procedure Dibujar_Matanzas is
   begin
     Display_Text(450,380,"Numero de enemigos matados: " & Integer'Image(NroMatanzas) ,
         Cyan);
   end  Dibujar_Matanzas;
  
   procedure Dibujar_Caidas is
   begin
     Display_Text(450,360,"Tus hogares destruidos ;( : " & Integer'Image(Nrocaidas) ,
         Light_Blue);
   end  Dibujar_Caidas;


 procedure Mato_Enemigo is
 begin
 NroMatanzas := NroMatanzas +1;
 if (NroMatanzas = Nivel_de_Dificultad) then
            Gano:=True;
            Salir:=True;
         end if;
 end  Mato_Enemigo;


   procedure Dibujaravion (
         Colorusado : in     Extended_Color_Type ) is
   begin
      Draw_Line(X_Avioncito , Y_Avioncito, X_Avioncito+30, Y_Avioncito, Colorusado , True);
      Draw_Line(X_Avioncito +30 , Y_Avioncito, X_Avioncito+15, Y_Avioncito + 20, Colorusado , True);
      Draw_Line(X_Avioncito , Y_Avioncito, X_Avioncito+15, Y_Avioncito +20, Colorusado , True);
      Draw_Circle(X_Avioncito + 15 , Y_Avioncito+8, 5, Colorusado , True);
      Draw_Box(X_Avioncito + 12 , Y_Avioncito,X_Avioncito + 18 ,Y_Avioncito-5, Colorusado , True);
     
        
      if (MetralletaVisible  = True) then
         Draw_Box(X_Avioncito + 15 , Y_Avioncito +21, X_Avioncito+15 + 5, 600, Cyan , True);
         if (X_Avioncito + 15 >= X_Bicho1 and X_Avioncito+15 + 5 <= X_Bicho1 +30 ) then ReiniciarEnemigo1; Mato_Enemigo; end if;         
         if (X_Avioncito + 15 >= X_Bicho2-10 and X_Avioncito+15 + 5 <= X_Bicho2 +10 ) then ReiniciarEnemigo2; Mato_Enemigo; end if;          
         if (X_Avioncito + 15 >= X_Bicho3-10 and X_Avioncito+15 + 5 <= X_Bicho3 +10 ) then ReiniciarEnemigo3; Mato_Enemigo; end if;         
         if (X_Avioncito >= X_Bicho4-15 and X_Avioncito + 15 <= X_Bicho4 +15 ) then ReiniciarEnemigo4; Mato_Enemigo; end if;         
         if (X_Avioncito + 15  >= X_Bicho5-10 and X_Avioncito + 15 + 5 <= X_Bicho5 +10 ) then ReiniciarEnemigo5; Mato_Enemigo; end if;         
        
         MetralletaVisible  := False;
      end if;
        
   end Dibujaravion;


   procedure DibujarEnemigo1 (
         Colorusado : in     Extended_Color_Type ) is
   begin
      Draw_Line(X_Bicho1 , Y_Bicho1, X_Bicho1+30, Y_Bicho1, Colorusado , True);
      Draw_Line(X_Bicho1 +30 , Y_Bicho1, X_Bicho1+15, Y_Bicho1 - 20, Colorusado , True);
      Draw_Line(X_Bicho1 , Y_Bicho1, X_Bicho1+15, Y_Bicho1 -20, Colorusado , True);
      Draw_Circle(X_Bicho1 + 15 , Y_Bicho1+8, 5, Colorusado , True);
      Draw_Box(X_Bicho1 + 12 , Y_Bicho1,X_Bicho1 + 18 ,Y_Bicho1-5, Colorusado , True);
  
      Draw_Circle(X_Bicho1 + 15  , Y_Bicho1, 5, White , True);
   end DibujarEnemigo1;
  

   procedure DibujarEnemigo2 (
         Colorusado1 : in     Extended_Color_Type; Colorusado2 : in     Extended_Color_Type ) is
   begin
      Draw_Circle(X_Bicho2, Y_Bicho2, 10,Colorusado1 ,True);
      Draw_Circle(X_Bicho2 -5, Y_Bicho2, 2,Colorusado2 ,True);
      Draw_Circle(X_Bicho2+5, Y_Bicho2, 2,Colorusado2 ,True);
      Draw_Box(X_Bicho2-2, Y_Bicho2-5, X_Bicho2+2, Y_Bicho2-3 , Colorusado2 ,True);
   end DibujarEnemigo2;

  procedure DibujarEnemigo3 (
         Colorusado1 : in     Extended_Color_Type; Colorusado2 : in     Extended_Color_Type ) is
   begin
      Draw_Circle(X_Bicho3, Y_Bicho3, 10,Colorusado1 ,True);
      Draw_Circle(X_Bicho3 -5, Y_Bicho3, 2,Colorusado2 ,True);
      Draw_Circle(X_Bicho3+5, Y_Bicho3, 2,Colorusado2 ,True);
      Draw_Box(X_Bicho3-2, Y_Bicho3-5, X_Bicho3+2, Y_Bicho3-3 , Colorusado2 ,True);
   end DibujarEnemigo3;

  procedure DibujarEnemigo4 (
         Colorusado1 : in     Extended_Color_Type; Colorusado2 : in     Extended_Color_Type ) is
   begin
      Draw_Box(X_Bicho4, Y_Bicho4, X_Bicho4 + 10, Y_Bicho4 + 10, Colorusado1 ,True);
      Draw_Circle(X_Bicho4 +2, Y_Bicho4, 2,Colorusado2 ,True);
      Draw_Circle(X_Bicho4+ 5, Y_Bicho4, 2,Colorusado2 ,True);
      Draw_Box(X_Bicho4+2, Y_Bicho4-5, X_Bicho4+6, Y_Bicho4-3 , Colorusado2 ,True);
   end DibujarEnemigo4;

  procedure DibujarEnemigo5 (
         Colorusado1 : in     Extended_Color_Type; Colorusado2 : in     Extended_Color_Type ) is
   begin
      Draw_Circle(X_Bicho5, Y_Bicho5, 10,Colorusado1 ,True);
      Draw_Circle(X_Bicho5 -5, Y_Bicho5, 2,Colorusado2 ,True);
      Draw_Circle(X_Bicho5+5, Y_Bicho5, 2,Colorusado2 ,True);
      Draw_Box(X_Bicho5-2, Y_Bicho5-5, X_Bicho5+2, Y_Bicho5-3 , Colorusado2 ,True);
   end DibujarEnemigo5;


procedure Reiniciarenemigos is
begin
   Clear_Window(Hue => Black);
   Dibujar_Edificios;
  
   ReiniciarEnemigo1; 
   ReiniciarEnemigo2; 
   ReiniciarEnemigo3; 
   ReiniciarEnemigo4; 
   ReiniciarEnemigo5; 
    
   end Reiniciarenemigos;


   procedure Dibujarnave (
         Tecla : in     Character ) is
   begin

      Dibujaravion(Black);
      Draw_Line(X_Avioncito + 15 , Y_Avioncito +21, X_Avioncito+15, 400, Black , True);
     
      if Tecla =Vk_Right then
         X_Avioncito:=X_Avioncito+10;
      end if;
      if Tecla =Vk_Left then
         X_Avioncito:=X_Avioncito-10;
      end if;
       if Tecla ='n' then
         MetralletaVisible:=True;
      end if;


      Dibujaravion(Yellow);

      if (X_Avioncito+10>=X_Bicho1 and X_Avioncito+10<=(X_Bicho1+15)  and Y_Avioncito>=
            Y_Bicho1 and Y_Avioncito <= (Y_Bicho1 +15)) then
         Nrovidas := Nrovidas - 1;
         Reiniciarenemigos;
      end if;


      if (X_Avioncito+10>=X_Bicho2 and X_Avioncito+10<=(X_Bicho2+15)  and Y_Avioncito>=
            Y_Bicho2 and Y_Avioncito <= (Y_Bicho2 +15)) then
         Nrovidas := Nrovidas - 1;
         Reiniciarenemigos;
      end if;

      if (X_Avioncito+10>=X_Bicho3 and X_Avioncito+10<=(X_Bicho3+15)  and Y_Avioncito>=
            Y_Bicho3 and Y_Avioncito <= (Y_Bicho3 +15)) then
         Nrovidas := Nrovidas - 1;
         Reiniciarenemigos;
      end if;

      if (X_Avioncito+10>=X_Bicho4 and X_Avioncito+10<=(X_Bicho4+15)  and Y_Avioncito>=
            Y_Bicho4 and Y_Avioncito <= (Y_Bicho4 +15)) then
         Nrovidas := Nrovidas - 1;
         Reiniciarenemigos;
      end if;

      if (X_Avioncito+10>=X_Bicho5 and X_Avioncito+10<=(X_Bicho5+15)  and Y_Avioncito>=
            Y_Bicho5 and Y_Avioncito <= (Y_Bicho5 +15)) then
         Nrovidas := Nrovidas - 1;
         Reiniciarenemigos;
      end if;

      if (Nrovidas=0) then
         Dibujar_Vidas;
         Gano:=False;
         Salir:=True;
      end if;


   end Dibujarnave;


   procedure Dibujarbala is
   begin
      delay(0.01);

      --re pintamos de negro los enemigos para evitar barrido

      Dibujarenemigo1(Black);
      Dibujarenemigo2(Black,Black);
      Dibujarenemigo3(Black,Black);
      Dibujarenemigo4(Black,Black);
      Dibujarenemigo5(Black,Black);
     
      --repintamos la metralleta de negro para ocultarla
      Draw_Box(X_Avioncito + 15 , Y_Avioncito +21, X_Avioncito+15 + 5, 600, Black, True);
       
      -- dibujamos al avioncito matador
      Dibujaravion(Yellow);

    
      if (X_Avioncito > 600) then
         X_Avioncito :=0;
         Reiniciarenemigos;
      
      end if;

      delay(0.01);
      if (Y_Bicho1< 20 ) then
         Y_Bicho1 := 600;
         Nrocaidas := Nrocaidas+1;
         X_Bicho1 := Generar_Numero_Aleatorio (
            Minvalue => 5,
            Maxvalue => 400);
      end if;

      if (Y_Bicho2< 20 ) then
         Y_Bicho2 := 800;
         Nrocaidas := Nrocaidas+1;
         X_Bicho2 := Generar_Numero_Aleatorio (
            Minvalue => 40,
            Maxvalue => 480);
      end if;

      if (Y_Bicho3< 20 ) then
         Y_Bicho3 := 1200;
         Nrocaidas := Nrocaidas+1;
         X_Bicho3 := Generar_Numero_Aleatorio (
            Minvalue => 100,
            Maxvalue => 300);
      end if;

      if (Y_Bicho4< 20 ) then
         Y_Bicho4 := 900;
         Nrocaidas := Nrocaidas+1;
         X_Bicho4 := Generar_Numero_Aleatorio (
            Minvalue => 55,
            Maxvalue => 380);
      end if;

      if (Y_Bicho5< 20 ) then
         Y_Bicho5 := 800;
         Nrocaidas := Nrocaidas+1;
         X_Bicho5 := Generar_Numero_Aleatorio (
            Minvalue => 10,
            Maxvalue => 500);
      end if;
      if (Nrocaidas= 6) then
         Gano:=False;
         Salir:=True;  
      end if;

      Y_Bicho1:= Y_Bicho1 - 5;
      Y_Bicho2:= Y_Bicho2 - 4;
      Y_Bicho3:= Y_Bicho3- 2;
      Y_Bicho4:= Y_Bicho4- 1;
      Y_Bicho5:= Y_Bicho5- 3;

      --dibujamos los enemigos

      Dibujarenemigo1(Light_Red);
      Dibujarenemigo2(Cyan,Red);
      Dibujarenemigo3(Green,Magenta);
      Dibujarenemigo4(Light_Red,White);
      Dibujarenemigo5(Green,Yellow);


   end Dibujarbala;

   procedure JugarNivel1 is
   begin
      Tecla:=Vk_Nul;

      loop
         Dibujarnave(Vk_Nul);
       
         Dibujar_Vidas;
         Dibujar_Matanzas;
         Dibujar_Caidas;    
         Dibujar_Nivel;
        
         Dibujarbala;
         Dibujarnave(Vk_Nul);

         if (Key_Hit) then
            Tecla:=Get_Key;

            if Tecla=Vk_Left or Tecla=Vk_Right  or Tecla='n' then
               Dir:=Tecla;
               Dibujarnave(Dir);
            end if;
      
            if Tecla='q' then
               SalirCualquierMomento:=True;
            end if;
           
        end if;
  
         exit when Salir=True or  SalirCualquierMomento=True;

      end loop;
    
   end JugarNivel1;

procedure JugarNivel2 is
   begin
      Tecla:=Vk_Nul;

      loop
         Dibujarnave(Vk_Nul);
       
         Dibujar_Vidas;
         Dibujar_Matanzas;
         Dibujar_Caidas;    
         Dibujar_Nivel;
        

         Dibujarbala;
         Dibujarnave(Vk_Nul);

         if (Key_Hit) then
            Tecla:=Get_Key;

            if Tecla=Vk_Left or Tecla=Vk_Right  or Tecla='n' then
               Dir:=Tecla;
               Dibujarnave(Dir);
            end if;
           
           if Tecla='q' then
               SalirCualquierMomento:=True;
            end if;


         end if;
  
           

         exit when Salir=True or  SalirCualquierMomento=True;

      end loop;
     
   end JugarNivel2;


procedure JugarNivel3 is
   begin
      Tecla:=Vk_Nul;

      loop
         Dibujarnave(Vk_Nul);
       
         Dibujar_Vidas;
         Dibujar_Matanzas;
         Dibujar_Caidas; 
         Dibujar_Nivel;
        
         Dibujarbala;
         Dibujarnave(Vk_Nul);

         if (Key_Hit) then
            Tecla:=Get_Key;

            if Tecla=Vk_Left or Tecla=Vk_Right  or Tecla='n' then
               Dir:=Tecla;
               Dibujarnave(Dir);
            end if;
   
            if Tecla='q' then
               SalirCualquierMomento:=True;
            end if;
   
        end if;
  
         exit when Salir=True or  SalirCualquierMomento=True;
      end loop;
     
          if (Salir=True) then
            Mostrar_Cuadro;
            end if;
  
   end JugarNivel3;




   procedure Esperartecla is
   begin
      Salir := False;
      loop
         if (Key_Hit) then
           Tecla:=Get_Key;

            if Tecla='s' then
             Salir:=True;
            end if;
         end if;
        
         exit when Salir=True;
      end loop;
   end Esperartecla ;


begin
   Inicializar;
  
   JugarNivel1;
  
   Salir:=False;
   Nivel_De_Dificultad:=20;
   
   NroMatanzas := 0;
   Nivel :=2;
   JugarNivel2;
 
   Salir:=False;
   NroMatanzas := 0;
   Nivel_De_Dificultad:=30;
   Nivel :=3;
   Jugarnivel3;
  
   if (Salir=True) then
   Esperartecla;
   Tecla:= Get_Key;
   end if;
  
-------------------------------
--Juego del Avioncito Matador--
-------------------------------
--Posterior a la Segunda Guerra Mundial, los judios, aprovechando
--que Hitler esta muerto, vuelven a fortalecerse y armarse.
--Usted como buen nazi, debera darles su merecido y evitar que se multipliquen
--atacando a los inocentes hogares de Alemania.

--Mover con Left, Right, disparar con letra ´n´.

end Avioncitomatador ;

Ladrones de Azucar Juego en Adagraph

-- Demonios, existe escasez de azucar en la patria. Usted, un afamado
-- contrabandista, debera robar unos buenos quintales del Peru y meterlos
-- en su auto rojo Formula-1 y escapar a Bolivia, asi sus compatriotas
-- podran endulzar sus tecitos y refrescos hervidos. Animo patriota !!


with Adagraph;
use Adagraph;
with Ada.Numerics.Discrete_Random;
use Ada.Numerics;

-- Demonios, existe escasez de azucar en la patria. Usted, un afamado
-- contrabandista, debera robar unos buenos quintales del Peru y meterlos
-- en su auto rojo Formula-1 y escapar a Bolivia, asi sus compatriotas
-- podran endulzar sus tecitos y refrescos hervidos. Animo patriota !!

procedure ladronesDeAzucar is

   X_Max,
   Y_Max : Integer := 0;

   X_Char,
   Y_Char : Integer := 0;

   Tecla         : Character;
   Dir           : Character := Vk_Left;
   Nrovidas      : Integer   := 3;
   Azucar_Quintales : Integer   := 0;
   ColorCarretera : Extended_Color_Type := Green;
   ColorLineasCarretera : Extended_Color_Type := Yellow;
  
   X_Personaje,
   Y_Personaje : Integer := 1;

   X_Personaje_Estacionado,
   Y_Personaje_Estacionado: Integer := 1;  

   X_Cosa1 : Integer := 40;
   Y_Cosa1 : Integer :=30;
       
   X_Cosa2 : Integer := 70;
   Y_Cosa2 : Integer := 10;

   X_Cosa3 : Integer := 20;
   Y_Cosa3 : Integer := 10;

   X_Cosa4 : Integer := 45;
   Y_Cosa4 : Integer := 10;

   X_Cosa5 : Integer := 30;
   Y_Cosa5 : Integer := 10;

   contadorKM : Integer :=210;
   NivelDelJuego : Integer :=1;

 
   Ganar : Boolean  := False;
   Salir : Boolean  := False;
 
  procedure Ventana is
   begin
      Get_Max_Size(X_Max, Y_Max);
      Create_Graph_Window(
         X_Max  ,
         Y_Max ,
         X_Char  ,
         Y_Char );
    
   end Ventana ;

 procedure Inicializar is
   begin
      Ventana;

      X_Personaje:=30;
      Y_Personaje:=20;

   end Inicializar;

--pagina 172 de Ada_Programming.pdf para generar numeros aleatorios
function Generate_Number (MinValue : Integer;
MaxValue : Integer) return Integer
is
subtype Random_Type is Integer range MinValue .. MaxValue;
package Random_Pack is new Ada.Numerics.Discrete_Random (Random_Type);
G : Random_Pack.Generator;
begin
   Random_Pack.Reset (G);
    return Random_Pack.Random (G);
end Generate_Number;


  procedure Dibujar_Mensaje_Final is
   begin
         
     if (Ganar=True) then
     Draw_Box((X_Max/2)-150,(Y_Max/2)+80,(X_Max/2)+150,(Y_Max/2)-80,Blue,True);
     Display_Text((X_Max/2)-(X_Char*6)-30,(Y_Max/2)+(Y_Char*3),"JOJOJO!! GANASTE!!!",Yellow);
     Display_Text((X_Max/2)-(X_Char*6)-70,(Y_Max/2)+(Y_Char*3) - 20,"LOGRASTE CONTRABANDEAR LA AZUCAR!!",Yellow);
     Display_Text((X_Max/2)-(X_Char*15),(Y_Max/2)-Y_Char,"APRETA LA TECLA 'q' PARA SALIR",Yellow);
     end if;
    
     if (Ganar=False) then
     Draw_Box((X_Max/2)-150,(Y_Max/2)+80,(X_Max/2)+150,(Y_Max/2)-80,White,True);
     Display_Text((X_Max/2)-(X_Char*6)-70,(Y_Max/2)+(Y_Char*3),"CARAMBA! PERDISTE BROTHER!!!",Red);
     Display_Text((X_Max/2)-(X_Char*6)-80,(Y_Max/2)+(Y_Char*3) - 20,"  TE MATARON POR CONTRABANDISTA!!",Red);
     Display_Text((X_Max/2)-(X_Char*15),(Y_Max/2)-Y_Char,"APRETA LA TECLA 'q' PARA SALIR",Red);
      end if;
     
   end Dibujar_Mensaje_Final;

procedure Dibujar_Vidas is
begin
 Draw_Box(400, 100, 600, 200 , Black,True);
 Display_Text(400,100,"Tus Vidas: " & integer'image(NroVidas) ,Green);
end  Dibujar_Vidas;


procedure Dibujar_Nivel is
begin

 Display_Text(400,200,"Nivel del Juego: " & integer'image(NivelDelJuego) ,Green);
end  Dibujar_Nivel;


procedure Dibujar_Quintales is
begin
 Draw_Box(400, 400, 1000, 450 , Black,True);
 Display_Text(400,400,"Quintales de Azucar: " & integer'image( Azucar_Quintales) ,White);
end  Dibujar_Quintales;

procedure Dibujar_Km is
begin
 Draw_Box(240, 420, 600, 450 , Black,True);
 Display_Text(240,420,"Km para llegar a Bolivia: " & integer'image(contadorKM) ,Yellow);
end  Dibujar_Km;

  procedure Dibujar_Carretera is
   begin
   
      Draw_Box(0, 0, 210, 600 , ColorCarretera ,True);
      Draw_Box(105, 10, 110, 20 , ColorLineasCarretera,True);
      Draw_Box(105, 30, 110, 40 , ColorLineasCarretera,True);
      Draw_Box(105, 50, 110, 60 , ColorLineasCarretera,True);
      Draw_Box(105, 70, 110, 80 , ColorLineasCarretera,True);
      Draw_Box(105, 90, 110, 100 , ColorLineasCarretera,True);
      Draw_Box(105, 110, 110, 120 , ColorLineasCarretera,True);
      Draw_Box(105, 130, 110, 140 , ColorLineasCarretera,True);
      Draw_Box(105, 150, 110, 160 , ColorLineasCarretera,True);
      Draw_Box(105, 170, 110, 180 , ColorLineasCarretera,True);
      Draw_Box(105, 190, 110, 200 , ColorLineasCarretera,True);
      Draw_Box(105, 210, 110, 220 , ColorLineasCarretera,True);
      Draw_Box(105, 230, 110, 240 , ColorLineasCarretera,True);
      Draw_Box(105, 250, 110, 260 , ColorLineasCarretera,True);
      Draw_Box(105, 270, 110, 280 , ColorLineasCarretera,True);
      Draw_Box(105, 290, 110, 300 , ColorLineasCarretera,True);
      Draw_Box(105, 310, 110, 320 , ColorLineasCarretera,True);
      Draw_Box(105, 330, 110, 340 , ColorLineasCarretera,True);
      Draw_Box(105, 350, 110, 360 , ColorLineasCarretera,True);
      Draw_Box(105, 370, 110, 380 , ColorLineasCarretera,True);
      Draw_Box(105, 390, 110, 400 , ColorLineasCarretera,True);
      Draw_Box(105, 410, 110, 420 , ColorLineasCarretera,True);
      Draw_Box(105, 430, 110, 440 , ColorLineasCarretera,True);
      Draw_Box(105, 450, 110, 460 , ColorLineasCarretera,True);
      Draw_Box(105, 470, 110, 480 , ColorLineasCarretera,True);
      Draw_Box(105, 490, 110, 500 , ColorLineasCarretera,True);
      Draw_Box(105, 510, 110, 520 , ColorLineasCarretera,True);
      Draw_Box(105, 530, 110, 540 , ColorLineasCarretera,True);
      Draw_Box(105, 550, 110, 560 , ColorLineasCarretera,True);
      Draw_Box(105, 570, 110, 580 , ColorLineasCarretera,True);
     
      --banderas
      --Bolivia
      Draw_Box(240, 400, 260, 405 , Green,True);
      Draw_Box(240, 405, 260, 410 , Yellow,True);
      Draw_Box(240, 410, 260, 415 , Red,True);
      --Peru
      Draw_Box(240, 60, 260, 55 , White,True);
      Draw_Box(240, 55, 260, 50 , Red,True);
      Draw_Box(240, 50, 260, 45 , White,True);

   end Dibujar_Carretera;



   procedure DibujarAuto is
   begin
   Draw_Box(X_Personaje, Y_Personaje, X_Personaje+20, Y_Personaje+5, Light_Red, True);
   Draw_Box(X_Personaje + 5, Y_Personaje, X_Personaje+15, Y_Personaje-15, White, True);
   Draw_Box(X_Personaje , Y_Personaje-15, X_Personaje+20, Y_Personaje-40, Light_Red, True);
   Draw_Circle(X_Personaje + 10 , Y_Personaje-25, 5, Red, True);
   Draw_Box(X_Personaje +7, Y_Personaje-40, X_Personaje+12, Y_Personaje-45, White, True);
   Draw_Box(X_Personaje -2, Y_Personaje-45, X_Personaje+22, Y_Personaje-55, Light_Red, True);
   end DibujarAuto;


   procedure DibujarPersona(ColorUsado : in     Extended_Color_Type ; ColorUsadoComedor : in     Extended_Color_Type) is
   begin
   Draw_Circle(X_Personaje , Y_Personaje, 3, ColorUsadoComedor , True);
   Draw_Circle(X_Personaje + 10 , Y_Personaje, 5, ColorUsado, True);
   Draw_Box(X_Personaje +10 , Y_Personaje-5, X_Personaje+15, Y_Personaje-15, ColorUsado, True);
   Draw_Box(X_Personaje +12 , Y_Personaje-15, X_Personaje+15, Y_Personaje-20, ColorUsado, True);
   end DibujarPersona;

   procedure DibujarAutoEstacionado is
   begin
      X_Personaje_Estacionado := 400;
      Y_Personaje_Estacionado := 100;
     

   Draw_Box(X_Personaje_Estacionado, Y_Personaje_Estacionado, X_Personaje_Estacionado+20, Y_Personaje_Estacionado+5, Light_Red, True);
   Draw_Box(X_Personaje_Estacionado + 5, Y_Personaje_Estacionado, X_Personaje_Estacionado+15, Y_Personaje_Estacionado-15, White, True);
   Draw_Box(X_Personaje_Estacionado , Y_Personaje_Estacionado-15, X_Personaje_Estacionado+20, Y_Personaje_Estacionado-40, Light_Red, True);
   Draw_Circle(X_Personaje_Estacionado+ 10 , Y_Personaje_Estacionado-25, 5, Red, True);
   Draw_Box(X_Personaje_Estacionado +7, Y_Personaje_Estacionado-40, X_Personaje_Estacionado+12, Y_Personaje_Estacionado-45, White, True);
   Draw_Box(X_Personaje_Estacionado -2, Y_Personaje_Estacionado-45, X_Personaje_Estacionado+22, Y_Personaje_Estacionado-55, Light_Red, True);
   end DibujarAutoEstacionado;


  procedure  DibujarAzucar is
   begin
     
   Draw_Box(15, 20, 20, 25, White, True);
   Draw_Box(55, 70, 60, 75, White, True);
   Draw_Box(115, 40, 120, 45, White, True);
   Draw_Box(98, 200, 103, 205, White, True);
   Draw_Box(33, 140, 38, 145, White, True);
   Draw_Box(35, 120, 40, 125, White, True);
   Draw_Box(55, 170, 60, 175, White, True);
   Draw_Box(215, 40, 220, 45, White, True);
   Draw_Box(48, 200, 53, 205, White, True);
   Draw_Box(33, 140, 38, 145, White, True);
   Draw_Box(25, 44, 30, 49, White, True);
   Draw_Box(55, 70, 60, 75, White, True);
   Draw_Box(215, 99, 220, 104, White, True);
   Draw_Box(28, 200, 33, 205, White, True);
   Draw_Box(23, 160, 28, 165, White, True);
   Draw_Box(15, 20, 20, 25, White, True);
   Draw_Box(55, 70, 60, 75, White, True);
   Draw_Box(115, 40, 120, 45, White, True);
   Draw_Box(98, 200, 103, 205, White, True);
   Draw_Box(33, 140, 38, 145, White, True);
   Draw_Box(35, 120, 40, 125, White, True);
   Draw_Box(55, 170, 60, 175, White, True);
   Draw_Box(215, 40, 220, 45, White, True);
   Draw_Box(48, 200, 53, 205, White, True);
   Draw_Box(33, 140, 38, 145, White, True);
   Draw_Box(25, 44, 30, 49, White, True);
   Draw_Box(55, 70, 60, 75, White, True);
   Draw_Box(215, 99, 220, 104, White, True);
   Draw_Box(28, 200, 33, 205, White, True);
   Draw_Box(23, 160, 28, 165, White, True);
   Draw_Box(15, 20, 20, 25, White, True);
   Draw_Box(55, 70, 60, 75, White, True);
   Draw_Box(115, 40, 120, 45, White, True);
   Draw_Box(98, 200, 103, 205, White, True);
   Draw_Box(33, 440, 38, 445, White, True);
   Draw_Box(35, 420, 40, 425, White, True);
   Draw_Box(55, 470, 60, 475, White, True);
   Draw_Box(215, 40, 220, 45, White, True);
   Draw_Box(48, 200, 53, 205, White, True);
   Draw_Box(33, 140, 38, 145, White, True);
   Draw_Box(25, 44, 30, 49, White, True);
   Draw_Box(55, 70, 60, 75, White, True);
   Draw_Box(215, 99, 220, 104, White, True);
   Draw_Box(28, 200, 33, 205, White, True);
   Draw_Box(23, 160, 28, 165, White, True);
   Draw_Box(315, 20, 320, 25, White, True);
   Draw_Box(355, 70, 360, 75, White, True);
   Draw_Box(315, 40, 320, 45, White, True);
   Draw_Box(198, 200, 203, 205, White, True);
   Draw_Box(133, 40, 138, 45, White, True);
   Draw_Box(35, 120, 40, 125, White, True);
   Draw_Box(55, 170, 60, 175, White, True);
   Draw_Box(315, 60, 320, 65, White, True);
   Draw_Box(48, 200, 53, 205, White, True);
   Draw_Box(33, 140, 38, 145, White, True);
   Draw_Box(25, 44, 30, 49, White, True);
   Draw_Box(55, 70, 60, 75, White, True);
   Draw_Box(215, 99, 220, 104, White, True);
   Draw_Box(28, 200, 33, 205, White, True);
   Draw_Box(23, 160, 28, 165, White, True);

   Draw_Box(53, 147, 58, 152, Magenta, True);
   Draw_Box(25, 44, 30, 49, Magenta, True);
   Draw_Box(55, 70, 60, 75, Yellow, True);
   Draw_Box(15, 209, 20, 214, Green, True);
   Draw_Box(27, 100, 32, 105, Red, True);
   Draw_Box(24, 560, 29, 565, Cyan, True);

   end  DibujarAzucar;

   procedure ResetearObjetos is
   begin
         X_Cosa1 := Generate_Number (Minvalue =>  5, Maxvalue => 200);
         X_Cosa2 := Generate_Number (Minvalue =>  4, Maxvalue => 200);
         X_Cosa3 := Generate_Number (Minvalue => 20, Maxvalue => 200);
         X_Cosa4 := Generate_Number (Minvalue => 10, Maxvalue => 200);
         X_Cosa5 := Generate_Number (Minvalue => 50, Maxvalue => 200);
        
         Y_Cosa1 := 600;
         Y_Cosa2 := 800;
         Y_Cosa3 := 1000;
         Y_Cosa4 := 750;
         Y_Cosa5 := 1300;
   end ResetearObjetos;


procedure RealizarAccion is
   begin
     
      if (NiveldelJuego = 3) then 
      NroVidas := NroVidas - 1;
      end if;
     
      if (NiveldelJuego = 2) then 
      Azucar_Quintales:=Azucar_Quintales +1;
      end if;
     
      Resetearobjetos;
     
      if (Nrovidas=0) then
         Dibujar_Vidas;
         Ganar:=False;
         Salir:=True;
      end if;
     
   end RealizarAccion;


  procedure DibujarLadron (Tecla : in     Character ) is
   begin
  
      if Tecla =Vk_Right then
         X_Personaje:=X_Personaje+10;
      end if;
      if Tecla =Vk_Left then
      
         X_Personaje:=X_Personaje-10;
         
      end if;
      if Tecla =Vk_Up then
         Y_Personaje:=Y_Personaje+10;
      end if;
         
    
      DibujarAuto;

      if (X_Personaje+10>=X_Cosa1 and X_Personaje+10<=(X_Cosa1+15)  and Y_Personaje>=Y_Cosa1 and Y_Personaje <= (Y_Cosa1 +15)) then
      RealizarAccion ;
      end if;

      if (X_Personaje+10>=X_Cosa2 and X_Personaje+10<=(X_Cosa2+15)  and Y_Personaje>=Y_Cosa2 and Y_Personaje <= (Y_Cosa2 +15)) then
       RealizarAccion ;
      end if;

      if (X_Personaje+10>=X_Cosa3 and X_Personaje+10<=(X_Cosa3+15)  and Y_Personaje>=Y_Cosa3 and Y_Personaje <= (Y_Cosa3 +15)) then
       RealizarAccion ;
      end if;

      if (X_Personaje+10>=X_Cosa4 and X_Personaje+10<=(X_Cosa4+15)  and Y_Personaje>=Y_Cosa4 and Y_Personaje <= (Y_Cosa4 +15)) then
      RealizarAccion ;
      end if;

      if (X_Personaje+10>=X_Cosa5 and X_Personaje+10<=(X_Cosa5+15)  and Y_Personaje>=Y_Cosa5 and Y_Personaje <= (Y_Cosa5 +15)) then
      RealizarAccion ;
      end if;


   end Dibujarladron;


 procedure DibujarladronPersona(Tecla : in     Character ) is
   begin
  
      DibujarPersona(Black, Black);
        
      if Tecla =Vk_Right then
         X_Personaje:=X_Personaje+10;
      end if;
      if Tecla =Vk_Left then
         X_Personaje:=X_Personaje-10;
      end if;
      if Tecla =Vk_Up then
         Y_Personaje:=Y_Personaje+10;
      end if;
    
    
      if (Get_Pixel(X_Personaje, Y_Personaje ) = White) then
      Azucar_Quintales:=Azucar_Quintales +1;
      end if;

      --para subirse al auto
      if (Get_Pixel(X_Personaje +10 , Y_Personaje -5  ) = Light_Red) then
      Salir:=True;
      end if;
     
      DibujarPersona(Yellow,  Light_Green);



   end DibujarladronPersona;



   procedure DibujarBala is
   begin
      delay(0.02);
          
     --dibujamos los enemigos
     Draw_Box( X_Cosa1, Y_Cosa1,  X_Cosa1+15, Y_Cosa1+15, Black, True);
     Draw_Box( X_Cosa2, Y_Cosa2,  X_Cosa2+15, Y_Cosa2+15, Black, True);
     Draw_Box( X_Cosa3, Y_Cosa3,  X_Cosa3+15, Y_Cosa3+15, Black, True);
     Draw_Box( X_Cosa4, Y_Cosa4,  X_Cosa4+15, Y_Cosa4+15, Black, True);
     Draw_Box( X_Cosa5, Y_Cosa5,  X_Cosa5+15, Y_Cosa5+15, Black, True);

      -- dibujamos al ladron contrabandista
     DibujarAuto;

      Y_Personaje:= Y_Personaje +5;
      
       if (Y_Personaje > 600) then
         Y_Personaje :=0;
         ResetearObjetos;
         contadorKM := contadorKM - 10;
       end if;
        
            delay(0.01);
            if (Y_Cosa1< 10 ) then
            Y_Cosa1 := 600;
            X_Cosa1 := Generate_Number (Minvalue => 5, Maxvalue => 90);
            end if;
           
            if (Y_Cosa2< 10 ) then
            Y_Cosa2 := 800;
            X_Cosa2 := Generate_Number (Minvalue => 40, Maxvalue => 80);
            end if;

            if (Y_Cosa3< 10 ) then
            Y_Cosa3 := 1200;
            X_Cosa3 := Generate_Number (Minvalue => 50, Maxvalue => 80);
            end if;
      
            if (Y_Cosa4< 10 ) then
            Y_Cosa4 := 900;
            X_Cosa4 := Generate_Number (Minvalue => 4, Maxvalue => 80);
            end if;
      
            if (Y_Cosa5< 10 ) then
            Y_Cosa5 := 800;
            X_Cosa5 := Generate_Number (Minvalue => 20, Maxvalue => 80);
            end if;

            Y_Cosa1:= Y_Cosa1 - 7;
            Y_Cosa2:= Y_Cosa2 - 8;
            Y_Cosa3:= Y_Cosa3- 1;
            Y_Cosa4:= Y_Cosa4- 1;
            Y_Cosa5:= Y_Cosa5- 3;
         
           --dibujamos los enemigos
           Draw_Box( X_Cosa1, Y_Cosa1,  X_Cosa1+15, Y_Cosa1+15, Black, True);
           Draw_Box( X_Cosa2, Y_Cosa2,  X_Cosa2+15, Y_Cosa2+15, Black, True);
           Draw_Box( X_Cosa3, Y_Cosa3,  X_Cosa3+15, Y_Cosa3+15, Black, True);
           Draw_Box( X_Cosa4, Y_Cosa4,  X_Cosa4+15, Y_Cosa4+15, Black, True);
           Draw_Box( X_Cosa5, Y_Cosa5,  X_Cosa5+15, Y_Cosa5+15, Black, True);

   end DibujarBala;
     


procedure JugarNivel1 is
   begin
      Tecla:=Vk_Nul;
      DibujarAzucar;
      loop
         DibujarAutoEstacionado;
      
         Display_Text( 20, 400,  "Usted esta en la Fabrica de Azucar <<LA DULCE PERUANA>>", Yellow);
         Display_Text( 20, 380,  "..robe los quintales de azucar y escape en su auto rojo...go go go...", Yellow);

        Draw_Box( 20, 380, 360, 320, Black, True);
        Display_Text( 20, 360,  "Quintales de azucar robados: " & integer'image(Azucar_Quintales) , Cyan);
       
        Dibujar_Nivel;

       
         if (Key_Hit) then
            Tecla:=Get_Key;
           
               if Tecla=Vk_Left or Tecla=Vk_Right or Tecla=Vk_Up or Tecla=Vk_Down  then
                  Dir:=Tecla;
                  DibujarLadronPersona(Dir);
               end if;
         end if;

  
      exit when Salir=True;
      end loop;
    
   end JugarNivel1;


 procedure JugarNivel2 is
   begin
      Tecla:=Vk_Nul;

      loop
         Dibujarladron(Vk_Nul);
         Dibujar_Carretera;
         Dibujar_Vidas;
         Dibujar_Km;
         DibujarBala;
         Dibujarladron(Vk_Nul);
         Dibujar_Nivel;
         Dibujar_Quintales;
        
         if (Key_Hit) then
            Tecla:=Get_Key;
           
               if Tecla=Vk_Left or Tecla=Vk_Right or Tecla=Vk_Up or Tecla=Vk_Down then
                  Dir:=Tecla;
                  DibujarLadron(Dir);
               end if;
         end if;

         if (Contadorkm = 100) then
              Salir:=True;
            end if;
           

      exit when Salir=True;
      end loop;
          
   end JugarNivel2;


 procedure JugarNivel3 is
   begin
      Tecla:=Vk_Nul;

      loop
         Dibujarladron(Vk_Nul);
         Dibujar_Carretera;
         Dibujar_Vidas;
         Dibujar_Km;
         DibujarBala;
         Dibujarladron(Vk_Nul);
         Dibujar_Nivel;
         Dibujar_Quintales;
       
         if (Key_Hit) then
            Tecla:=Get_Key;
           
               if Tecla=Vk_Left or Tecla=Vk_Right or Tecla=Vk_Up or Tecla=Vk_Down then
                  Dir:=Tecla;
                  DibujarLadron(Dir);
               end if;
         end if;

         if (Contadorkm = 0) then
              Ganar:=True;
              Salir:=True;
            end if;
           

      exit when Salir=True;
      end loop;
    
      Dibujar_Mensaje_Final;
   end JugarNivel3;


   procedure Esperartecla is
   begin
   Salir := False;
    loop
        
         if (Key_Hit) then
           Tecla:= Get_Key;
           if Tecla='q' then
             Salir:=True;
            end if;
         end if;
        
    exit when Salir=True;
    end loop;
   end Esperartecla ;


begin
   Inicializar;
  
   Jugarnivel1;
  
   Salir:=False;
   Clear_Window(Hue => Black);
   X_Personaje := 20;
   Y_Personaje := 0;
   NivelDelJuego := 2;
   Jugarnivel2;
  
   Salir:=False;
   Clear_Window(Hue => Black);
   NivelDelJuego := 3;
  
   Jugarnivel3;
  
   EsperarTecla;
   Tecla:= Get_Key;
  
-- Demonios, existe escasez de azucar en la patria. Usted, un afamado
-- contrabandista, debera robar unos buenos quintales del Peru y meterlos
-- en su auto rojo F1 y escapar a Bolivia, asi sus compatriotas
-- podran endulzar sus tecitos y refrescos hervidos. Animo patriota !!

end ladronesDeAzucar ;

jueves, 3 de marzo de 2011

Principales características de Ada

A continuación se enumeran las principales características de Ada:

a) Legibilidad: se reconoce que los programas profesionales se leen con mayor frecuencia de lo que son escritos. Por lo tanto es importante evitar una notación lacónica como en C, que permite escribir un programa rápidamente, pero que hace casi imposible entenderlo, excepto para el autor al poco tiempo de haberlo escrito.
b) Tipificación fuerte: esto asegura que cada objeto tiene un conjunto claramente definido de posibles valores y previene la confusión entre conceptos lógicamente distintos. Como consecuencia de esto, muchos errores pueden ser detectados en tiempo de compilación, en otros lenguajes esto podría conducir a programas ejecutables, pero incorrectos.
c) Programación en gran escala: se necesitan mecanismos de encapsulación, compilación separada y manejo de bibliotecas para escribir programas portables y mantenibles.
d) Manejo de excepciones: es un hecho que los programas raramente son correctos en un cien por ciento. Por este motivo se hace necesario proveer un medio por el cual los programas puedan ser construidos de forma tal que los errores en una parte de éste no repercutan en las demás.
e) Abstracción de datos: como ya se ha mencionado, se puede lograr mayor portabilidad y mantenibilidad si los detalles de la representación de los datos puede ser separada de la especificación de las operaciones lógicas sobre los datos.
f) Tareas: en muchos casos es importante que el programa sea concebido como una serie de actividades paralelas en lugar de una secuencia simple de acciones. Al entregar estas facilidades dentro del lenguaje y no a través de llamadas a un sistema operativo se logra una mayor portabilidad y mantenibilidad.
g) Unidades genéricas: es muchos casos la parte lógica de un programa es independiente de los tipos de valores que son manipulados. Por lo tanto se requiere de un mecanismo para la creación de partes lógicamente relacionadas a partir de un prototipo único. Esto es especialmente útil para la creación de bibliotecas.

Extractado por Eduardo Jara de J.G.P. Barnes. Programmining in Ada.

Super smash Peleas en adagraph

Buscando en Internet se puede encontrar este codigo de ejemplo de supersmash, me gusta la IA del rival.
Saludos querubines...

with Adagraph;use Adagraph;
with Ada.Integer_Text_Io;use Ada.Integer_Text_Io;
with ada.Text_IO;use ada.Text_IO;
procedure Super_Smash is
   X:Integer:=100;
   Y,Y1:Integer:=110;
   X1:Integer:=480;
   Guanyador:Boolean:=False;
   K:Character;
   Vida1,Vida2:Integer:=100;
   Ia:Boolean:=False;
   Ia1:Boolean:=False;
   Sortir:Boolean:=False;
   Color:Extended_Color_Type;
   procedure Menu_Seleccio(K:in out Character;Ia,Ia1,Sortir:in out Boolean) is
      i,j:integer;
   begin
      K:='.';
      Ia:=False;
      Ia1:=False;
      Sortir:=false;
      Open_Graph_Window(600,500);
      Clear_Window(Blue);
      Draw_Box(50,200,150,220,Green,True);
      Draw_Box(235,200,355,220,Green,True);
      Draw_Box(435,200,555,220,Green,True);
      Draw_Box(525,20,580,40,Green,True);
      Display_Text(55,205,"HUM VS HUM");
      Display_Text(240,205,"HUM VS IA EASY");
      Display_Text(440,205,"HUM VS IA HARD");
      Display_Text(530,25,"SORTIR");
      while not Ia and not Ia1 and not sortir and K/=' ' loop
         Get_Mouse_Button(Left_Button,I,J);
         if I>50 and J>200 and I<150  and J<220 then
            K:=' ';
         elsif I>235 and J>200 and I<355  and J<220 then
            Ia1:=True;
         elsif I>435 and J>200 and I<555  and J<220 then
            Ia:=True;
         elsif I>525 and J>20 and I<580  and J<40 then
            Sortir:=True;
         end if;
      end loop;
      close_graph_window;
   end Menu_Seleccio;
   procedure Inicialitzacio is
   begin
      Open_Graph_Window(600,500);
      Clear_Window(Light_Blue);
      Draw_Box(100,0,500,110,Green,True);
      Draw_Box(100,100,500,110,Brown,True);
      Draw_Box(150,180,250,190,Black,True);
      Draw_Box(350,180,450,190,Black,True);
      Draw_Circle(400,400,40,Yellow,True);
      Draw_Line(400,400,450,450,Yellow);
      Draw_Line(400,400,450,350,Yellow);
      Draw_Line(400,400,350,450,Yellow);
      Draw_Line(400,400,350,350,Yellow);
      Draw_Line(400,400,460,400,Yellow);
      Draw_Line(400,400,340,400,Yellow);
      Draw_Line(400,400,400,460,Yellow);
      Draw_line(400,400,400,340,yellow);
   end Inicialitzacio;
   procedure Dibuixar_Vida(Vida1,Vida2:in Integer) is
   begin
      Draw_Box(148,60,252,80,Black,True);
      Draw_Box(150,62,150+Vida1,78,Blue,True);
      Draw_Box(348,60,452,80,Black,True);
      Draw_Box(350,62,350+Vida2,78,Blue,True);
   end Dibuixar_Vida;
   procedure Dibuix_Personatge_Aturat(X,Y:in Integer) is
   begin
      Draw_Line(X,Y,X+10,Y+20);
      Draw_Line(X+10,Y+20,X+20,Y);
      Draw_Line(X+10,Y+20,X+10,Y+50);
      Draw_Line(X+10,Y+45,X,Y+25);
      Draw_Line(X+10,Y+45,X+20,Y+25);
      Draw_Circle(X+10,Y+55,10,Black,True);
   end Dibuix_Personatge_Aturat;
   procedure Cop_De_Puny_Dret(X,Y:in Integer) is
   begin
      Draw_Line(X,Y,X+10,Y+20,Light_Blue);
      Draw_Line(X+10,Y+20,X+20,Y,Light_Blue);
      Draw_Line(X+10,Y+20,X+10,Y+50,Light_Blue);
      Draw_Line(X+10,Y+45,X,Y+25,Light_Blue);
      Draw_Line(X+10,Y+45,X+20,Y+25,Light_Blue);
      Draw_Circle(X+10,Y+55,10,Light_Blue,True);
      Draw_Line(X,Y,X+10,Y+20);
      Draw_Line(X+10,Y+20,X+20,Y);
      Draw_Line(X+10,Y+20,X+10,Y+50);
      Draw_Line(X+10,Y+45,X,Y+25);
      Draw_Line(X+10,Y+45,X+20,Y+35);
      Draw_Line(X+20,Y+35,X+25,Y+40);
      Draw_Circle(X+10,Y+55,10,Black,True);
      delay 0.1;
      Draw_Line(X,Y,X+10,Y+20,Light_Blue);
      Draw_Line(X+10,Y+20,X+20,Y,Light_Blue);
      Draw_Line(X+10,Y+20,X+10,Y+50,Light_Blue);
      Draw_Line(X+10,Y+45,X,Y+25,Light_Blue);
      Draw_Line(X+10,Y+45,X+20,Y+35,Light_Blue);
      Draw_Line(X+20,Y+35,X+25,Y+40,Light_Blue);
      Draw_Circle(X+10,Y+55,10,Light_Blue,True);
      Draw_Line(X,Y,X+10,Y+20);
      Draw_Line(X+10,Y+20,X+20,Y);
      Draw_Line(X+10,Y+20,X+10,Y+50);
      Draw_Line(X+10,Y+45,X,Y+25);
      Draw_Line(X+10,Y+45,X+20,Y+25);
      Draw_Circle(X+10,Y+55,10,Black,True);
   end Cop_De_Puny_Dret;
   procedure Cop_De_Puny_Esquerre(X,Y:in Integer) is
   begin
      Draw_Line(X,Y,X+10,Y+20,Light_Blue);
      Draw_Line(X+10,Y+20,X+20,Y,Light_Blue);
      Draw_Line(X+10,Y+20,X+10,Y+50,Light_Blue);
      Draw_Line(X+10,Y+45,X,Y+25,Light_Blue);
      Draw_Line(X+10,Y+45,X+20,Y+25,Light_Blue);
      Draw_Circle(X+10,Y+55,10,Light_Blue,True);
      Draw_Line(X,Y,X+10,Y+20);
      Draw_Line(X+10,Y+20,X+20,Y);
      Draw_Line(X+10,Y+20,X+10,Y+50);
      Draw_Line(X+10,Y+45,X,Y+35);
      Draw_Line(X,Y+35,X-5,Y+40);
      Draw_Line(X+10,Y+45,X+20,Y+25);
      Draw_Circle(X+10,Y+55,10,Black,True);
      delay 0.1;
      Draw_Line(X,Y,X+10,Y+20,Light_Blue);
      Draw_Line(X+10,Y+20,X+20,Y,Light_Blue);
      Draw_Line(X+10,Y+20,X+10,Y+50,Light_Blue);
      Draw_Line(X+10,Y+45,X,Y+35,Light_Blue);
      Draw_Line(X,Y+35,X-5,Y+40,Light_Blue);
      Draw_Line(X+10,Y+45,X+20,Y+25,Light_Blue);
      Draw_Circle(X+10,Y+55,10,Light_Blue,True);
      Draw_Line(X,Y,X+10,Y+20);
      Draw_Line(X+10,Y+20,X+20,Y);
      Draw_Line(X+10,Y+20,X+10,Y+50);
      Draw_Line(X+10,Y+45,X,Y+25);
      Draw_Line(X+10,Y+45,X+20,Y+25);
      Draw_Circle(X+10,Y+55,10,Black,True);
   end Cop_De_Puny_Esquerre;
   procedure Bot_Dreta(X,Y:in Integer;POSX,POSY:out integer) is
   begin
      Draw_Line(X,Y,X+10,Y+20,Light_Blue);
      Draw_Line(X+10,Y+20,X+20,Y,Light_Blue);
      Draw_Line(X+10,Y+20,X+10,Y+50,Light_Blue);
      Draw_Line(X+10,Y+45,X,Y+25,Light_Blue);
      Draw_Line(X+10,Y+45,X+20,Y+25,Light_Blue);
      Draw_Circle(X+10,Y+55,10,Light_Blue,True);
      delay 0.03;
      POSX:=X+40;
      POSY:=Y+80;
      Draw_Line(POSX,POSY,POSX+10,POSY+20);
      Draw_Line(POSX+10,POSY+20,POSX+20,POSY);
      Draw_Line(POSX+10,POSY+20,POSX+10,POSY+50);
      Draw_Line(POSX+10,POSY+45,POSX,POSY+25);
      Draw_Line(POSX+10,POSY+45,POSX+20,POSY+25);
      Draw_Circle(POSX+10,POSY+55,10,Black,True);
   end Bot_Dreta;
   procedure Bot_Esquerra(X,Y:in Integer;Posx,Posy:out Integer) is
   begin
      Draw_Line(X,Y,X+10,Y+20,Light_Blue);
      Draw_Line(X+10,Y+20,X+20,Y,Light_Blue);
      Draw_Line(X+10,Y+20,X+10,Y+50,Light_Blue);
      Draw_Line(X+10,Y+45,X,Y+25,Light_Blue);
      Draw_Line(X+10,Y+45,X+20,Y+25,Light_Blue);
      Draw_Circle(X+10,Y+55,10,Light_Blue,True);
      delay 0.03;
      POSX:=X-40;
      POSY:=Y+80;
      Draw_Line(POSX,POSY,POSX+10,POSY+20);
      Draw_Line(POSX+10,POSY+20,POSX+20,POSY);
      Draw_Line(POSX+10,POSY+20,POSX+10,POSY+50);
      Draw_Line(POSX+10,POSY+45,POSX,POSY+25);
      Draw_Line(POSX+10,POSY+45,POSX+20,POSY+25);
      Draw_Circle(POSX+10,POSY+55,10,Black,True);
   end Bot_Esquerra;
   procedure Efecte_Gravetat(X,Y:in out Integer) is
   begin
      Draw_Line(X,Y,X+10,Y+20,Light_Blue);
      Draw_Line(X+10,Y+20,X+20,Y,Light_Blue);
      Draw_Line(X+10,Y+20,X+10,Y+50,Light_Blue);
      Draw_Line(X+10,Y+45,X,Y+25,Light_Blue);
      Draw_Line(X+10,Y+45,X+20,Y+25,Light_Blue);
      Draw_Circle(X+10,Y+55,10,Light_Blue,True);
      if Y>190 then
         Y:=Y-80;
      end if;
      if Y>110 and (X+20<150 or (X>250 and X+20<350) or X>450) then
         Y:=Y-80;
      end if;
      if Y=110 and (X<100 or X>500) then
         Y:=Y-110;
      end if;
      Draw_Line(X,Y,X+10,Y+20);
      Draw_Line(X+10,Y+20,X+20,Y);
      Draw_Line(X+10,Y+20,X+10,Y+50);
      Draw_Line(X+10,Y+45,X,Y+25);
      Draw_Line(X+10,Y+45,X+20,Y+25);
      Draw_Circle(X+10,Y+55,10,Black,True);
   end Efecte_Gravetat;
   procedure Moure_Dreta(X,Y:in out Integer) is
   begin
      Draw_Line(X,Y,X+10,Y+20,Light_Blue);
      Draw_Line(X+10,Y+20,X+20,Y,Light_Blue);
      Draw_Line(X+10,Y+20,X+10,Y+50,Light_Blue);
      Draw_Line(X+10,Y+45,X,Y+25,Light_Blue);
      Draw_Line(X+10,Y+45,X+20,Y+25,Light_Blue);
      Draw_Circle(X+10,Y+55,10,Light_Blue,True);
      Draw_Line(X+10,Y+20,X+20,Y);
      Draw_Line(X+10,Y+20,X+10,Y+50);
      Draw_Line(X+10,Y+45,X,Y+25);
      Draw_Line(X+10,Y+45,X+20,Y+25);
      Draw_Circle(X+10,Y+55,10,Black,True);
      delay 0.1;
      Draw_Line(X+10,Y+20,X+20,Y,Light_Blue);
      Draw_Line(X+10,Y+20,X+10,Y+50,Light_Blue);
      Draw_Line(X+10,Y+45,X,Y+25,Light_Blue);
      Draw_Line(X+10,Y+45,X+20,Y+25,Light_Blue);
      Draw_Circle(X+10,Y+55,10,Light_Blue,True);
      delay 0.1;
      X:=X+20;
      Draw_Line(X,Y,X+10,Y+20);
      Draw_Line(X+10,Y+20,X+20,Y);
      Draw_Line(X+10,Y+20,X+10,Y+50);
      Draw_Line(X+10,Y+45,X,Y+25);
      Draw_Line(X+10,Y+45,X+20,Y+25);
      Draw_Circle(X+10,Y+55,10,Black,True);
   end Moure_Dreta;
   procedure Moure_Esquerra(X,Y:in out Integer) is
   begin
      Draw_Line(X,Y,X+10,Y+20,Light_Blue);
      Draw_Line(X+10,Y+20,X+20,Y,Light_Blue);
      Draw_Line(X+10,Y+20,X+10,Y+50,Light_Blue);
      Draw_Line(X+10,Y+45,X,Y+25,Light_Blue);
      Draw_Line(X+10,Y+45,X+20,Y+25,Light_Blue);
      Draw_Circle(X+10,Y+55,10,Light_Blue,True);
      Draw_Line(X,Y,X+10,Y+20);
      Draw_Line(X+10,Y+20,X+10,Y+50);
      Draw_Line(X+10,Y+45,X,Y+25);
      Draw_Line(X+10,Y+45,X+20,Y+25);
      Draw_Circle(X+10,Y+55,10,Black,True);
      delay 0.1;
      Draw_Line(X,Y,X+10,Y+20,Light_Blue);
      Draw_Line(X+10,Y+20,X+10,Y+50,Light_Blue);
      Draw_Line(X+10,Y+45,X,Y+25,Light_Blue);
      Draw_Line(X+10,Y+45,X+20,Y+25,Light_Blue);
      Draw_Circle(X+10,Y+55,10,Light_Blue,True);
      delay 0.1;
      X:=X-20;
      Draw_Line(X,Y,X+10,Y+20);
      Draw_Line(X+10,Y+20,X+20,Y);
      Draw_Line(X+10,Y+20,X+10,Y+50);
      Draw_Line(X+10,Y+45,X,Y+25);
      Draw_Line(X+10,Y+45,X+20,Y+25);
      Draw_Circle(X+10,Y+55,10,Black,True);
   end Moure_Esquerra;
   procedure Evaluar_Si_Ferit_Dreta(A,B,Y,Y1,Vida:in out Integer) is
   begin
      if B-A=20 and Y=Y1 then
         Draw_Line(B,Y,B+10,Y+20,Light_Blue);
         Draw_Line(B+10,Y+20,B+20,Y,Light_Blue);
         Draw_Line(B+10,Y+20,B+10,Y+50,Light_Blue);
         Draw_Line(B+10,Y+45,B,Y+25,Light_Blue);
         Draw_Line(B+10,Y+45,B+20,Y+25,Light_Blue);
         Draw_Circle(B+10,Y+55,10,Light_Blue,True);
         Draw_Line(B,Y,B+10,Y+20);
         Draw_Line(B+10,Y+20,B+20,Y);
         Draw_Line(B+10,Y+20,B+10,Y+50);
         Draw_Line(B+10,Y+45,B,Y+25);
         Draw_Line(B+10,Y+45,B+20,Y+25);
         Draw_Circle(B+10,Y+55,10,Black,True);
         Draw_Circle(B+10,Y+40,5,Red,True);
         delay 0.02;
         Draw_Line(B,Y,B+10,Y+20,Light_Blue);
         Draw_Line(B+10,Y+20,B+20,Y,Light_Blue);
         Draw_Line(B+10,Y+20,B+10,Y+50,Light_Blue);
         Draw_Line(B+10,Y+45,B,Y+25,Light_Blue);
         Draw_Line(B+10,Y+45,B+20,Y+25,Light_Blue);
         Draw_Circle(B+10,Y+55,10,Light_Blue,True);
         Draw_Circle(B+10,Y+40,5,Light_Blue,True);
         B:=B+20;
         Draw_Line(B,Y,B+10,Y+20);
         Draw_Line(B+10,Y+20,B+20,Y);
         Draw_Line(B+10,Y+20,B+10,Y+50);
         Draw_Line(B+10,Y+45,B,Y+25);
         Draw_Line(B+10,Y+45,B+20,Y+25);
         Draw_Circle(B+10,Y+55,10,Black,True);
         Vida:=Vida-10;
      end if;
   end Evaluar_Si_Ferit_Dreta;
   procedure Evaluar_Si_Ferit_Esquerra(A,B,Y,Y1,Vida:in out Integer) is
   begin
      if (A-B)=20 and Y=Y1 then
         Draw_Line(B,Y,B+10,Y+20,Light_Blue);
         Draw_Line(B+10,Y+20,B+20,Y,Light_Blue);
         Draw_Line(B+10,Y+20,B+10,Y+50,Light_Blue);
         Draw_Line(B+10,Y+45,B,Y+25,Light_Blue);
         Draw_Line(B+10,Y+45,B+20,Y+25,Light_Blue);
         Draw_Circle(B+10,Y+55,10,Light_Blue,True);
         Draw_Line(B,Y,B+10,Y+20);
         Draw_Line(B+10,Y+20,B+20,Y);
         Draw_Line(B+10,Y+20,B+10,Y+50);
         Draw_Line(B+10,Y+45,B,Y+25);
         Draw_Line(B+10,Y+45,B+20,Y+25);
         Draw_Circle(B+10,Y+55,10,Black,True);
         Draw_Circle(B+10,Y+40,5,Red,True);
         delay 0.02;
         Draw_Line(B,Y,B+10,Y+20,Light_Blue);
         Draw_Line(B+10,Y+20,B+20,Y,Light_Blue);
         Draw_Line(B+10,Y+20,B+10,Y+50,Light_Blue);
         Draw_Line(B+10,Y+45,B,Y+25,Light_Blue);
         Draw_Line(B+10,Y+45,B+20,Y+25,Light_Blue);
         Draw_Circle(B+10,Y+55,10,Light_Blue,True);
         Draw_Circle(B+10,Y+40,5,Light_Blue,True);
         B:=B-20;
         Draw_Line(B,Y,B+10,Y+20);
         Draw_Line(B+10,Y+20,B+20,Y);
         Draw_Line(B+10,Y+20,B+10,Y+50);
         Draw_Line(B+10,Y+45,B,Y+25);
         Draw_Line(B+10,Y+45,B+20,Y+25);
         Draw_Circle(B+10,Y+55,10,Black,True);
         Vida:=Vida-10;
      end if;
   end Evaluar_Si_Ferit_Esquerra;
begin
   while not Sortir loop
      Menu_Seleccio(K,Ia,Ia1,Sortir);
      if ia then
         Inicialitzacio;
         Dibuixar_Vida(Vida1,Vida2);
         X:=100;
         Y:=110;
         Y1:=110;
         X1:=480;
         Guanyador:=False;
         Dibuix_Personatge_Aturat(X,Y);
         Dibuix_Personatge_Aturat(X1,Y1);
         while not Guanyador loop
            K:=Get_Key;
            if K='a' then
               Moure_Esquerra(X,Y);
               Efecte_Gravetat(X,Y);
            elsif K='d' then
               Moure_Dreta(X,Y);
               Efecte_Gravetat(X,Y);
            elsif K='q' then
               Bot_Esquerra(X,Y,X,Y);
               delay 0.05;
               Efecte_Gravetat(X,Y);
            elsif K='e' then
               Bot_Dreta(X,Y,X,Y);
               delay 0.05;
               Efecte_Gravetat(X,Y);
            elsif K='w' then
               Cop_De_Puny_Dret(X,Y);
               Evaluar_Si_Ferit_Dreta(X,X1,Y,Y1,Vida2);
               Dibuixar_Vida(Vida1,Vida2);
               Efecte_Gravetat(X1,Y1);
            elsif K='s' then
               Cop_De_Puny_Esquerre(X,Y);
               Evaluar_Si_Ferit_Esquerra(X,X1,Y,Y1,Vida2);
               Dibuixar_Vida(Vida1,Vida2);
               Efecte_Gravetat(X1,Y1);
            end if;
            while not key_hit and not guanyador loop
               Put_Pixel(1,1,Random_Color);
               Color:=Get_Pixel(1,1);
               if (X1-X)>20 and (color=black or color=blue or color=green or color=cyan or color=red or color=magenta or color=brown or color=light_gray or color=dark_gray) then
                  Moure_Esquerra(X1,Y1);
                  Efecte_Gravetat(X1,Y1);
               elsif (X1-X)>20 and (Color=Light_Blue or Color=Light_Green or Color=Light_Cyan or Color=Light_Red) then
                  Bot_Esquerra(X1,Y1,X1,Y1);
                  delay 0.05;
                  Efecte_Gravetat(X1,Y1);
               elsif (X1-X)>20 and (Color=Light_Magenta or Color=Yellow or Color=White)then
                  null;
               end if;
               if (X-X1)>20 and (color=black or color=blue or color=green or color=cyan or color=red or color=magenta or color=brown or color=light_gray or color=dark_gray) then
                  Moure_Dreta(X1,Y1);
                  Efecte_Gravetat(X1,Y1);
               elsif (X-X1)>20 and (Color=Light_Blue or Color=Light_Green or Color=Light_Cyan or Color=Light_Red) then
                  Bot_Dreta(X1,Y1,X1,Y1);
                  delay 0.05;
                  Efecte_Gravetat(X1,Y1);
               elsif (X-X1)>20 and (Color=Light_Magenta or Color=Yellow or Color=White) then
                  null;
               end if;
               if (X1-X)=20 and (color=black or color=blue or color=green or color=cyan or color=red or color=magenta or color=brown or color=light_gray) then
                  Cop_De_Puny_Esquerre(X1,Y1);
                  Evaluar_Si_Ferit_Esquerra(X1,X,Y,Y1,Vida1);
                  Dibuixar_Vida(Vida1,Vida2);
                  Efecte_Gravetat(X,Y);
               elsif (X1-X)=20 and (Color=Light_Blue or Color=Light_Green or Color=Light_Cyan) then
                  Moure_Esquerra(X1,Y1);
                  Efecte_Gravetat(X1,Y1);
               elsif (X1-X)=20 and (Color=Light_Magenta or Color=Yellow or Color=White) then
                  Moure_Dreta(X1,Y1);
                  Efecte_Gravetat(X1,Y1);
               elsif  (X1-X)=20 and (Color=Dark_Gray or Color=Light_Red) then
                  null;
               end if;
               if (X1-X)=-20 and (color=black or color=blue or color=green or color=cyan or color=red or color=magenta or color=brown or color=light_gray) then
                  Cop_De_Puny_Dret(X1,Y1);
                  Evaluar_Si_Ferit_Dreta(X1,X,Y,Y1,Vida1);
                  Dibuixar_Vida(Vida1,Vida2);
                  Efecte_Gravetat(X,Y);
               elsif (X1-X)=-20 and (Color=Light_Blue or Color=Light_Green or Color=Light_Cyan) then
                  Moure_Dreta(X1,Y1);
                  Efecte_Gravetat(X1,Y1);
               elsif (X1-X)=-20 and (Color=Light_Magenta or Color=Yellow or Color=White) then
                  Moure_Esquerra(X1,Y1);
                  Efecte_Gravetat(X1,Y1);
               elsif  (X1-X)=-20 and (Color=Dark_Gray or Color=Light_Red) then
                  null;
               end if;
               if X=X1 and (color=black or color=blue or color=green or color=cyan or color=red or color=magenta or color=brown or color=light_gray or color=dark_gray) then
                  Bot_Esquerra(X1,Y1,X1,Y1);
                  delay 0.05;
                  Efecte_Gravetat(X1,Y1);
               elsif X=X1 and (Color=Light_Blue or Color=Light_Green or Color=Light_Cyan or Color=Light_Red or Color=Light_Magenta or Color=Yellow or Color=White) then
                  Bot_Dreta(X1,Y1,X1,Y1);
                  delay 0.05;
                  Efecte_Gravetat(X1,Y1);
               end if;
               if Y=0 or Y1=0 or Vida1<=0 or Vida2<=0 then
                  Guanyador:=True;
               end if;
            end loop;
         end loop;
      elsif ia1 then
         Inicialitzacio;
         Dibuixar_Vida(Vida1,Vida2);
         X:=100;
         Y:=110;
         Y1:=110;
         X1:=480;
         Guanyador:=False;
         Dibuix_Personatge_Aturat(X,Y);
         Dibuix_Personatge_Aturat(X1,Y1);
         while not Guanyador loop
            K:=Get_Key;
            if K='a' then
               Moure_Esquerra(X,Y);
               Efecte_Gravetat(X,Y);
            elsif K='d' then
               Moure_Dreta(X,Y);
               Efecte_Gravetat(X,Y);
            elsif K='q' then
               Bot_Esquerra(X,Y,X,Y);
               delay 0.05;
               Efecte_Gravetat(X,Y);
            elsif K='e' then
               Bot_Dreta(X,Y,X,Y);
               delay 0.05;
               Efecte_Gravetat(X,Y);
            elsif K='w' then
               Cop_De_Puny_Dret(X,Y);
               Evaluar_Si_Ferit_Dreta(X,X1,Y,Y1,Vida2);
               Dibuixar_Vida(Vida1,Vida2);
               Efecte_Gravetat(X1,Y1);
            elsif K='s' then
               Cop_De_Puny_Esquerre(X,Y);
               Evaluar_Si_Ferit_Esquerra(X,X1,Y,Y1,Vida2);
               Dibuixar_Vida(Vida1,Vida2);
               Efecte_Gravetat(X1,Y1);
            end if;
            while not key_hit and not guanyador loop
               Put_Pixel(1,1,Random_Color);
               Color:=Get_Pixel(1,1);
               if (X1-X)>20 and (color=black or color=blue or color=green or color=cyan or color=red or color=magenta or color=brown or color=light_gray or color=dark_gray) then
                  Moure_Esquerra(X1,Y1);
                  Efecte_Gravetat(X1,Y1);
               elsif (X1-X)>20 and (Color=Light_Blue or Color=Light_Green or Color=Light_Cyan or Color=Light_Red) then
                  Bot_Esquerra(X1,Y1,X1,Y1);
                  delay 0.05;
                  Efecte_Gravetat(X1,Y1);
               elsif (X1-X)>20 and (Color=Light_Magenta or Color=Yellow or Color=White)then
                  null;
               end if;
               if (X-X1)>20 and (color=black or color=blue or color=green or color=cyan or color=red or color=magenta or color=brown or color=light_gray or color=dark_gray) then
                  Moure_Dreta(X1,Y1);
                  Efecte_Gravetat(X1,Y1);
               elsif (X-X1)>20 and (Color=Light_Blue or Color=Light_Green or Color=Light_Cyan or Color=Light_Red) then
                  Bot_Dreta(X1,Y1,X1,Y1);
                  delay 0.05;
                  Efecte_Gravetat(X1,Y1);
               elsif (X-X1)>20 and (Color=Light_Magenta or Color=Yellow or Color=White) then
                  null;
               end if;
               if (X1-X)=20 and (color=black or color=blue or color=green or color=cyan) then
                  Cop_De_Puny_Esquerre(X1,Y1);
                  Evaluar_Si_Ferit_Esquerra(X1,X,Y,Y1,Vida1);
                  Dibuixar_Vida(Vida1,Vida2);
                  Efecte_Gravetat(X,Y);
               elsif (X1-X)=20 and (Color=Light_Blue or Color=Light_Green or Color=Light_Cyan) then
                  Moure_Esquerra(X1,Y1);
                  Efecte_Gravetat(X1,Y1);
               elsif (X1-X)=20 and (Color=Light_Magenta or Color=Yellow or Color=White) then
                  Moure_Dreta(X1,Y1);
                  Efecte_Gravetat(X1,Y1);
               elsif  (X1-X)=20 and (Color=Brown or Color=Light_Gray or Color=Dark_Gray or Color=Light_Red or Color=Red or Color=Magenta) then
                  null;
               end if;
               if (X1-X)=-20 and (color=black or color=blue or color=green or color=cyan) then
                  Cop_De_Puny_Dret(X1,Y1);
                  Evaluar_Si_Ferit_Dreta(X1,X,Y,Y1,Vida1);
                  Dibuixar_Vida(Vida1,Vida2);
                  Efecte_Gravetat(X,Y);
               elsif (X1-X)=-20 and (Color=Light_Blue or Color=Light_Green or Color=Light_Cyan) then
                  Moure_Dreta(X1,Y1);
                  Efecte_Gravetat(X1,Y1);
               elsif (X1-X)=-20 and (Color=Light_Magenta or Color=Yellow or Color=White) then
                  Moure_Esquerra(X1,Y1);
                  Efecte_Gravetat(X1,Y1);
               elsif  (X1-X)=20 and (Color=Brown or Color=Light_Gray or Color=Dark_Gray or Color=Light_Red or Color=Red or Color=Magenta) then
                  null;
               end if;
               if X=X1 and (color=black or color=blue or color=green or color=cyan or color=brown or color=light_gray or color=dark_gray) then
                  Bot_Esquerra(X1,Y1,X1,Y1);
                  delay 0.05;
                  Efecte_Gravetat(X1,Y1);
               elsif X=X1 and (Color=Light_Blue or Color=Light_Green or Color=Light_Cyan or Color=Light_Red or Color=Light_Magenta or Color=Yellow or Color=White or color=red or color=magenta) then
                  Bot_Dreta(X1,Y1,X1,Y1);
                  delay 0.05;
                  Efecte_Gravetat(X1,Y1);
               end if;
               if Y=0 or Y1=0 or Vida1<=0 or Vida2<=0 then
                  Guanyador:=True;
               end if;
            end loop;
         end loop;
      elsif K=' ' then
         Inicialitzacio;
         Dibuixar_Vida(Vida1,Vida2);
         X:=100;
         Y:=110;
         Y1:=110;
         X1:=480;
         Guanyador:=False;
         Dibuix_Personatge_Aturat(X,Y);
         Dibuix_Personatge_Aturat(X1,Y1);
         while not Guanyador loop
            K:=Get_Key;
            if K='a' then
               Moure_Esquerra(X,Y);
               Efecte_Gravetat(X,Y);
            elsif K='d' then
               Moure_Dreta(X,Y);
               Efecte_Gravetat(X,Y);
            elsif K='q' then
               Bot_Esquerra(X,Y,X,Y);
               delay 0.05;
               Efecte_Gravetat(X,Y);
            elsif K='e' then
               Bot_Dreta(X,Y,X,Y);
               delay 0.05;
               Efecte_Gravetat(X,Y);
            elsif K='w' then
               Cop_De_Puny_Dret(X,Y);
               Evaluar_Si_Ferit_Dreta(X,X1,Y,Y1,Vida2);
               Dibuixar_Vida(Vida1,Vida2);
               Efecte_Gravetat(X1,Y1);
            elsif K='s' then
               Cop_De_Puny_Esquerre(X,Y);
               Evaluar_Si_Ferit_Esquerra(X,X1,Y,Y1,Vida2);
               Dibuixar_Vida(Vida1,Vida2);
               Efecte_Gravetat(X1,Y1);
            end if;
            if K='j' then
               Moure_Esquerra(X1,Y1);
               Efecte_Gravetat(X1,Y1);
            elsif K='l' then
               Moure_Dreta(X1,Y1);
               Efecte_Gravetat(X1,Y1);
            elsif K='u' then
               Bot_Esquerra(X1,Y1,X1,Y1);
               delay 0.05;
               Efecte_Gravetat(X1,Y1);
            elsif K='o' then
               Bot_Dreta(X1,Y1,X1,Y1);
               delay 0.05;
               Efecte_Gravetat(X1,Y1);
            elsif K='i' then
               Cop_De_Puny_Dret(X1,Y1);
               Evaluar_Si_Ferit_Dreta(X1,X,Y,Y1,Vida1);
               Dibuixar_Vida(Vida1,Vida2);
               Efecte_Gravetat(X,Y);
            elsif K='k' then
               Cop_De_Puny_Esquerre(X1,Y1);
               Evaluar_Si_Ferit_Esquerra(X1,X,Y,Y1,Vida1);
               Dibuixar_Vida(Vida1,Vida2);
               Efecte_Gravetat(X,Y);
            end if;
            if Y=0 or Y1=0 or Vida1<=0 or Vida2<=0 then
               Guanyador:=True;
            end if;
         end loop;
      end if;
      if Y=0 or Vida1<=0 then
         if Vida1<=0 then
            Draw_Circle(X+10,Y+40,30,Red,True);
         end if;
         Display_Text(100,260,"GUANYADOR EL JUGADOR 2",Red);
      else
         if Vida2<=0 then
            Draw_Circle(X1+10,Y1+40,15,Red,True);
         end if;
         Display_Text(100,260,"GUANYADOR EL JUGADOR 1",Red);
      end if;
      Vida1:=100;
      Vida2:=100;
      delay 3.0;
      if not Sortir then
         Close_Graph_Window;
      end if;
   end loop;
end super_smash;