Enum pokelab::pokemon::eevee::EvolvedEevee
source · pub enum EvolvedEevee {
Vaporeon(Eevee, u16),
Flareon(Eevee, u16),
Leafeon(Eevee, u16),
}
Expand description
This type represent an evolved Eevee in the form of either Vaporeon, Flareon, or Leafeon.
An EvolvedEevee
contains an inner Eevee
as well as a secondary attribute value.
This attribute value changes one of the inner Eevee
’s base stats depending on which
of the 3 types the EvolvedEevee
is.
Variants§
Vaporeon(Eevee, u16)
The secondary attribute for Vaporeon
is added to the base health.
Flareon(Eevee, u16)
The secondary attribute for Flareon
is added to the base attack.
Leafeon(Eevee, u16)
The secondary attribute for Leafeon
is added to the base defense.
Implementations§
source§impl EvolvedEevee
impl EvolvedEevee
There’s a lot of boiler plate code here that we’ll implement for you.
All you need to do is implement
take_damage
and devolve
.
In all honesty, if you had to actually implement this logic, you would probably have each
EvolvedEevee
variant be its own standalone type,
each implementing something called a trait.
However, we haven’t talked about traits yet, so stay tuned till week 5!
pub fn get_level(&self) -> u8
pub fn get_health(&self) -> u16
pub fn get_attack(&self) -> u16
pub fn get_defense(&self) -> u16
pub fn set_secondary_attribute(&mut self, extra: u16)
sourcepub fn take_damage(&mut self, damage: u16)
pub fn take_damage(&mut self, damage: u16)
Deals damage
amount of damage to the EvolvedEevee
’s health.
This is similar to Eevee::take_damage
,
but the logic is slightly different for Vaporeon
and Flareon
, since they have
extra health and extra defense, respectively.
For Vaporeon, you will want to apply the damage to the extra health,
until the extra health runs out. For Leafeon, you apply the extra defense
on every take_damage
call.
It’s also fine to just panic with the same message, "Eevee fainted!"
.
let mut flareon = Eevee::new().evolve(ElementalStone::PyroStone);
flareon.take_damage(40);
assert_eq!(flareon.get_health(), 80);
let mut vaporeon = Eevee::new().evolve(ElementalStone::HydroStone);
vaporeon.set_secondary_attribute(20); // Adds 20 extra health
vaporeon.take_damage(40);
assert_eq!(vaporeon.get_health(), 100);
let mut leafeon = Eevee::new().evolve(ElementalStone::MossyStone);
leafeon.set_secondary_attribute(5); // Adds 5 extra defense
for _ in 0..100 {
leafeon.take_damage(25);
}
assert_eq!(leafeon.get_health(), 100);
sourcepub fn devolve(self) -> Eevee
pub fn devolve(self) -> Eevee
Devolves an EvolvedEevee
into an Eevee
.
Note that base stats like health should not change even after devolving.
let leafeon = Eevee::new().evolve(ElementalStone::MossyStone);
assert!(matches!(leafeon, EvolvedEevee::Leafeon(_, _)));
let back_to_eevee: Eevee = leafeon.devolve();
Trait Implementations§
source§impl Debug for EvolvedEevee
impl Debug for EvolvedEevee
source§impl PartialEq<EvolvedEevee> for EvolvedEevee
impl PartialEq<EvolvedEevee> for EvolvedEevee
source§fn eq(&self, other: &EvolvedEevee) -> bool
fn eq(&self, other: &EvolvedEevee) -> bool
self
and other
values to be equal, and is used
by ==
.