From bc40572efd3858ff3dee3c5ab57e3c8922568c80 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Sun, 31 Jan 2021 20:45:17 +0100 Subject: removes combo'd parts --- src/main.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/main.rs') 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 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(()) } -- cgit v1.2.3