summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs77
1 files changed, 39 insertions, 38 deletions
diff --git a/src/main.rs b/src/main.rs
index 4c2fdf8..cef5b84 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -17,6 +17,8 @@ pub const TILE_WIDTH: f32 = 16.0;
pub const BORDER_SIZE: f32 = 3.0;
pub const SHIFT_X: f32 = 50.0;
pub const SHIFT_Y: f32 = 50.0;
+pub const COLUMNS: usize = 8;
+pub const ROWS: usize = 8;
#[derive(Clone, Copy, PartialEq)]
enum Occupant {
@@ -158,41 +160,15 @@ impl Game {
let mut grid = Vec::new();
let mut y = 0.0;
- for _ in 0..8 {
- let mut column = Vec::new();
- column.push(Cell::new(Point2 {
- x: SHIFT_X,
- y: y + SHIFT_Y,
- }));
- column.push(Cell::new(Point2 {
- x: 1.0 * (TILE_WIDTH * TILE_SCALE + BORDER_SIZE) + SHIFT_X,
- y: y + SHIFT_Y,
- }));
- column.push(Cell::new(Point2 {
- x: 2.0 * (TILE_WIDTH * TILE_SCALE + BORDER_SIZE) + SHIFT_X,
- y: y + SHIFT_Y,
- }));
- column.push(Cell::new(Point2 {
- x: 3.0 * (TILE_WIDTH * TILE_SCALE + BORDER_SIZE) + SHIFT_X,
- y: y + SHIFT_Y,
- }));
- column.push(Cell::new(Point2 {
- x: 4.0 * (TILE_WIDTH * TILE_SCALE + BORDER_SIZE) + SHIFT_X,
- y: y + SHIFT_Y,
- }));
- column.push(Cell::new(Point2 {
- x: 5.0 * (TILE_WIDTH * TILE_SCALE + BORDER_SIZE) + SHIFT_X,
- y: y + SHIFT_Y,
- }));
- column.push(Cell::new(Point2 {
- x: 6.0 * (TILE_WIDTH * TILE_SCALE + BORDER_SIZE) + SHIFT_X,
- y: y + SHIFT_Y,
- }));
- column.push(Cell::new(Point2 {
- x: 7.0 * (TILE_WIDTH * TILE_SCALE + BORDER_SIZE) + SHIFT_X,
- y: y + SHIFT_Y,
- }));
+ for _ in 0..COLUMNS {
+ let mut column = Vec::new();
+ for j in 0..ROWS {
+ column.push(Cell::new(Point2 {
+ x: (j as f32) * (TILE_WIDTH * TILE_SCALE + BORDER_SIZE) + SHIFT_X,
+ y: y + SHIFT_Y,
+ }));
+ }
y += TILE_HEIGHT * TILE_SCALE + BORDER_SIZE;
grid.push(column);
}
@@ -226,17 +202,17 @@ impl EventHandler for Game {
let mut last = Occupant::None;
let mut connected = Vec::new();
- for (i, row) in self.grid.iter_mut().enumerate() {
+ for i in 0..COLUMNS {
let mut c = Vec::new();
- for (j, cell) in row.iter_mut().enumerate() {
- if cell.occupant == last {
+ for j in 0..ROWS {
+ if self.grid[i][j].occupant == last {
c.push((i, j));
c.push((i, j - 1));
} else {
connected.push(c.clone());
c.clear();
}
- last = cell.occupant;
+ last = self.grid[i][j].occupant;
}
connected.push(c);
last = Occupant::None;
@@ -250,6 +226,31 @@ impl EventHandler for Game {
}
}
+ connected.clear();
+ for i in 0..COLUMNS {
+ let mut c = Vec::new();
+ for j in 0..ROWS {
+ if self.grid[j][i].occupant == last {
+ c.push((j, i));
+ c.push((j - 1, i));
+ } else {
+ connected.push(c.clone());
+ c.clear();
+ }
+ last = self.grid[j][i].occupant;
+ }
+ connected.push(c);
+ last = Occupant::None;
+ }
+
+ for c in connected.iter() {
+ if c.len() > 3 {
+ for (j, i) in c.iter() {
+ self.grid[*j][*i].occupant = Occupant::Explosion;
+ }
+ }
+ }
+
Ok(())
}