diff --git a/tetros/src/game/board.rs b/tetros/src/game/board.rs index daa96d6..eaaae8e 100644 --- a/tetros/src/game/board.rs +++ b/tetros/src/game/board.rs @@ -97,12 +97,28 @@ impl TetrisBoard { /// Get the value of the cell at the given position. /// Returns [`None`] if (x, y) exceeds the board's bounds. pub fn get_cell(&self, x: usize, y: usize) -> Option<&TetrisCell> { + if y >= TetrisBoard::BOARD_HEIGHT { + return None; + } + + if x >= TetrisBoard::BOARD_WIDTH { + return None; + } + return self.board.get(y * TetrisBoard::BOARD_WIDTH + x); } /// Get a mutable reference to the cell at the given position. /// Returns [`None`] if (x, y) exceeds the board's bounds. pub fn get_cell_mut(&mut self, x: usize, y: usize) -> Option<&mut TetrisCell> { + if y >= TetrisBoard::BOARD_HEIGHT { + return None; + } + + if x >= TetrisBoard::BOARD_WIDTH { + return None; + } + return self.board.get_mut(y * TetrisBoard::BOARD_WIDTH + x); } }