with Mouv ;
with Gada.Text_IO ;
procedure Mission1 is
package M renames Mouv ;
package Txt renames Gada.Text_IO ;
procedure Affiche_Pos (Pos : M.T_Pos) is
begin
Txt.Put_Line("X = " & Integer'Image(Pos.X) & ", Y = " & Integer'Image(Pos.Y)) ;
Txt.New_Line ;
end Affiche_Pos ;
procedure Affiche_Direction (Dir : M.T_Direction) is
begin
case Dir is
when M.Up => Txt.Put("Haut ") ;
when M.Down => Txt.Put("Bas ") ;
when M.Left => Txt.Put("Gauche ") ;
when M.Right => Txt.Put("Droite ") ;
when M.None => Txt.Put("Rien ") ;
end case ;
end Affiche_Direction ;
procedure Affiche_Sequence (Seq : M.T_Sequence) is
begin
for Index in Seq'Range loop
Affiche_Direction(Seq(Index)) ;
end loop ;
Txt.New_Line ;
end Affiche_Sequence ;
function Calcule_Position (Origine : M.T_Pos ; Seq : M.T_Sequence) return M.T_Pos is
Pos : M.T_Pos := Origine ;
begin
for Index in Seq'Range loop
case Seq(Index) is
when M.Up => Pos.Y := Pos.Y + 1 ;
when M.Down => Pos.Y := Pos.Y - 1 ;
when M.Left => Pos.X := Pos.X - 1 ;
when M.Right => Pos.X := Pos.X + 1 ;
when M.None => null ;
end case ;
end loop ;
return Pos ;
end Calcule_Position ;
function Transforme (Chaine : String) return M.T_Sequence is
Resultat : M.T_Sequence(Chaine'Range) ;
Dir : M.T_Direction ;
begin
for Index in Chaine'Range loop
case Chaine(Index) is
when 'U' => Dir := M.Up ;
when 'D' => Dir := M.Down ;
when 'L' => Dir := M.Left ;
when 'R' => Dir := M.Right ;
when others => Dir := M.None ;
end case ;
Resultat(Index) := Dir ;
end loop ;
return Resultat ;
end Transforme ;
Test1 : M.T_Sequence := (M.Up, M.Up, M.Right) ;
Pos_Depart : M.T_Pos := (4, 2) ;
begin
Txt.Put_Line("Origine : ") ;
Affiche_Pos( Pos_Depart) ;
Affiche_Sequence( Test1 ) ;
Affiche_Pos( Calcule_Position( Pos_Depart, Test1) ) ;
Txt.Put("Entrez maintenant votre propre séquence : ") ;
declare
Chaine_Perso : String := Txt.FGet ;
Sequence : M.T_Sequence := Transforme(Chaine_Perso) ;
begin
Affiche_Sequence(Sequence) ;
Affiche_Pos( Calcule_Position( Pos_Depart, Sequence) ) ;
end ;
end Mission1 ;