use std::usize;
pub struct Grid {
pub width: usize,
pub height: usize,
tiles: Vec<char>
}
impl Grid {
pub fn new(width: usize, height: usize) -> Grid {
let mut tiles = Vec::new();
for _i in 0..(width * height) {
tiles.push('.');
}
Grid {
width,
height,
tiles
}
}
pub fn _get(&self, x: usize, y: usize) -> char {
return self.tiles[self.width * y + x];
}
pub fn set(&mut self, value: char, x: usize, y: usize) {
self.tiles[self.width * y + x] = value;
}
pub fn for_each(&mut self, callback: fn()) {
for _i in 0..(self.width * self.height) {
// let x = 0;
// let y = _i / self.width;
callback();
}
}
pub fn print(&self) {
for i in 0..self.tiles.len() {
if i % self.width as usize == 0 {
print!("\n");
}
print!("{}", self.tiles[i]);
print!(" ");
}
print!("\n");
}
}