From 88933958780c2db29900c7954585b036a9c948a2 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 5 Mar 2025 21:33:17 -0800 Subject: [PATCH] Small bug --- tetros/src/game/board.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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); } }