Skip to content

Commit

Permalink
wip 1
Browse files Browse the repository at this point in the history
  • Loading branch information
yttersian committed Feb 17, 2025
1 parent 5052134 commit ee66365
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 235 deletions.
118 changes: 37 additions & 81 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ version = "0.1.0"
edition = "2021"

[dependencies]
rand = "0.8.5"
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.135"
82 changes: 78 additions & 4 deletions src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,68 @@ use crate::types::PokemonType;

use crate::moves::{Move, MoveCategory};

fn load_pokemon_db() {
todo!();
#[non_exhaustive]
enum EvolutionItem {
FireStone,
WaterStone,
ThunderStone,
}

enum EvolutionCondition {
Level(u8),
Item(EvolutionItem),
}

struct EvolutionPath {
evolves_to: SpeciesId,
condition: EvolutionCondition,
}

pub struct SpeciesId(u16);

pub struct Species {
species_id: SpeciesId,
base_stats: Stats,
types: Vec<PokemonType>,
learnset: Vec<(u8, Move)>,
evolutions: Vec<EvolutionPath>,
}

impl Species {
pub fn new(
species_id: SpeciesId,
base_stats: Stats,
types: Vec<PokemonType>,
learnset: Vec<(u8, Move)>,
evolutions: Vec<EvolutionPath>,
) -> Self {
Self {
species_id,
base_stats,
types,
learnset,
evolutions,
}
}
}

pub fn load_pokemon_db() -> String {
let data = std::fs::read_to_string("./src/data/pokemon_db.json")
.expect("Unable to read Pokemon database");
// let pokemon_db: HashMap<String, Pokemon> =

data
}

pub fn get_pokemon(species: &str) -> Pokemon {
let types: Vec<PokemonType>;
let stats: Stats;
let moves: Vec<Move>;
let evolutions: Vec<EvolutionPath>;
let learnset: Vec<(u8, &str)>;

match species {
"Bulbasaur" => {
types = vec![PokemonType::Grass];
stats = Stats {
max_hp: 45,
attack: 49,
Expand All @@ -23,11 +73,15 @@ pub fn get_pokemon(species: &str) -> Pokemon {
special_defense: 65,
speed: 45,
};
types = vec![PokemonType::Grass];
moves = vec![get_move("Tackle"), get_move("Vine Whip")];
evolutions = vec![EvolutionPath {
evolves_to: SpeciesId(2), // Ivysaur
condition: EvolutionCondition::Level(16),
}];
}

"Pikachu" => {
types = vec![PokemonType::Electric];
stats = Stats {
max_hp: 35,
attack: 55,
Expand All @@ -36,7 +90,27 @@ pub fn get_pokemon(species: &str) -> Pokemon {
special_defense: 40,
speed: 90,
};
types = vec![PokemonType::Electric];
moves = vec![get_move("Tackle"), get_move("Thunderbolt")];
evolutions = vec![EvolutionPath {
evolves_to: SpeciesId(26), // Raichu
condition: EvolutionCondition::Item(EvolutionItem::ThunderStone),
}];
learnset = vec![
(1, "Thunder Shock"),
(1, "Growl"),
(5, "Tail Whip"),
(10, "Thunder Wave"),
(13, "Quick Attack"),
(18, "Double Team"),
(21, "Slam"),
(26, "Thunderbolt"),
(29, "Feint"),
(34, "Agility"),
(35, "Discharge"),
(42, "Light Screen"),
(45, "Thunder"),
];
}

_ => unimplemented!("The Pokemon '{}' is not implemented.", species),
Expand Down
20 changes: 16 additions & 4 deletions src/data/pokemon_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@
"types": [
"Grass"
],
"moves": [
"Vine Whip",
"Tackle"
],
"moves": {
"level_up": [
{
"level": 1,
"move": "Tackle"
},
{
"level": 1,
"move": "Growl"
},
{
"level": 3,
"move": "Vine Whip"
}
]
},
"evolves_to": {
"pokemon": "Ivysaur",
"level_required": 16
Expand Down
9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(dead_code, unused)]
// #![allow(dead_code, unused)]

// mod battle;
mod constants;
Expand All @@ -21,8 +21,9 @@ fn main() {
leaf.add_pokemon(get_pokemon("Bulbasaur"));
red.add_pokemon(get_pokemon("Pikachu"));

dbg!(leaf);
dbg!(red);
println!("{:?}", leaf);

// start_battle(&mut leaf, &mut red);
// let db = data::load_pokemon_db();

// println!("{db}");
}
Loading

0 comments on commit ee66365

Please sign in to comment.