Simple genetic simulator, 1
This commit is contained in:
64
src/creature/species.rs
Normal file
64
src/creature/species.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
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,
|
||||
}
|
||||
Reference in New Issue
Block a user