summaryrefslogtreecommitdiff
path: root/src/actions.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@gmail.com>2017-05-13 19:19:06 +0200
committerJustin Worthe <justin.worthe@gmail.com>2017-05-13 19:19:06 +0200
commit36b72bfef7b7b8dea94546d11704ec529091bce1 (patch)
tree4a8cdae81db3ab44aa946046bbfbb87f96c360c5 /src/actions.rs
parent27682d0ab246af8d0375853fdea44c38de2c2db4 (diff)
Split into smaller portions
Diffstat (limited to 'src/actions.rs')
-rw-r--r--src/actions.rs22
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))
+ }
+ }
+}
+