add removal of colliding marks when placing number
This commit is contained in:
parent
c94ef2721d
commit
d5678967e3
@ -51,7 +51,7 @@ The current control scheme adheres to vim-like keybindings and is modal.
|
||||
|
||||
### Todo
|
||||
|
||||
- [ ] Game logic
|
||||
- [x] Game logic
|
||||
- [x] Validate Sudokus
|
||||
- [x] Generate Sudokus
|
||||
- [x] Difficulties to choose
|
||||
@ -69,7 +69,7 @@ The current control scheme adheres to vim-like keybindings and is modal.
|
||||
- [x] Preselect numbers
|
||||
- [x] Edit Mode to (re)place numbers
|
||||
- [x] Markup Mode to mark where numbers could go
|
||||
- [ ] Autoremove marks after placing number in edit mode
|
||||
- [x] Autoremove marks after placing number in edit mode
|
||||
- [x] Go Mode to move to blocks 1-9
|
||||
- [x] Toggle Number/Mark with Space
|
||||
- [ ] Undo/Redo stack
|
||||
|
||||
@ -16,7 +16,7 @@ use std::{io, time::Duration};
|
||||
|
||||
fn main() {
|
||||
let mut screen = Screen::init(io::stdout());
|
||||
let mut state = State::init(Difficulty::Expert);
|
||||
let mut state = State::init(Difficulty::Mid);
|
||||
screen.draw_board().or_crash();
|
||||
|
||||
loop {
|
||||
|
||||
15
src/state.rs
15
src/state.rs
@ -102,10 +102,11 @@ impl State {
|
||||
|
||||
pub fn toggle_current_cell(&mut self) {
|
||||
if self.current_cell_is_modifiable() {
|
||||
*self.current_cell() = if *self.current_cell() == self.preselection {
|
||||
0
|
||||
if *self.current_cell() == self.preselection {
|
||||
*self.current_cell() = 0;
|
||||
} else {
|
||||
self.preselection
|
||||
*self.current_cell() = self.preselection;
|
||||
self.delete_colliding_marks(self.preselection, self.cur_row, self.cur_col);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -116,6 +117,14 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn delete_colliding_marks(&mut self, num: u8, row: usize, col: usize) {
|
||||
for i in 0..9 {
|
||||
self.markups[i][col][num as usize - 1] = false;
|
||||
self.markups[row][i][num as usize - 1] = false;
|
||||
self.markups[row / 3 * 3 + i / 3][col / 3 * 3 + i % 3][num as usize - 1] = false;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enter_mode(&mut self, mode: Mode) {
|
||||
match mode {
|
||||
Mode::Go => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user