1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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")
}
}
}
|