Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
add Board::set_cell_color
Browse files Browse the repository at this point in the history
  • Loading branch information
MinusKelvin committed Jan 9, 2022
1 parent bf37ad9 commit 13b097a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libtetris/src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ impl<R: Row> Board<R> {
}
}

pub fn set_cell_color(&mut self, x: i32, y: i32, color: CellColor) {
self.cells[y as usize].set(x as usize, color);
let h = &mut self.column_heights[x as usize];
if color != CellColor::Empty {
*h = (*h).max(y + 1);
} else if *h == y + 1 {
while *h > 0 && !self.cells[*h as usize - 1].get(x as usize) {
*h -= 1;
}
}
}

pub fn obstructed(&self, piece: &FallingPiece) -> bool {
piece.cells().iter().any(|&(x, y)| self.occupied(x, y))
}
Expand Down

0 comments on commit 13b097a

Please sign in to comment.