use super::*;
#[derive(Debug, Copy, Clone)]
pub enum FieldType {
Start,
Goal,
Normal,
}
#[derive(Clone)]
pub struct Field {
passages: Vec<Direction>,
pub field_type: FieldType,
pub coordinates: Coordinates,
}
impl Field {
pub(crate) fn new(
field_type: FieldType,
coordinates: Coordinates,
passages: Vec<Direction>,
) -> Self {
Field {
passages,
field_type,
coordinates,
}
}
pub fn has_passage(&self, direction: &Direction) -> bool {
self.passages.contains(direction)
}
}
impl std::fmt::Debug for Field {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct(stringify!(Field))
.field(
"north",
&if !self.has_passage(&Direction::North) {
String::from("wall")
} else {
String::from("passage")
},
)
.field(
"east",
&if !self.has_passage(&Direction::East) {
String::from("wall")
} else {
String::from("passage")
},
)
.field(
"south",
&if !self.has_passage(&Direction::South) {
String::from("wall")
} else {
String::from("passage")
},
)
.field(
"west",
&if !self.has_passage(&Direction::West) {
String::from("wall")
} else {
String::from("passage")
},
)
.finish()
}
}