Slightly less ugly fix for invalid input
This commit is contained in:
parent
2209dd7786
commit
7e5253fb4b
1 changed files with 6 additions and 9 deletions
|
@ -103,20 +103,17 @@ public class SudokuController {
|
||||||
try {
|
try {
|
||||||
value = Integer.parseInt(cellValue);
|
value = Integer.parseInt(cellValue);
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
model.set(row, col, 0);
|
value = 0;
|
||||||
view.updateView(model.getBoard());
|
|
||||||
view.showErrorMessage("Invalid input. Try again.");
|
|
||||||
return; // Bail out if the input is invalid
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the input is legal and update the model and view
|
// If the input is invalid
|
||||||
if (model.isLegal(row, col, value)) {
|
if (!model.isLegal(row, col, value)) {
|
||||||
model.set(row, col, value);
|
value = 0;
|
||||||
view.updateView(model.getBoard());
|
|
||||||
} else {
|
|
||||||
view.showErrorMessage("Invalid input. Try again.");
|
view.showErrorMessage("Invalid input. Try again.");
|
||||||
}
|
}
|
||||||
|
model.set(row, col, value);
|
||||||
|
view.updateView(model.getBoard());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue