implement display trait for cell
This commit is contained in:
parent
41af614d74
commit
f226635edd
28
src/lib.rs
28
src/lib.rs
|
@ -57,6 +57,22 @@ impl Sub for Pos {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Cell {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
match self {
|
||||
Cell::Wall => 'X',
|
||||
Cell::Box => '*',
|
||||
Cell::Goal(true) => '!',
|
||||
Cell::Goal(false) => '.',
|
||||
Cell::None => ' ',
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Pos {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{} {}", self.0, self.1)
|
||||
|
@ -111,17 +127,7 @@ impl std::fmt::Display for Level {
|
|||
if Pos(j, i) == self.player {
|
||||
write!(f, "@")?;
|
||||
} else {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
match self[Pos(j, i)] {
|
||||
Cell::Wall => 'X',
|
||||
Cell::Box => '*',
|
||||
Cell::Goal(true) => '!',
|
||||
Cell::Goal(false) => '.',
|
||||
Cell::None => ' ',
|
||||
}
|
||||
)?;
|
||||
write!(f, "{}", self[Pos(j, i)])?;
|
||||
}
|
||||
}
|
||||
writeln!(f)?;
|
||||
|
|
Loading…
Reference in New Issue