Skip to content

Commit 3473403

Browse files
committed
first commit
0 parents  commit 3473403

File tree

6 files changed

+367
-0
lines changed

6 files changed

+367
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

Cargo.lock

Lines changed: 92 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "pokedex"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
colored = "3.0.0"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# rust-dex

src/gen1.rs

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
use crate::Pokemon;
2+
3+
pub fn gen1_pokedex() -> Vec<Pokemon> {
4+
vec![
5+
Pokemon::new("Bulbizarre", "plante"),
6+
Pokemon::new("Herbizarre", "plante"),
7+
Pokemon::new("Florizarre", "plante"),
8+
Pokemon::new("Salamèche", "feu"),
9+
Pokemon::new("Reptincel", "feu"),
10+
Pokemon::new("Dracaufeu", "feu"),
11+
Pokemon::new("Carapuce", "eau"),
12+
Pokemon::new("Carabaffe", "eau"),
13+
Pokemon::new("Tortank", "eau"),
14+
Pokemon::new("Chenipan", "insecte"),
15+
Pokemon::new("Chrysacier", "insecte"),
16+
Pokemon::new("Papilusion", "insecte"),
17+
Pokemon::new("Aspicot", "insecte"),
18+
Pokemon::new("Coconfort", "insecte"),
19+
Pokemon::new("Dardargnan", "insecte"),
20+
Pokemon::new("Roucool", "normal"),
21+
Pokemon::new("Roucoups", "normal"),
22+
Pokemon::new("Roucarnage", "normal"),
23+
Pokemon::new("Rattata", "normal"),
24+
Pokemon::new("Rattatac", "normal"),
25+
Pokemon::new("Piafabec", "normal"),
26+
Pokemon::new("Rapasdepic", "normal"),
27+
Pokemon::new("Abo", "poison"),
28+
Pokemon::new("Arbok", "poison"),
29+
Pokemon::new("Pikachu", "électrique"),
30+
Pokemon::new("Raichu", "électrique"),
31+
Pokemon::new("Sabelette", "sol"),
32+
Pokemon::new("Sablaireau", "sol"),
33+
Pokemon::new("Nidoran♀", "poison"),
34+
Pokemon::new("Nidorina", "poison"),
35+
Pokemon::new("Nidoqueen", "poison"),
36+
Pokemon::new("Nidoran♂", "poison"),
37+
Pokemon::new("Nidorino", "poison"),
38+
Pokemon::new("Nidoking", "poison"),
39+
Pokemon::new("Mélofée", "fée"),
40+
Pokemon::new("Mélodelfe", "fée"),
41+
Pokemon::new("Goupix", "feu"),
42+
Pokemon::new("Feunard", "feu"),
43+
Pokemon::new("Rondoudou", "normal"),
44+
Pokemon::new("Grodoudou", "normal"),
45+
Pokemon::new("Nosferapti", "poison"),
46+
Pokemon::new("Nosferalto", "poison"),
47+
Pokemon::new("Mystherbe", "plante"),
48+
Pokemon::new("Ortide", "plante"),
49+
Pokemon::new("Rafflesia", "plante"),
50+
Pokemon::new("Paras", "insecte"),
51+
Pokemon::new("Parasect", "insecte"),
52+
Pokemon::new("Mimitoss", "insecte"),
53+
Pokemon::new("Aéromite", "insecte"),
54+
Pokemon::new("Taupiqueur", "sol"),
55+
Pokemon::new("Triopikeur", "sol"),
56+
Pokemon::new("Miaouss", "normal"),
57+
Pokemon::new("Persian", "normal"),
58+
Pokemon::new("Psykokwak", "eau"),
59+
Pokemon::new("Akwakwak", "eau"),
60+
Pokemon::new("Férosinge", "combat"),
61+
Pokemon::new("Colossinge", "combat"),
62+
Pokemon::new("Caninos", "feu"),
63+
Pokemon::new("Arcanin", "feu"),
64+
Pokemon::new("Ptitard", "eau"),
65+
Pokemon::new("Têtarte", "eau"),
66+
Pokemon::new("Tartard", "eau"),
67+
Pokemon::new("Abra", "psy"),
68+
Pokemon::new("Kadabra", "psy"),
69+
Pokemon::new("Alakazam", "psy"),
70+
Pokemon::new("Machoc", "combat"),
71+
Pokemon::new("Machopeur", "combat"),
72+
Pokemon::new("Mackogneur", "combat"),
73+
Pokemon::new("Chétiflor", "plante"),
74+
Pokemon::new("Boustiflor", "plante"),
75+
Pokemon::new("Empiflor", "plante"),
76+
Pokemon::new("Tentacool", "eau"),
77+
Pokemon::new("Tentacruel", "eau"),
78+
Pokemon::new("Racaillou", "roche"),
79+
Pokemon::new("Gravalanch", "roche"),
80+
Pokemon::new("Grolem", "roche"),
81+
Pokemon::new("Ponyta", "feu"),
82+
Pokemon::new("Galopa", "feu"),
83+
Pokemon::new("Ramoloss", "eau"),
84+
Pokemon::new("Flagadoss", "eau"),
85+
Pokemon::new("Magnéti", "électrique"),
86+
Pokemon::new("Magnéton", "électrique"),
87+
Pokemon::new("Canarticho", "normal"),
88+
Pokemon::new("Doduo", "normal"),
89+
Pokemon::new("Dodrio", "normal"),
90+
Pokemon::new("Otaria", "eau"),
91+
Pokemon::new("Lamantine", "eau"),
92+
Pokemon::new("Tadmorv", "poison"),
93+
Pokemon::new("Grotadmorv", "poison"),
94+
Pokemon::new("Kokiyas", "eau"),
95+
Pokemon::new("Crustabri", "eau"),
96+
Pokemon::new("Fantominus", "spectre"),
97+
Pokemon::new("Spectrum", "spectre"),
98+
Pokemon::new("Ectoplasma", "spectre"),
99+
Pokemon::new("Onix", "roche"),
100+
Pokemon::new("Soporifik", "psy"),
101+
Pokemon::new("Hypnomade", "psy"),
102+
Pokemon::new("Krabby", "eau"),
103+
Pokemon::new("Krabboss", "eau"),
104+
Pokemon::new("Voltorbe", "électrique"),
105+
Pokemon::new("Électrode", "électrique"),
106+
Pokemon::new("Noeunoeuf", "plante"),
107+
Pokemon::new("Noadkoko", "plante"),
108+
Pokemon::new("Osselait", "sol"),
109+
Pokemon::new("Ossatueur", "sol"),
110+
Pokemon::new("Kicklee", "combat"),
111+
Pokemon::new("Tygnon", "combat"),
112+
Pokemon::new("Excelangue", "normal"),
113+
Pokemon::new("Smogo", "poison"),
114+
Pokemon::new("Smogogo", "poison"),
115+
Pokemon::new("Rhinocorne", "sol"),
116+
Pokemon::new("Rhinoféros", "sol"),
117+
Pokemon::new("Leveinard", "normal"),
118+
Pokemon::new("Saquedeneu", "plante"),
119+
Pokemon::new("Kangourex", "normal"),
120+
Pokemon::new("Hypotrempe", "eau"),
121+
Pokemon::new("Hypocéan", "eau"),
122+
Pokemon::new("Poissirène", "eau"),
123+
Pokemon::new("Poissoroy", "eau"),
124+
Pokemon::new("Stari", "eau"),
125+
Pokemon::new("Staross", "eau"),
126+
Pokemon::new("M. Mime", "psy"),
127+
Pokemon::new("Insécateur", "insecte"),
128+
Pokemon::new("Lippoutou", "glace"),
129+
Pokemon::new("Élektek", "électrique"),
130+
Pokemon::new("Magmar", "feu"),
131+
Pokemon::new("Scarabrute", "insecte"),
132+
Pokemon::new("Tauros", "normal"),
133+
Pokemon::new("Magicarpe", "eau"),
134+
Pokemon::new("Léviator", "eau"),
135+
Pokemon::new("Lokhlass", "eau"),
136+
Pokemon::new("Métamorph", "normal"),
137+
Pokemon::new("Évoli", "normal"),
138+
Pokemon::new("Aquali", "eau"),
139+
Pokemon::new("Voltali", "électrique"),
140+
Pokemon::new("Pyroli", "feu"),
141+
Pokemon::new("Porygon", "normal"),
142+
Pokemon::new("Amonita", "roche"),
143+
Pokemon::new("Amonistar", "roche"),
144+
Pokemon::new("Kabuto", "roche"),
145+
Pokemon::new("Kabutops", "roche"),
146+
Pokemon::new("Ptéra", "roche"),
147+
Pokemon::new("Ronflex", "normal"),
148+
Pokemon::new("Artikodin", "glace"),
149+
Pokemon::new("Électhor", "électrique"),
150+
Pokemon::new("Sulfura", "feu"),
151+
Pokemon::new("Minidraco", "dragon"),
152+
Pokemon::new("Draco", "dragon"),
153+
Pokemon::new("Dracolosse", "dragon"),
154+
Pokemon::new("Mewtwo", "psy"),
155+
Pokemon::new("Mew", "psy"),
156+
]
157+
}

src/main.rs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
use colored::*;
2+
use std::collections::{HashMap, HashSet};
3+
use std::io::{self};
4+
mod gen1;
5+
6+
type Pokedex = HashMap<String, HashSet<String>>;
7+
8+
fn add_pokemon(dex: &mut Pokedex, p_type: &str, nom: &str) {
9+
dex.entry(p_type.to_string())
10+
.or_default()
11+
.insert(nom.to_string());
12+
}
13+
14+
fn print_pokedex(dex: &Pokedex) {
15+
let mut types: Vec<_> = dex.keys().collect();
16+
types.sort();
17+
18+
for t in types {
19+
let colorized_type = match t.as_str() {
20+
"feu" => t.red(),
21+
"eau" => t.blue(),
22+
"plante" => t.green(),
23+
"électrique" => t.yellow(),
24+
"dragon" => t.purple(),
25+
"fée" => t.magenta(),
26+
"combat" => t.bright_cyan(),
27+
"glace" => t.bright_white(),
28+
"insecte" => t.bright_green(),
29+
"poison" => t.bright_red(),
30+
"roche" => t.bright_yellow(),
31+
"psy" => t.bright_blue(),
32+
"spectre" => t.bright_magenta(),
33+
"sol" => t.bright_black(),
34+
_ => t.white(),
35+
};
36+
37+
println!("{}", colorized_type.bold());
38+
39+
let mut pokemons: Vec<_> = dex[t].iter().collect();
40+
pokemons.sort();
41+
42+
for p in pokemons {
43+
println!(" - {}", p);
44+
}
45+
46+
println!();
47+
}
48+
}
49+
50+
fn add_from_struct(dex: &mut Pokedex, p: &Pokemon) {
51+
add_pokemon(dex, &p.p_type, &p.nom);
52+
}
53+
54+
fn add_many_pokemon_from_struct(dex: &mut Pokedex, pokemons: Vec<Pokemon>) {
55+
for p in pokemons {
56+
add_from_struct(dex, &p);
57+
}
58+
}
59+
60+
fn init_pokedex() -> Pokedex {
61+
let mut dex: Pokedex = HashMap::new();
62+
63+
let list_pokemon = gen1::gen1_pokedex();
64+
65+
add_many_pokemon_from_struct(&mut dex, list_pokemon);
66+
67+
dex
68+
}
69+
70+
#[derive(Debug)]
71+
struct Pokemon {
72+
nom: String,
73+
p_type: String,
74+
}
75+
76+
impl Pokemon {
77+
fn new(nom: &str, p_type: &str) -> Self {
78+
Self {
79+
nom: nom.to_string(),
80+
p_type: p_type.to_string(),
81+
}
82+
}
83+
}
84+
85+
fn main() {
86+
println!("initialisation du pokedex...");
87+
let dex = init_pokedex();
88+
89+
let total_pokemon: usize = dex.values().map(|set| set.len()).sum();
90+
91+
println!("Pokedex initialisé avec {total_pokemon} Pokémon !");
92+
93+
println!("Afficher les pokemons ? y/n");
94+
95+
let display_pokemon = io::stdin()
96+
.lines()
97+
.next()
98+
.expect("Erreur de lecture")
99+
.expect("Erreur de lecture")
100+
.trim()
101+
.to_lowercase();
102+
103+
if display_pokemon == "y" {
104+
println!("Affichage du Pokédex :");
105+
print_pokedex(&dex);
106+
} else {
107+
println!("Affichage du Pokédex annulé.");
108+
}
109+
}

0 commit comments

Comments
 (0)