summaryrefslogtreecommitdiff
path: root/src/shooting.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@gmail.com>2017-05-13 21:43:27 +0200
committerJustin Worthe <justin.worthe@gmail.com>2017-05-13 21:43:27 +0200
commit05ccf5572b39fe254c7b0464cc78a1b623f732c7 (patch)
tree723d35b3eca744d5739174bfe965df12cd678fe1 /src/shooting.rs
parent872529bc9a13b1923047a7f9308abaa40eb63d3c (diff)
Added checking if state is in use before shooting
Diffstat (limited to 'src/shooting.rs')
-rw-r--r--src/shooting.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/shooting.rs b/src/shooting.rs
index 14f2b81..c2ca56e 100644
--- a/src/shooting.rs
+++ b/src/shooting.rs
@@ -1,6 +1,16 @@
use actions::*;
use math::*;
+use state::*;
-pub fn shoot_randomly(map_size: u16) -> Action {
- Action::Shoot(Point::random(map_size))
+pub fn shoot_randomly(state: &State) -> Action {
+ let mut shot: Point;
+
+ while {
+ shot = Point::random(state.map_size);
+ let ref target = state.opponent_map.cells[shot.x as usize][shot.y as usize];
+ target.damaged || target.missed
+ } {}
+
+
+ Action::Shoot(shot)
}