summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2021-01-31 20:45:17 +0100
committerTom Barrett <tom@tombarrett.xyz>2021-01-31 20:45:17 +0100
commitbc40572efd3858ff3dee3c5ab57e3c8922568c80 (patch)
tree07bf86eb89a30a138d035750ad6c54a501ad89b3
parent27e699fb40acaa72c7a28f0ef99a8a9427be81d9 (diff)
removes combo'd parts
-rw-r--r--src/main.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 2bd1ef0..4c2fdf8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -18,13 +18,14 @@ pub const BORDER_SIZE: f32 = 3.0;
pub const SHIFT_X: f32 = 50.0;
pub const SHIFT_Y: f32 = 50.0;
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, PartialEq)]
enum Occupant {
None,
Green,
Yellow,
Diamond,
Red,
+ Explosion,
}
impl Distribution<Occupant> for Standard {
@@ -88,6 +89,7 @@ impl Cell {
pub fn draw(&self, context: &mut Context, spritebatch: &mut SpriteBatch) -> GameResult {
let source = match self.occupant {
Occupant::None => None,
+ Occupant::Explosion => None,
Occupant::Green => Some(Rect::new(0.0, 0.0, 0.25, 1.0)),
Occupant::Yellow => Some(Rect::new(0.25, 0.0, 0.25, 1.0)),
Occupant::Diamond => Some(Rect::new(0.50, 0.0, 0.25, 1.0)),
@@ -222,6 +224,32 @@ impl EventHandler for Game {
}
}
+ let mut last = Occupant::None;
+ let mut connected = Vec::new();
+ for (i, row) in self.grid.iter_mut().enumerate() {
+ let mut c = Vec::new();
+ for (j, cell) in row.iter_mut().enumerate() {
+ if cell.occupant == last {
+ c.push((i, j));
+ c.push((i, j - 1));
+ } else {
+ connected.push(c.clone());
+ c.clear();
+ }
+ last = cell.occupant;
+ }
+ connected.push(c);
+ last = Occupant::None;
+ }
+
+ for c in connected.iter() {
+ if c.len() > 3 {
+ for (i, j) in c.iter() {
+ self.grid[*i][*j].occupant = Occupant::Explosion;
+ }
+ }
+ }
+
Ok(())
}