Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
roguelike-tdd: Add MapGenerator::write and MapUtil::parse
- Loading branch information
Showing
6 changed files
with
120 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
mod door; | ||
mod map_chips; | ||
mod map_generator; | ||
mod map_util; | ||
mod passage; | ||
mod room; | ||
mod stairs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use super::map_chips::MapChip; | ||
|
||
pub struct MapUtil; | ||
|
||
impl MapUtil { | ||
pub fn parse(s: &str) -> Vec<Vec<MapChip>> { | ||
s.lines() | ||
.map(|line| { | ||
line.chars() | ||
.map(|c| match c { | ||
'D' => MapChip::Door, | ||
'P' => MapChip::Passage, | ||
'R' => MapChip::Room, | ||
'S' => MapChip::DownStairs, | ||
'U' => MapChip::UpStairs, | ||
'W' => MapChip::Wall, | ||
_ => unreachable!(), | ||
}) | ||
.collect::<Vec<MapChip>>() | ||
}) | ||
.collect::<Vec<Vec<MapChip>>>() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters