@@ -88,6 +88,7 @@ fn add_pokemon_from_input(dex: &mut Pokedex) {
8888 . expect ( "Erreur de lecture" )
8989 . expect ( "Erreur de lecture" )
9090 . trim ( )
91+ . to_lowercase ( )
9192 . to_string ( ) ;
9293
9394 add_pokemon ( dex, & p_type, & nom) ;
@@ -100,42 +101,31 @@ fn main() {
100101 let total_pokemon: usize = dex. values ( ) . map ( |set| set. len ( ) ) . sum ( ) ;
101102
102103 println ! ( "Pokedex initialisé avec les {total_pokemon} Pokémon de la gen 1 !" ) ;
103-
104- println ! ( "Voulez-vous ajouter un Pokémon ? y/n" ) ;
105-
106- let add_pokemon = io:: stdin ( )
107- . lines ( )
108- . next ( )
109- . expect ( "Erreur de lecture" )
110- . expect ( "Erreur de lecture" )
111- . trim ( )
112- . to_lowercase ( ) ;
113-
114- if add_pokemon == "y" {
115- add_pokemon_from_input ( & mut dex) ;
116- println ! ( "Pokémon ajouté avec succès !" ) ;
117- } else {
118- println ! ( "Aucun Pokémon ajouté." ) ;
119- }
120-
121- println ! ( "Afficher les pokemons ? y/n" ) ;
122-
123- let display_pokemon = io:: stdin ( )
124- . lines ( )
125- . next ( )
126- . expect ( "Erreur de lecture" )
127- . expect ( "Erreur de lecture" )
128- . trim ( )
129- . to_lowercase ( ) ;
130-
131- if display_pokemon == "y" {
132- println ! ( "Affichage du Pokédex :" ) ;
133- print_pokedex ( & dex) ;
134- } else {
135- println ! ( "Affichage du Pokédex annulé." ) ;
104+ loop {
105+ println ! (
106+ "\n Bienvenue dans le pokedex ! \n \n 1 : Afficher le pokedex 2: Ajouter un pokemon 3: Quitter le programme\n \n Votre choix :"
107+ ) ;
108+
109+ let usr_choice = io:: stdin ( )
110+ . lines ( )
111+ . next ( )
112+ . expect ( "Erreur de lecture" )
113+ . expect ( "Erreur de lecture" ) ;
114+
115+ match usr_choice. trim ( ) . parse :: < u8 > ( ) {
116+ Ok ( 1 ) => {
117+ println ! ( "Affichage du Pokédex :" ) ;
118+ print_pokedex ( & dex) ;
119+ }
120+ Ok ( 2 ) => {
121+ add_pokemon_from_input ( & mut dex) ;
122+ println ! ( "\n Pokémon ajouté avec succès !" ) ;
123+ }
124+ Ok ( 3 ) => {
125+ break ;
126+ }
127+ _ => println ! ( "\n Choix invalide, veuillez réessayer." ) ,
128+ }
136129 }
137-
138- println ! ( "\n Appuyez sur Entrée pour quitter..." ) ;
139- io:: stdout ( ) . flush ( ) . unwrap ( ) ; // s'assurer que le texte s'affiche avant de bloquer
140- let _ = io:: stdin ( ) . read_line ( & mut String :: new ( ) ) ;
130+ println ! ( "Fermeture du programme..." ) ;
141131}
0 commit comments