--MARTIN Mathieu Gr F le 25/11/03
--TP3
--programme mastermind
with Ada.Text_Io,Ada.Integer_Text_Io,Choisir_Chiffre;

procedure Mastermind is

   Nc,Np,P,N,Choix : Integer;
   subtype Choix_Possibles is Integer range 1..2;


   --declaration des tableaux
   subtype  Des_Chiffres is Integer range 0..9;
   Un_Chiffre : Des_Chiffres;
   subtype Taille_Tableau is Integer range 1..6;
   type Tableau_Nombre_A_6_chiffres is array (Taille_Tableau) of Des_Chiffres;
   Nombre_Cherche : Tableau_Nombre_A_6_Chiffres;
   Nombre_Propose : Tableau_Nombre_A_6_Chiffres;

begin
   NC :=0;
   NP :=0;
   Choix :=1;
   --  cration du menu
   while Choix/=2 loop
      Ada.Text_Io.Put_Line("Pour jouer tapez 1");
      Ada.Text_Io.Put_Line("Pour sortir tapez 2");
      Ada.Integer_Text_Io.Get(Choix);

      --dbut du jeu
      if Choix = 1 then
         --  initialisation du nombre  trouver
         for Index in Taille_Tableau loop
            Choisir_Chiffre.Chiffre_Au_Hasard(Un_Chiffre);
            Nombre_Cherche(index):= Un_Chiffre;
         end loop;
         --  entre du nombre propos par le joueur
         for Nombres_De_Coups in 0..7 loop
            Ada.Text_Io.Put_Line("entrez votre nombre de 6 chiffres");
            Ada.Integer_Text_Io.Get(NP);
            for Index   in reverse Taille_Tableau loop
               Nombre_Propose(Index) := NP rem  10;
               NP := NP/10;
            end loop;
            --comparaison d'galit entre les 2 nombres
            for Index in Taille_Tableau loop
               if Nombre_Propose(Index)=Nombre_cherche(Index)
               then Ada.Text_Io.Put("*");
               else null;
               end if;
            end loop;
            --comparaison d'existence
            N:=0;
            for Index in Taille_Tableau loop
               for I in Taille_Tableau loop
                  if Nombre_propose(I)=Nombre_cherche(Index)
                  then Ada.Text_Io.Put("+");
                  else null;
                  end if;
                  N:=N+1;
               end loop;
            end loop;
            P:=6-N;
            -- affichage des "-"
            for C in 1..P loop
               Ada.Text_Io.Put("-");
            end loop;
         end loop;
      end if;
      if Choix = 2 then null;
      end if;

   end loop;

end Mastermind;




 
 
 
