Skip to content

Commit

Permalink
Update Ui and game logics
Browse files Browse the repository at this point in the history
  • Loading branch information
Pentza committed Apr 21, 2020
1 parent 83a96f0 commit de17bc0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
21 changes: 21 additions & 0 deletions SudokuSovellus/src/main/java/domain/Sudoku.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
16 changes: 13 additions & 3 deletions SudokuSovellus/src/main/java/ui/SudokuUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit de17bc0

Please # to comment.