enter and exit solution editor
This commit is contained in:
parent
44b7d63cde
commit
c4381ac1a1
8 changed files with 195 additions and 41 deletions
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue