From b05dda146f978502b3c551f1214bf2d032dfa118 Mon Sep 17 00:00:00 2001 From: tmp1u19 <tmp1u19@soton.ac.uk> Date: Mon, 27 Apr 2020 00:34:05 +0300 Subject: [PATCH] Add the hint functionality and the solver of the board --- Handler.java | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/Handler.java b/Handler.java index 06b7419..03d2ac8 100644 --- a/Handler.java +++ b/Handler.java @@ -1,4 +1,6 @@ import javafx.animation.*; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.Node; import javafx.scene.control.Button; @@ -717,10 +719,29 @@ public class Handler { return true; } - public void solveBoard(Button solve, GridPane grid, int n) { - solve.setOnAction(actionEvent -> { - Solver solver = new Solver(n, grid); - solver.backtracking(1, 1); + public void solveBoard(GridPane grid) { + + Solver solver = new Solver(n, grid); + solver.backtracking(1, 1); + clear(grid); + } + + public void hint(Button hint, GridPane grid) { + + hint.setOnAction(actionEvent -> { + + boolean found = false; + + for(int i = 0; i < n && !found; i ++) { + for(int j = 0; j < n; j ++) { + if(cellValues[i][j] != Solver.solved[i][j]) { + getCell(grid, i, j).setValue(Solver.solved[i][j]); + cellValues[i][j] = Solver.solved[i][j]; + found = true; + break; + } + } + } }); } } -- GitLab