Small bug
This commit is contained in:
parent
cf60d6734a
commit
8893395878
@ -97,12 +97,28 @@ impl TetrisBoard {
|
|||||||
/// Get the value of the cell at the given position.
|
/// Get the value of the cell at the given position.
|
||||||
/// Returns [`None`] if (x, y) exceeds the board's bounds.
|
/// Returns [`None`] if (x, y) exceeds the board's bounds.
|
||||||
pub fn get_cell(&self, x: usize, y: usize) -> Option<&TetrisCell> {
|
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);
|
return self.board.get(y * TetrisBoard::BOARD_WIDTH + x);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a mutable reference to the cell at the given position.
|
/// Get a mutable reference to the cell at the given position.
|
||||||
/// Returns [`None`] if (x, y) exceeds the board's bounds.
|
/// Returns [`None`] if (x, y) exceeds the board's bounds.
|
||||||
pub fn get_cell_mut(&mut self, x: usize, y: usize) -> Option<&mut TetrisCell> {
|
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);
|
return self.board.get_mut(y * TetrisBoard::BOARD_WIDTH + x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user