diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs index 0fa52ab..18dd403 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,6 +73,14 @@ impl Cell { false } + pub fn moveable(&self) -> bool { + match self.occupant { + Occupant::Explosion { .. } => false, + Occupant::None => false, + _ => true, + } + } + pub fn clicked_on(&mut self) { self.clicked = true; } @@ -248,13 +256,16 @@ impl Game { } fn update_dropping(&mut self) { - /* - for (i, row) in self.grid.iter_mut().enumerate() { - for (j, cell) in row.iter_mut().enumerate() { - println!("a"); + for i in 1..COLUMNS { + for j in 0..ROWS { + if self.grid[i][j].occupant == Occupant::None + && self.grid[i - 1][j].occupant != Occupant::None + { + self.grid[i][j].occupant = self.grid[i - 1][j].occupant; + self.grid[i - 1][j].occupant = Occupant::None; + } } } - */ } fn update_frames(&mut self) { @@ -319,7 +330,7 @@ impl EventHandler for Game { let position = Point2 { x, y }; for (i, row) in self.grid.iter_mut().enumerate() { for (j, cell) in row.iter_mut().enumerate() { - if cell.contains(position) { + if cell.contains(position) && cell.moveable() { self.selected = Some((i, j)); cell.clicked_on(); } @@ -348,6 +359,7 @@ impl EventHandler for Game { for (i, row) in self.grid.iter_mut().enumerate() { for (j, cell) in row.iter_mut().enumerate() { if cell.contains(position) + && cell.moveable() && (((i + 1 == selected.0) && (j == selected.1)) || ((i.overflowing_sub(1).0 == selected.0) && (j == selected.1)) || ((i == selected.0) && (j + 1 == selected.1)) |