diff options
Diffstat (limited to 'src/actions.rs')
-rw-r--r-- | src/actions.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/actions.rs b/src/actions.rs new file mode 100644 index 0000000..a7f61b5 --- /dev/null +++ b/src/actions.rs @@ -0,0 +1,22 @@ +use math::*; +use ships::*; + +use std::fmt; + +#[derive(Clone, PartialEq, Eq, Debug)] +pub enum Action { + PlaceShips(Vec<(Ship, Point, Orientation)>), + Shoot(Point) +} + +impl fmt::Display for Action { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + &Action::Shoot(p) => writeln!(f, "1,{},{}", p.x, p.y), + &Action::PlaceShips(ref ships) => ships.iter().map(|&(ref ship_type, p, orientation)| { + writeln!(f, "{} {} {} {}", ship_type, p.x, p.y, orientation) + }).fold(Ok(()), |acc, next| acc.and(next)) + } + } +} + |