draw marble direction
This commit is contained in:
parent
fc6c66ff31
commit
682dff48f9
2 changed files with 19 additions and 9 deletions
Binary file not shown.
Before Width: | Height: | Size: 183 B After Width: | Height: | Size: 176 B |
|
@ -70,14 +70,27 @@ impl Machine {
|
|||
if let Some(tile) = self.board.get((x, y).into()) {
|
||||
let px = x as i32 * tile_size + offset.x as i32 + tile_size / 2;
|
||||
let py = y as i32 * tile_size + offset.y as i32 + tile_size / 2;
|
||||
if let Tile::Marble { value, dir: _ } = tile {
|
||||
if let Tile::Marble { value, dir } = tile {
|
||||
let fontsize = (zoom + 1) * 10;
|
||||
d.draw_text(
|
||||
&format!("{value}"),
|
||||
px - tile_size / 2 + 2,
|
||||
py - tile_size / 2 + 2,
|
||||
20,
|
||||
fontsize,
|
||||
Color::MAGENTA,
|
||||
)
|
||||
);
|
||||
d.draw_text(
|
||||
match dir {
|
||||
Direction::Up => "^",
|
||||
Direction::Down => "v",
|
||||
Direction::Left => "<",
|
||||
Direction::Right => ">",
|
||||
},
|
||||
px - tile_size / 2 + 2,
|
||||
py - tile_size / 2 + fontsize,
|
||||
fontsize,
|
||||
Color::MAGENTA,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,9 +127,7 @@ impl Machine {
|
|||
new_tile = Some(Tile::Blank);
|
||||
}
|
||||
Tile::Digit(d) => {
|
||||
let new_val = value
|
||||
.wrapping_mul(10)
|
||||
.wrapping_add(*d as MarbleValue);
|
||||
let new_val = value.wrapping_mul(10).wrapping_add(*d as MarbleValue);
|
||||
*target = Tile::Marble {
|
||||
value: new_val,
|
||||
dir,
|
||||
|
@ -258,7 +269,7 @@ impl Machine {
|
|||
|| !self.board.get_or_blank(pos_b).is_blank())
|
||||
&& self.board.get_or_blank(front_pos).is_blank()
|
||||
{
|
||||
let result = match op {
|
||||
let value = match op {
|
||||
MathOp::Add => val_a.wrapping_add(val_b),
|
||||
MathOp::Sub => val_a.wrapping_sub(val_b),
|
||||
MathOp::Mul => val_a.wrapping_mul(val_b),
|
||||
|
@ -266,7 +277,7 @@ impl Machine {
|
|||
MathOp::Rem => val_a.checked_rem(val_b).unwrap_or_default(),
|
||||
};
|
||||
// println!("{op:?} a:{val_a} b:{val_b}");
|
||||
*self.board.get_mut_unchecked(front_pos) = Tile::Marble { value: result, dir };
|
||||
*self.board.get_mut_unchecked(front_pos) = Tile::Marble { value, dir };
|
||||
self.marbles.push(front_pos);
|
||||
}
|
||||
}
|
||||
|
@ -314,4 +325,3 @@ impl Machine {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue