From 591e4f977a4800083bdad78596d2af28089c886a Mon Sep 17 00:00:00 2001 From: Janet-Doe Date: Sun, 2 Feb 2025 21:31:32 +0100 Subject: [PATCH] update ConsoleInterface --- .../main/java/sudoku/io/ConsoleInterface.java | 18 ++++++++++++------ .../main/java/sudoku/io/SudokuSerializer.java | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/sudoku/io/ConsoleInterface.java b/app/src/main/java/sudoku/io/ConsoleInterface.java index bebc621..012c8d7 100644 --- a/app/src/main/java/sudoku/io/ConsoleInterface.java +++ b/app/src/main/java/sudoku/io/ConsoleInterface.java @@ -21,12 +21,16 @@ public class ConsoleInterface { public void welcome() { System.out.println("Welcome to our Sudoku Solver!"); System.out.println("This is the project of Melvyn Bauvent, Lilas Grenier and Simon Pribylski."); + createDoku(); + + /* System.out.println("Do you have a save sudoku you would like to continue? (y/n, default n)"); if (reader.next().equalsIgnoreCase("y")) { useSavedDoku(); } else { createDoku(); } + */ } /** @@ -94,6 +98,7 @@ public class ConsoleInterface { if (difficulty.equals("full")) { generateFullDoku(doku); System.out.println("Here's your sudoku !"); + showMultidoku(doku, listSymbols, width, height); exit(); } else { generatePartialDoku(doku, difficulty); @@ -141,10 +146,13 @@ public class ConsoleInterface { MultiDoku md = null; do { nbSave = reader.nextInt(); + if (nbSave == -1) { + System.exit(0); + } try { md = SudokuSerializer.getSavedMultiDoku(nbSave); } catch (Exception e) { - System.out.println("There seems to be a problem with this save, please try again."); + System.out.println("There seems to be a problem with this save, please try again or write '-1' to abort."); } } while (md == null); return md; @@ -348,7 +356,7 @@ public class ConsoleInterface { * @param width int, largeur d'un bloc du sudoku * @param height int, hauteur d'un bloc du sudoku * @param step SolverStep, étape de résolution à afficher - * @return + * @return boolean, valant true si l'utilisateur veut afficher l'étape, false sinon */ private boolean showStep(MultiDoku doku, List listSymbols, int width, int height, SolverStep step) { System.out.println("Here is the step : \n"); @@ -401,6 +409,7 @@ public class ConsoleInterface { new RandomSolver().solve(doku, steps); break; } + showMultidoku(doku, listSymbols, width, height); showSolveSteps(doku, listSymbols, width, height, steps); } @@ -444,10 +453,7 @@ public class ConsoleInterface { */ private boolean isValidCoordinates(RenderableMultidoku doku, int width, int height, int x, int y) { Cell cell = doku.getCell(x, y); - if ((cell != null) && cell.isMutable()) { - return true; - } - return false; + return ((cell != null) && cell.isMutable()); } /** diff --git a/app/src/main/java/sudoku/io/SudokuSerializer.java b/app/src/main/java/sudoku/io/SudokuSerializer.java index 395c10f..c3d0ce4 100644 --- a/app/src/main/java/sudoku/io/SudokuSerializer.java +++ b/app/src/main/java/sudoku/io/SudokuSerializer.java @@ -173,7 +173,7 @@ public class SudokuSerializer { * Get a MultiDoku from a pre-existing json save file. * * @param numberSave int, number of the save file to open. - * @return MultiDoku, MultoDoku contained in the file. + * @return MultiDoku, MultiDoku contained in the file. * @throws Exception when the given save file does not exist. */ public static MultiDoku getSavedMultiDoku(int numberSave) throws Exception {