Slightly less ugly fix for invalid input

This commit is contained in:
Imbus 2023-12-11 13:58:05 +01:00
parent 2209dd7786
commit 7e5253fb4b

View file

@ -103,20 +103,17 @@ public class SudokuController {
try {
value = Integer.parseInt(cellValue);
} catch (NumberFormatException ex) {
model.set(row, col, 0);
view.updateView(model.getBoard());
view.showErrorMessage("Invalid input. Try again.");
return; // Bail out if the input is invalid
value = 0;
}
}
// Check if the input is legal and update the model and view
if (model.isLegal(row, col, value)) {
model.set(row, col, value);
view.updateView(model.getBoard());
} else {
// If the input is invalid
if (!model.isLegal(row, col, value)) {
value = 0;
view.showErrorMessage("Invalid input. Try again.");
}
model.set(row, col, value);
view.updateView(model.getBoard());
}
}
}