From de17bc02c44cb182cb8cbe370ba2a19bad3247be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pentti=20L=C3=A4hdeaho?= Date: Tue, 21 Apr 2020 22:08:03 +0300 Subject: [PATCH] Update Ui and game logics --- .../src/main/java/domain/Sudoku.java | 21 +++++++++++++++++++ SudokuSovellus/src/main/java/ui/SudokuUi.java | 16 +++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/SudokuSovellus/src/main/java/domain/Sudoku.java b/SudokuSovellus/src/main/java/domain/Sudoku.java index 1fce94b..d2d4fb7 100644 --- a/SudokuSovellus/src/main/java/domain/Sudoku.java +++ b/SudokuSovellus/src/main/java/domain/Sudoku.java @@ -14,6 +14,27 @@ public class Sudoku { public Sudoku() { grid = new int[9][9]; + grid[0][0] = 8; + grid[1][2] = 3; + grid[1][3] = 6; + grid[2][1] = 7; + grid[2][4] = 9; + grid[2][6] = 2; + grid[3][1] = 5; + grid[3][5] = 7; + grid[4][4] = 4; + grid[4][5] = 5; + grid[4][6] = 7; + grid[5][3] = 1; + grid[5][7] = 3; + grid[6][2] = 1; + grid[6][7] = 6; + grid[6][8] = 8; + grid[7][2] = 8; + grid[7][3] = 5; + grid[7][7] = 1; + grid[8][2] = 9; + grid[8][6] = 4; } public int[][] getGrid() { diff --git a/SudokuSovellus/src/main/java/ui/SudokuUi.java b/SudokuSovellus/src/main/java/ui/SudokuUi.java index 5ffce6f..cd2d6c8 100644 --- a/SudokuSovellus/src/main/java/ui/SudokuUi.java +++ b/SudokuSovellus/src/main/java/ui/SudokuUi.java @@ -73,9 +73,10 @@ public void start(Stage stage) throws Exception { Button playHard = new Button("Hard"); Button solve = new Button("Solve"); Button clear = new Button("Clear"); + Text solved = new Text(); menuButtons.getChildren().add(play); - gameButtons.getChildren().addAll(solve, clear); + gameButtons.getChildren().addAll(solved, solve, clear); play.setOnAction(e -> { menuButtons.getChildren().remove(play); @@ -98,8 +99,12 @@ public void start(Stage stage) throws Exception { this.update(); }); solve.setOnAction(e -> { - solver.solve(sudoku.getGrid()); - this.update(); + if (solver.solve(sudoku.getGrid())) { + solved.setText("Solved!"); + this.update(); + } else { + solved.setText("Not solvable"); + } }); root.setCenter(menuButtons); @@ -136,6 +141,11 @@ public Button createButton(int x, int y) { Button btn = new Button(); btn.setPrefSize(40, 40); btn.setFont(Font.font(18)); + if (sudoku.getNumeber(x, y) != 0) { + btn.setText(String.valueOf(sudoku.getNumeber(x, y))); + btn.setDisable(true); + + } btn.setOnKeyPressed(key -> { KeyCode keyCode = key.getCode();