summaryrefslogtreecommitdiff
path: root/src/command.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2019-06-24 21:04:27 +0200
committerJustin Worthe <justin@worthe-it.co.za>2019-06-24 21:04:27 +0200
commit1aeab6da05a0c7b7dad4d06a38b282a82d5e1a51 (patch)
treede76a41b53f4ba383bda118dfb97bd2ff53f7a23 /src/command.rs
parent6d6cb9e39c4ec3f113833042f1b7bc8082c5d650 (diff)
New command types for select and bombs
Diffstat (limited to 'src/command.rs')
-rw-r--r--src/command.rs39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/command.rs b/src/command.rs
index 81e3d67..1ffdd35 100644
--- a/src/command.rs
+++ b/src/command.rs
@@ -3,20 +3,53 @@ use crate::geometry::Direction;
use crate::geometry::Point2d;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
-pub enum Command {
+pub struct Command {
+ pub worm: Option<i32>,
+ pub action: Action
+}
+
+impl fmt::Display for Command {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self.worm {
+ Some(worm) => write!(f, "select {};{}", worm, self.action),
+ None => write!(f, "{}", self.action)
+ }
+ }
+}
+
+impl Command {
+ pub fn with_select(worm: i32, action: Action) -> Command {
+ Command {
+ worm: Some(worm),
+ action
+ }
+ }
+
+ pub fn new(action: Action) -> Command {
+ Command {
+ worm: None,
+ action
+ }
+ }
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+pub enum Action {
Move(Point2d<i8>),
Dig(Point2d<i8>),
Shoot(Direction),
+ Bomb(Point2d<i8>),
DoNothing,
}
-impl fmt::Display for Command {
+impl fmt::Display for Action {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use Command::*;
+ use Action::*;
match self {
Move(p) => write!(f, "move {} {}", p.x, p.y),
Dig(p) => write!(f, "dig {} {}", p.x, p.y),
Shoot(dir) => write!(f, "shoot {}", dir),
+ Bomb(p) => write!(f, "banana {} {}", p.x, p.y),
DoNothing => write!(f, "nothing"),
}
}