Ugly fix for invalid input
This commit is contained in:
parent
3cf7005151
commit
2209dd7786
1 changed files with 16 additions and 1 deletions
|
@ -94,7 +94,22 @@ public class SudokuController {
|
|||
int row = view.getSelectedRow();
|
||||
int col = view.getSelectedColumn();
|
||||
|
||||
int value = Integer.parseInt(view.getCellValue(row, col));
|
||||
int value = 0;
|
||||
|
||||
String cellValue = view.getCellValue(row, col);
|
||||
if (cellValue == null || cellValue.equals("")) {
|
||||
value = 0;
|
||||
} else {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the input is legal and update the model and view
|
||||
if (model.isLegal(row, col, value)) {
|
||||
model.set(row, col, value);
|
||||
|
|
Loading…
Reference in a new issue