This commit is contained in:
2025-02-24 10:20:01 +01:00
parent ef0c51d993
commit 791780ddbb
2 changed files with 70 additions and 0 deletions

View File

@@ -123,6 +123,29 @@ impl Universe {
pub fn cells(&self) -> *const Cell {
self.cells.as_ptr()
}
pub fn set_width(&mut self, width: u32) {
self.width = width;
self.cells = (0..width * self.height).map(|_i| Cell::Dead).collect();
}
pub fn set_height(&mut self, height: u32) {
self.height = height;
self.cells = (0..height * self.height).map(|_i| Cell::Dead).collect();
}
}
impl Universe {
pub fn get_cells(&self) -> &[Cell] {
&self.cells
}
pub fn set_cells(&mut self, cells: &[(u32, u32)]) {
for (row, col) in cells.iter().cloned() {
let idx = self.get_index(row, col);
self.cells[idx] = Cell::Alive;
}
}
}
impl Default for Universe {