extern crate pancurses; use pancurses::{Window}; pub struct TileGrid { grid: Vec> } impl TileGrid { pub fn new(xsize: usize, ysize: usize) -> TileGrid { let mut grid = TileGrid { grid: Vec::with_capacity(ysize) }; for _ in 0..ysize { let mut subvec = Vec::with_capacity(xsize); for _ in 0..xsize { subvec.push(TileType::Empty); } grid.grid.push(subvec); } return grid; } pub fn set_tile(&mut self, x: usize, y: usize, tile: TileType) { self.grid[y][x] = tile; } /// Sets a tile if nothing lies underneath it. pub fn set_empty_tile(&mut self, x: usize, y: usize, tile: TileType) { self.set_tile(x, y, match self.grid[y][x] { TileType::Empty => tile, _ => self.grid[y][x].clone() }) } pub fn raw_data(& self) -> & Vec> { &self.grid } } fn tile_to_str(tile: &TileType) -> &str { match tile { TileType::Floor => ".", TileType::Wall => "#", TileType::Empty => " ", TileType::StairsDown => ">", TileType::StairsUp => "<", TileType::Player => "@", _ => "?" } } pub fn draw_block(window: &Window, block: &TileType) { window.printw(tile_to_str(block)); } pub trait Tileable { fn tile(&self, grid: &mut TileGrid) -> Result<(), String>; } #[derive(Clone)] pub enum TileType { Empty, Wall, Floor, StairsUp, StairsDown, Character, Player }