Error checking inputs and reverting if illegal
This commit is contained in:
parent
26df774ca3
commit
5bf0c92d10
1 changed files with 9 additions and 0 deletions
|
@ -127,6 +127,15 @@ public class SudokuController {
|
||||||
|
|
||||||
// Update the model and view
|
// Update the model and view
|
||||||
model.set(row, col, value);
|
model.set(row, col, value);
|
||||||
|
|
||||||
|
// Warn if the board is not solvable (e.g. if the user has made a mistake)
|
||||||
|
// This is very messy, error prone and computationally expensive
|
||||||
|
if(!model.isSolvable()) {
|
||||||
|
model.set(row, col, 0);
|
||||||
|
view.showErrorMessage("Illegal move. The board is not solvable.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sync the view with the model
|
||||||
view.updateView(model.getBoard());
|
view.updateView(model.getBoard());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue