enter and exit solution editor

This commit is contained in:
Crispy 2024-10-06 16:00:12 +02:00
parent 44b7d63cde
commit c4381ac1a1
8 changed files with 195 additions and 41 deletions

View file

@ -63,6 +63,17 @@ impl Board {
Board::new(rows)
}
pub fn to_string(&self)->String{
let mut out = String::new();
for row in &self.rows{
for tile in row{
out.push(tile.to_char())
}
out.push('\n');
}
out
}
pub fn new_empty(width: usize, height: usize) -> Self {
let rows = vec![vec![Tile::Blank; width]; height];
Self {

View file

@ -104,6 +104,50 @@ impl Tile {
}
}
pub fn to_char(self) -> char {
match self {
Tile::Blank => ' ',
Tile::Block => '#',
Tile::Marble { value: _, dir: _ } => 'o',
Tile::Digit(n) => (b'0' + n) as char,
Tile::Mirror(dir) => match dir {
MirrorType::Forward => '/',
MirrorType::Back => '\\',
},
Tile::Arrow(dir) => match dir {
Direction::Up => '^',
Direction::Down => 'v',
Direction::Left => '<',
Direction::Right => '>',
},
Tile::Powerable(tile, _) => match tile {
PTile::Trigger => '*',
PTile::Wire(wire) => match wire {
WireType::Vertical => '|',
WireType::Horizontal => '-',
WireType::Cross => '+',
},
PTile::Gate(gate) => match gate {
GateType::LessThan => 'L',
GateType::GreaterThan => 'G',
GateType::Equal => '=',
GateType::NotEqual => '!',
},
PTile::Math(math) => match math {
MathOp::Add => 'A',
MathOp::Sub => 'S',
MathOp::Mul => 'M',
MathOp::Div => 'D',
MathOp::Rem => 'R',
},
PTile::Bag => 'B',
PTile::Flipper => 'F',
PTile::Input => 'I',
PTile::Output => 'P',
},
}
}
pub fn is_blank(&self) -> bool {
matches!(self, Tile::Blank)
}