summaryrefslogtreecommitdiff
path: root/dungeon/src/map.rs
diff options
context:
space:
mode:
Diffstat (limited to 'dungeon/src/map.rs')
-rw-r--r--dungeon/src/map.rs46
1 files changed, 42 insertions, 4 deletions
diff --git a/dungeon/src/map.rs b/dungeon/src/map.rs
index 8d9a391..7d79f7f 100644
--- a/dungeon/src/map.rs
+++ b/dungeon/src/map.rs
@@ -29,8 +29,10 @@ pub const TILE_COUNT: usize = MAP_SIZE_USIZE * MAP_SIZE_USIZE;
pub enum Tile {
/// `Wall` represents an impassible wall
Wall,
- /// `Air` represents empty walkable space
- Air,
+ /// `Room` represents empty walkable space for a rectangular room
+ Room,
+ /// `Hallway` represents empty walkable space for a hallway
+ Hallway,
/// `Stairs` represents stairs to another floor
Stairs,
}
@@ -51,10 +53,12 @@ impl Tile {
pub const fn is_walkable(self) -> bool {
matches!(self, Self::Air)
}
+
+ // Index by u16
}
impl Default for Tile {
fn default() -> Self {
- Self::Air
+ Self::Wall
}
}
impl Display for Tile {
@@ -207,6 +211,40 @@ impl Floor {
*hash
}
+ /// Display the floor as a string for debugging
+ ///
+ /// # Examples
+ /// ```no_run
+ /// use dungeon::Floor;
+ /// let floor = Floor::generate();
+ /// println!("{}", floor.display());
+ /// ```
+ #[must_use]
+ pub fn display(&self) -> String {
+ let mut output = String::new();
+ for pos in Pos::values() {
+ // If it's the player start, show 'P'
+ if self.player_start == pos {
+ output.push('P');
+ continue;
+ }
+ // Otherwise, show the tile character
+ let tile = self.get(pos);
+ let char = match tile {
+ Tile::Wall => '#',
+ Tile::Room => '.',
+ Tile::Hallway => ',',
+ Tile::Stairs => '>',
+ };
+ output.push(char);
+ // Newline at the end of each row
+ if pos.xy().0 == MAP_SIZE - 1 {
+ output.push('\n');
+ }
+ }
+ output
+ }
+
/// Returns a random open (no wall) position
pub fn random_pos(&mut self) -> Pos {
loop {
@@ -227,7 +265,7 @@ impl Default for Floor {
/// Returns a floor with a single set of walls on the map border
fn default() -> Self {
let player_start = const_pos!(1, 1);
- let mut tiles = Box::new([Tile::Air; TILE_COUNT]);
+ let mut tiles = Box::new([Tile::Room; TILE_COUNT]);
let seed = 0u64;
for pos in Pos::values() {