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 {
|
impl std::fmt::Display for Pos {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "{} {}", self.0, self.1)
|
write!(f, "{} {}", self.0, self.1)
|
||||||
|
@ -111,17 +127,7 @@ impl std::fmt::Display for Level {
|
||||||
if Pos(j, i) == self.player {
|
if Pos(j, i) == self.player {
|
||||||
write!(f, "@")?;
|
write!(f, "@")?;
|
||||||
} else {
|
} else {
|
||||||
write!(
|
write!(f, "{}", self[Pos(j, i)])?;
|
||||||
f,
|
|
||||||
"{}",
|
|
||||||
match self[Pos(j, i)] {
|
|
||||||
Cell::Wall => 'X',
|
|
||||||
Cell::Box => '*',
|
|
||||||
Cell::Goal(true) => '!',
|
|
||||||
Cell::Goal(false) => '.',
|
|
||||||
Cell::None => ' ',
|
|
||||||
}
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writeln!(f)?;
|
writeln!(f)?;
|
||||||
|
|
Loading…
Reference in New Issue