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 ;