From 29020b56ac8377b88f2065874bebfaced75e312e Mon Sep 17 00:00:00 2001 From: David Li Date: Thu, 10 Dec 2015 17:29:50 -0500 Subject: Initial commit --- src/inhabitant.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/inhabitant.rs (limited to 'src/inhabitant.rs') 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") + } + } +} -- cgit v1.2.3