@@ -67,6 +67,28 @@ fn init_pokedex() -> Pokedex {
6767 dex
6868}
6969
70+ fn add_pokemon_from_input ( dex : & mut Pokedex ) {
71+ println ! ( "Entrez le nom du Pokémon :" ) ;
72+ let nom = io:: stdin ( )
73+ . lines ( )
74+ . next ( )
75+ . expect ( "Erreur de lecture" )
76+ . expect ( "Erreur de lecture" )
77+ . trim ( )
78+ . to_string ( ) ;
79+
80+ println ! ( "Entrez le type du Pokémon :" ) ;
81+ let p_type = io:: stdin ( )
82+ . lines ( )
83+ . next ( )
84+ . expect ( "Erreur de lecture" )
85+ . expect ( "Erreur de lecture" )
86+ . trim ( )
87+ . to_string ( ) ;
88+
89+ add_pokemon ( dex, & p_type, & nom) ;
90+ }
91+
7092#[ derive( Debug ) ]
7193struct Pokemon {
7294 nom : String ,
@@ -84,11 +106,28 @@ impl Pokemon {
84106
85107fn main ( ) {
86108 println ! ( "initialisation du pokedex..." ) ;
87- let dex = init_pokedex ( ) ;
109+ let mut dex = init_pokedex ( ) ;
88110
89111 let total_pokemon: usize = dex. values ( ) . map ( |set| set. len ( ) ) . sum ( ) ;
90112
91- println ! ( "Pokedex initialisé avec {total_pokemon} Pokémon !" ) ;
113+ println ! ( "Pokedex initialisé avec les {total_pokemon} Pokémon de la gen 1 !" ) ;
114+
115+ println ! ( "Voulez-vous ajouter un Pokémon ? y/n" ) ;
116+
117+ let add_pokemon = io:: stdin ( )
118+ . lines ( )
119+ . next ( )
120+ . expect ( "Erreur de lecture" )
121+ . expect ( "Erreur de lecture" )
122+ . trim ( )
123+ . to_lowercase ( ) ;
124+
125+ if add_pokemon == "y" {
126+ add_pokemon_from_input ( & mut dex) ;
127+ println ! ( "Pokémon ajouté avec succès !" ) ;
128+ } else {
129+ println ! ( "Aucun Pokémon ajouté." ) ;
130+ }
92131
93132 println ! ( "Afficher les pokemons ? y/n" ) ;
94133
0 commit comments