diff options
author | David Li <li.davidm96@gmail.com> | 2015-12-10 17:29:50 -0500 |
---|---|---|
committer | David Li <li.davidm96@gmail.com> | 2015-12-10 17:29:50 -0500 |
commit | 29020b56ac8377b88f2065874bebfaced75e312e (patch) | |
tree | cdb77ac6e91795478c41625a16675c011916ac5d /src/inhabitant.rs |
Diffstat (limited to 'src/inhabitant.rs')
-rw-r--r-- | src/inhabitant.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/inhabitant.rs b/src/inhabitant.rs new file mode 100644 index 0000000..2ed7de7 --- /dev/null +++ b/src/inhabitant.rs @@ -0,0 +1,46 @@ +use std::fmt; + +use coordinate; + +#[derive(Clone)] +pub enum Inhabitant { + Critter { + species: String, + offense: i32, + defense: i32, + size: i32, + energy: u32, + posture: i32, + position: coordinate::Coordinate, + direction: coordinate::Direction, + }, + Nothing, + Rock, + Food { + amount: i32, + }, +} + +impl fmt::Debug for Inhabitant { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + Inhabitant::Nothing => write!(f, "__"), + Inhabitant::Rock => write!(f, "RR"), + Inhabitant::Food { amount: amount } => { + if amount < 50 { + write!(f, "ff") + } + else if amount < 100 { + write!(f, "fF") + } + else if amount < 200 { + write!(f, "Ff") + } + else { + write!(f, "FF") + } + }, + Inhabitant::Critter {..} => write!(f, "CC") + } + } +} |