use crate::genetics::{Genetic, Transcriber}; use super::stats::Stat; #[derive(Default)] pub struct Parts { stare: Stat<'e', 'E', 0, 6>, fangs: Stat<'f', 'F', 0, 6>, wings: Stat<'w', 'W', 0, 6>, } impl Parts { pub fn profile(&self) -> String { format!("Species: {:?}\n", self.species()) } pub fn has_stare(&self) -> bool { return self.stare.value() >= 5; } pub fn has_fangs(&self) -> bool { return self.fangs.value() >= 5; } pub fn has_wings(&self) -> bool { return self.wings.value() >= 5; } pub fn species(&self) -> Species { let mut ix = 0; if self.has_stare() { ix += 4; } if self.has_fangs() { ix += 2; } if self.has_wings() { ix += 1; } use Species::*; return [Bunny, Pigeon, Rat, Dragon, Hare, Crow, Snake, Bat][ix]; } } impl Genetic for Parts { fn transcribe(&mut self, t: Transcriber) { self.stare.transcribe(t.nest("stare")); self.fangs.transcribe(t.nest("fangs")); self.wings.transcribe(t.nest("wings")); } } #[derive(Clone, Copy, Debug)] pub enum Species { Bunny, Pigeon, Rat, Dragon, Hare, Crow, Snake, Bat, }