mirror of
https://github.com/LukasKalbertodt/programmieren-in-rust.git
synced 2025-06-30 00:27:31 +02:00
Rename sheet folders to assure proper sorting
This commit is contained in:
169
aufgaben/sheet05/sol1/src/db/data.rs
Executable file
169
aufgaben/sheet05/sol1/src/db/data.rs
Executable file
@ -0,0 +1,169 @@
|
||||
use db::types::*;
|
||||
|
||||
|
||||
pub const POKEDEX: &'static [PokemonModel] = &[
|
||||
PokemonModel {
|
||||
name: "Bulbasaur",
|
||||
id: 001,
|
||||
type_: PokemonType::Two(Type::Poison, Type::Grass),
|
||||
base_stats: Stats {
|
||||
hp: 45,
|
||||
attack: 49,
|
||||
defense: 49,
|
||||
special_attack: 65,
|
||||
special_defense: 65,
|
||||
speed: 45,
|
||||
},
|
||||
attacks: &[TACKLE],
|
||||
},
|
||||
PokemonModel {
|
||||
name: "Ivysaur",
|
||||
id: 002,
|
||||
type_: PokemonType::Two(Type::Poison, Type::Grass),
|
||||
base_stats: Stats {
|
||||
hp: 60,
|
||||
attack: 62,
|
||||
defense: 63,
|
||||
special_attack: 80,
|
||||
special_defense: 80,
|
||||
speed: 60,
|
||||
},
|
||||
attacks: &[TACKLE, VINE_WHIP],
|
||||
},
|
||||
PokemonModel {
|
||||
name: "Venusaur",
|
||||
id: 003,
|
||||
type_: PokemonType::Two(Type::Poison, Type::Grass),
|
||||
base_stats: Stats {
|
||||
hp: 80,
|
||||
attack: 82,
|
||||
defense: 83,
|
||||
special_attack: 100,
|
||||
special_defense: 100,
|
||||
speed: 80,
|
||||
},
|
||||
attacks: &[TACKLE, VINE_WHIP],
|
||||
},
|
||||
PokemonModel {
|
||||
name: "Charmander",
|
||||
id: 004,
|
||||
type_: PokemonType::One(Type::Fire),
|
||||
base_stats: Stats {
|
||||
hp: 39,
|
||||
attack: 52,
|
||||
defense: 43,
|
||||
special_attack: 60,
|
||||
special_defense: 50,
|
||||
speed: 65,
|
||||
},
|
||||
attacks: &[TACKLE],
|
||||
},
|
||||
PokemonModel {
|
||||
name: "Charmeleon",
|
||||
id: 005,
|
||||
type_: PokemonType::One(Type::Fire),
|
||||
base_stats: Stats {
|
||||
hp: 58,
|
||||
attack: 64,
|
||||
defense: 58,
|
||||
special_attack: 80,
|
||||
special_defense: 65,
|
||||
speed: 80,
|
||||
},
|
||||
attacks: &[TACKLE, EMBER],
|
||||
},
|
||||
PokemonModel {
|
||||
name: "Charizard",
|
||||
id: 006,
|
||||
type_: PokemonType::Two(Type::Fire, Type::Flying),
|
||||
base_stats: Stats {
|
||||
hp: 78,
|
||||
attack: 84,
|
||||
defense: 78,
|
||||
special_attack: 109,
|
||||
special_defense: 85,
|
||||
speed: 100,
|
||||
},
|
||||
attacks: &[TACKLE, EMBER],
|
||||
},
|
||||
PokemonModel {
|
||||
name: "Squirtle",
|
||||
id: 007,
|
||||
type_: PokemonType::One(Type::Water),
|
||||
base_stats: Stats {
|
||||
hp: 44,
|
||||
attack: 48,
|
||||
defense: 65,
|
||||
special_attack: 50,
|
||||
special_defense: 64,
|
||||
speed: 43,
|
||||
},
|
||||
attacks: &[TACKLE],
|
||||
},
|
||||
PokemonModel {
|
||||
name: "Wartortle",
|
||||
id: 008,
|
||||
type_: PokemonType::One(Type::Water),
|
||||
base_stats: Stats {
|
||||
hp: 59,
|
||||
attack: 63,
|
||||
defense: 80,
|
||||
special_attack: 65,
|
||||
special_defense: 80,
|
||||
speed: 58,
|
||||
},
|
||||
attacks: &[TACKLE, WATER_GUN],
|
||||
},
|
||||
PokemonModel {
|
||||
name: "Blastoise",
|
||||
id: 009,
|
||||
type_: PokemonType::One(Type::Water),
|
||||
base_stats: Stats {
|
||||
hp: 79,
|
||||
attack: 83,
|
||||
defense: 100,
|
||||
special_attack: 85,
|
||||
special_defense: 105,
|
||||
speed: 78,
|
||||
},
|
||||
attacks: &[TACKLE, WATER_GUN],
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
/// List of all attacks.
|
||||
///
|
||||
/// Of course, these are not all attacks. We will probably provide a much
|
||||
/// bigger database with the next sheet.
|
||||
pub const ATTACK_DB: &'static [Attack] = &[
|
||||
Attack {
|
||||
category: AttackCategory::Physical,
|
||||
name: "Tackle",
|
||||
base_power: 50,
|
||||
type_: Type::Normal,
|
||||
},
|
||||
Attack {
|
||||
category: AttackCategory::Special,
|
||||
name: "Vine Whip",
|
||||
base_power: 45,
|
||||
type_: Type::Grass,
|
||||
},
|
||||
Attack {
|
||||
category: AttackCategory::Special,
|
||||
name: "Ember",
|
||||
base_power: 40,
|
||||
type_: Type::Fire,
|
||||
},
|
||||
Attack {
|
||||
category: AttackCategory::Special,
|
||||
name: "Water Gun",
|
||||
base_power: 40,
|
||||
type_: Type::Water,
|
||||
},
|
||||
];
|
||||
|
||||
// These are just some easy names to be more expressive in the Pokedex.
|
||||
pub const TACKLE: &'static Attack = &ATTACK_DB[0];
|
||||
pub const VINE_WHIP: &'static Attack = &ATTACK_DB[1];
|
||||
pub const EMBER: &'static Attack = &ATTACK_DB[2];
|
||||
pub const WATER_GUN: &'static Attack = &ATTACK_DB[3];
|
22
aufgaben/sheet05/sol1/src/db/mod.rs
Executable file
22
aufgaben/sheet05/sol1/src/db/mod.rs
Executable file
@ -0,0 +1,22 @@
|
||||
pub mod types;
|
||||
pub mod data;
|
||||
|
||||
pub use self::types::*;
|
||||
|
||||
|
||||
// pub fn pokemon_by_id(id: u16) -> Option<PokemonModel> {
|
||||
// match data::POKEDEX.get(id as usize) {
|
||||
// None => None,
|
||||
// Some(&pm) => Some(pm),
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn pokemon_by_name(name: &str) -> Option<PokemonModel> {
|
||||
for &pm in data::POKEDEX {
|
||||
if pm.name == name {
|
||||
return Some(pm);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
118
aufgaben/sheet05/sol1/src/db/types.rs
Executable file
118
aufgaben/sheet05/sol1/src/db/types.rs
Executable file
@ -0,0 +1,118 @@
|
||||
// This module defines types only. Not all fields or variants of those are
|
||||
// necessarily used, so we don't want all those warnings. This should be safe
|
||||
// since no algorithm is defined in this module (in which such a warning
|
||||
// could hint the existance of a bug).
|
||||
// #![allow(dead_code)]
|
||||
|
||||
/// Describes an attack with all its properties. This type is similar to
|
||||
/// `PokemonModel`, as there are finite many, immutable instances of this type
|
||||
/// in a database. This is not a type whose instances change over time.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Attack {
|
||||
pub category: AttackCategory,
|
||||
pub name: &'static str,
|
||||
/// Base power of the move. The actual inflicted damage is calculated with
|
||||
/// a formula using the move's power and a few other parameters.
|
||||
pub base_power: u8,
|
||||
pub type_: Type,
|
||||
}
|
||||
|
||||
/// Category of an attack.
|
||||
///
|
||||
/// Note: currently, the category 'status' is missing.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum AttackCategory {
|
||||
/// Attacks with body contact, like "Tackle" or "Bite"
|
||||
Physical,
|
||||
/// Attacks without body contact, like "Bubble Beam" or "Thunderbolt"
|
||||
Special,
|
||||
}
|
||||
|
||||
/// Describes how effective an attack of one type is on a Pokemon of another
|
||||
/// type.
|
||||
///
|
||||
/// Note that a Pokemon can have two types. In order to determine the
|
||||
/// effectiveness, the multipliers of the effectivenesses on both types
|
||||
/// are multiplied. As such, there can be 0.25 and 4.0 multipliers!
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum TypeEffectiveness {
|
||||
NotEffective,
|
||||
NotVeryEffective,
|
||||
Normal,
|
||||
SuperEffective,
|
||||
}
|
||||
|
||||
|
||||
/// Types (sometimes called "elements") of the Pokemon universe. Each
|
||||
/// attack-move has exactly one type, Pokemons can have one or two types.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[allow(dead_code)]
|
||||
pub enum Type {
|
||||
Normal,
|
||||
Fire,
|
||||
Fighting,
|
||||
Water,
|
||||
Flying,
|
||||
Grass,
|
||||
Poison,
|
||||
Electric,
|
||||
Ground,
|
||||
Psychic,
|
||||
Rock,
|
||||
Ice,
|
||||
Bug,
|
||||
Dragon,
|
||||
Ghost,
|
||||
Dark,
|
||||
Steel,
|
||||
Fairy,
|
||||
}
|
||||
|
||||
/// Describes the type of a Pokemon. Pokemon can have one or two types.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum PokemonType {
|
||||
One(Type),
|
||||
Two(Type, Type),
|
||||
}
|
||||
|
||||
/// Describes a kind of Pokemon, e.g. "Pikachu".
|
||||
///
|
||||
/// This is different than an actual, living Pokemon. This struct just
|
||||
/// describes properties that are the same for every creature of this
|
||||
/// Pokemon kind.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct PokemonModel {
|
||||
/// Name of the Pokemon
|
||||
pub name: &'static str,
|
||||
/// ID in the international Pokedex
|
||||
pub id: u16,
|
||||
pub type_: PokemonType,
|
||||
pub base_stats: Stats,
|
||||
/// This is different from the real Pokemon games: attacks are not part
|
||||
/// of the Pokemon model, but of the Pokemon itself (as they change over
|
||||
/// time). A pokemon just has an abstract learnset of potential attacks.
|
||||
/// But this is easier for now.
|
||||
pub attacks: &'static [&'static Attack]
|
||||
}
|
||||
|
||||
/// Describes the basic stats of a Pokemon.
|
||||
///
|
||||
/// Each living Pokemon has an actual stat value, but each Pokemon kind also
|
||||
/// has so called "base stats". These base stats are used to calculate the
|
||||
/// actual stats, whose depend on the Pokemon's current level. Stronger Pokemon
|
||||
/// have higher base stats.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Stats {
|
||||
/// Health points
|
||||
pub hp: u16,
|
||||
/// Speed, sometimes called initiative (INIT)
|
||||
pub speed: u16,
|
||||
/// Strength of physical attacks (like "Tackle")
|
||||
pub attack: u16,
|
||||
/// Strength of special attacks (like "Bubble Beam")
|
||||
pub special_attack: u16,
|
||||
/// Defense power against physical attacks (like "Tackle")
|
||||
pub defense: u16,
|
||||
/// Defense power against special attacks (like "Bubble Beam")
|
||||
pub special_defense: u16,
|
||||
}
|
Reference in New Issue
Block a user