From 7e5253fb4b7ac94e1002b05e2c6a68c7bbff2f95 Mon Sep 17 00:00:00 2001 From: Imbus Date: Mon, 11 Dec 2023 13:58:05 +0100 Subject: [PATCH] Slightly less ugly fix for invalid input --- app/src/main/java/gui/SudokuController.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/gui/SudokuController.java b/app/src/main/java/gui/SudokuController.java index 98c2f31..5528349 100644 --- a/app/src/main/java/gui/SudokuController.java +++ b/app/src/main/java/gui/SudokuController.java @@ -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()); } } }