2021-12-18 12:22:46 -06:00
|
|
|
use pancurses::Window;
|
|
|
|
|
2021-12-18 12:29:07 -06:00
|
|
|
/// A dungeon root.
|
2021-12-18 12:22:46 -06:00
|
|
|
pub struct Dungeon {
|
|
|
|
main_branch: DungeonBranch,
|
|
|
|
}
|
|
|
|
|
2021-12-18 12:29:07 -06:00
|
|
|
/// A single branch of a dungeon, which has a number of levels and
|
|
|
|
/// which can potentially contain passages to other branches.
|
2021-12-18 12:22:46 -06:00
|
|
|
pub struct DungeonBranch {
|
|
|
|
config: BranchConfig,
|
|
|
|
levels: Vec<DungeonLevel>,
|
|
|
|
}
|
|
|
|
|
2021-12-18 12:29:07 -06:00
|
|
|
/// The parameters that characterize a particular dungeon branch.
|
|
|
|
/// Currently a unit struct because there's only one type of branch,
|
|
|
|
/// but will later include e.g. architectural styles, good vs. evil &
|
|
|
|
/// lawful vs. chaotic weights, etc.
|
2021-12-18 12:22:46 -06:00
|
|
|
pub struct BranchConfig;
|
|
|
|
|
2021-12-18 12:29:07 -06:00
|
|
|
/// The size of a dungeon level, in tiles.
|
2021-12-18 12:22:46 -06:00
|
|
|
pub const LEVEL_SIZE: (usize, usize) = (80, 24);
|
|
|
|
|
2021-12-18 12:29:07 -06:00
|
|
|
/// A single level of the dungeon.
|
2021-12-18 12:22:46 -06:00
|
|
|
pub struct DungeonLevel {
|
2021-12-18 12:29:07 -06:00
|
|
|
/// The tiles at every position in the level.
|
2021-12-18 13:06:00 -06:00
|
|
|
tiles: [[DungeonTile; LEVEL_SIZE.0]; LEVEL_SIZE.1],
|
2021-12-18 12:22:46 -06:00
|
|
|
}
|
|
|
|
|
2021-12-18 12:29:07 -06:00
|
|
|
/// The smallest possible independent location in the dungeon,
|
|
|
|
/// corresponding to a single character on the screen.
|
2021-12-18 13:06:00 -06:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2021-12-18 12:22:46 -06:00
|
|
|
pub enum DungeonTile {
|
|
|
|
Floor,
|
|
|
|
Wall,
|
|
|
|
Hallway,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DungeonLevel {
|
2021-12-18 12:29:07 -06:00
|
|
|
/// Creates a new level in a branch that has the given
|
|
|
|
/// configuration.
|
2021-12-18 12:22:46 -06:00
|
|
|
pub fn new(cfg: &BranchConfig) -> Self {
|
2021-12-18 13:06:00 -06:00
|
|
|
Self {
|
|
|
|
tiles: [[DungeonTile::Floor; LEVEL_SIZE.0]; LEVEL_SIZE.1],
|
|
|
|
}
|
2021-12-18 12:22:46 -06:00
|
|
|
}
|
|
|
|
|
2021-12-18 12:29:07 -06:00
|
|
|
/// Draws a level on the display window.
|
2021-12-18 12:22:46 -06:00
|
|
|
pub fn draw(&self, win: &Window) {
|
2021-12-18 13:06:00 -06:00
|
|
|
for (y, row) in self.tiles.iter().enumerate() {
|
|
|
|
win.mv(y as _, 0);
|
|
|
|
for tile in row {
|
|
|
|
win.addch(match tile {
|
|
|
|
DungeonTile::Floor => '.',
|
|
|
|
DungeonTile::Wall => ' ',
|
|
|
|
DungeonTile::Hallway => '#',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
win.mv(0, 0);
|
2021-12-18 12:22:46 -06:00
|
|
|
}
|
|
|
|
}
|