mission1.adb

--
-- Ce programme affiche des trames de caractères.
--

with GAda.Text_IO ;
with GAda.Integer_Text_IO ;
with Caracteres ; use Caracteres ;

procedure Mission1 is

   package Txt renames GAda.Text_IO ;
   package ITxt renames GAda.Integer_Text_IO ;
   package Car renames Caracteres ;

   -- Affiche une trame avec des # et des espaces.
   procedure Afficher_Trame (Trame : Car.T_Trame) is
   begin
      for Y in Trame'Range(1) loop
         for X in Trame'Range(2) loop
            case Trame(Y,X) is
               when Car.Allume => Txt.Put("#") ;
               when Car.Eteint => Txt.Put(" ") ;
            end case ;
         end loop ;
         Txt.New_Line ;
      end loop ;
   end Afficher_Trame ;

   procedure Tester_Afficher_Trame is
   begin
      Afficher_Trame(Car.Table(30).Trame) ;
      Afficher_Trame(Car.Table(31).Trame) ;
      Afficher_Trame(Car.Table(32).Trame) ;
   end Tester_Afficher_Trame ;

   -- À partir d'un caractère, trouve la trame associée
   -- Renvoie la trame de l'étoile (caractère '*') si le caractère n'est pas trouvé.
   --- Algorithme de recherche, à connaître
   function Trouver_Trame (Lettre : Character) return Car.T_Trame is
      --- Deux variables
      No_Case : Integer ;
      Trouve : Boolean ;
   begin
      Trouve := False ;
      No_Case := Car.Table'First ;
      
      --- Deux conditions dans le while
      -- Parcourt la table jusqu'à trouver le caractère ou jusqu'à sortir de la table.
      while (not Trouve) and No_Case <= Car.Table'Last loop
         if Car.Table(No_Case).Car = Lettre then
            Trouve := True ;
         else
            No_Case := No_Case + 1 ;
         end if ;
      end loop ;

      -- Si on a pas trouvé le caractère, on renvoie l'étoile (numéro 9)
      if not Trouve then No_Case := 9 ;
      end if ;

      return Car.Table(No_Case).Trame ;

   end Trouver_Trame ;

   -- Affiche un mot verticalement
   procedure Afficher_Mot(Mot : String) is
   begin
      for NoCase in Mot'Range loop
         Afficher_Trame( Trouver_Trame( Mot(NoCase) ) ) ;
      end loop ;
   end Afficher_Mot ;

   --
   -- L'affichage de texte "horizontalement" est laissé en exercice.
   --

   No_Car : Integer ;

begin
   Txt.Put ("Numéro de caractère à afficher : ") ;
   No_Car := ITxt.FGet ;
   Txt.Put(Car.Table(No_Car).Car) ;

   Tester_Afficher_Trame ;

   Afficher_Mot("Sauron en Grèce") ;

end Mission1 ;