From a722b17ae6efe9068a87a533de8b7e1485073b80 Mon Sep 17 00:00:00 2001
From: tmp1u19 <tmp1u19@soton.ac.uk>
Date: Mon, 27 Apr 2020 00:34:59 +0300
Subject: [PATCH] The hint option ca now be accessed for boards equal or lower
 than 5x5

---
 Window.java | 247 +++++++++++++++++++++++++++-------------------------
 1 file changed, 126 insertions(+), 121 deletions(-)

diff --git a/Window.java b/Window.java
index 45c9e4a..58a1183 100644
--- a/Window.java
+++ b/Window.java
@@ -24,6 +24,132 @@ public class Window {
 
     static int n; //the size of the board nxn -> static to be the same everywhere
 
+    /**
+     * window that will create the game board and the buttons specific to it
+     * all the options for the game are accessed from this window
+     * @param n -> the size of the board nxn
+     * @param cages -> the cages that were extracted when a file was opened from the menu window
+     * @return Stage -> the Mathdoku window where a a user can play the game
+     */
+    public Stage mathdoku(int n, ArrayList<Cage> cages) {
+
+        Window.n = n; //set the size of the board to the n selected by the player in the menu window
+        Handler handler = new Handler(cages); //create a handler object to handle the functionalities of the game
+
+        Stage stage = new Stage(); //create the stage for the game
+
+        //create the root for the elements that will be added to the scene; set properties of the root
+        VBox root = new VBox(5);
+        root.setStyle("-fx-background-color: SeaShell");
+        root.setAlignment(Pos.CENTER);
+        root.setPadding(new Insets(20));
+
+        //create the top button menu -> horizontal box
+        HBox buttons = new HBox();
+        buttons.setAlignment(Pos.CENTER);
+
+        //create the grid where the cells of the game will be added; set properties
+        GridPane grid = new GridPane();
+        grid.setAlignment(Pos.CENTER);
+        grid.setStyle("-fx-border-color: black; -fx-border-width: 4 4 4 4;");
+
+        //create the buttons to be added to the top menu of buttons
+        Button undo = new Button("Undo");
+        Button redo = new Button("Redo");
+        Button help = new Button("Enable Help");
+        Button clear = new Button("Clear");
+        Button hint = new Button("Hint");
+
+        //set properties for the buttons
+        undo.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;" +
+                "-fx-border-color: black; -fx-border-width: 4 4 4 4;");
+        redo.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;" +
+                "-fx-border-color: black; -fx-border-width: 4 4 4 4;");
+        help.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;" +
+                "-fx-border-color: black; -fx-border-width: 4 4 4 4;");
+        clear.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;" +
+                "-fx-border-color: black; -fx-border-width: 4 4 4 4;");
+        hint.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;" +
+                "-fx-border-color: black; -fx-border-width: 4 4 4 4;");
+
+        //disable the redo and undo buttons (there is nothing to undo or redo yet)
+        undo.setDisable(true);
+        redo.setDisable(true);
+
+        //set the functionality for each button from the top menu of buttons
+        handler.helpButton(help, grid);
+        handler.clearBoard(clear, grid, undo, redo);
+        handler.undoAction(undo, redo, grid);
+        handler.redoAction(redo, grid);
+        handler.hint(hint, grid);
+
+        buttons.getChildren().addAll(undo, redo, help, clear, hint); //add the buttons to the top button menu
+
+        handler.drawGrid(grid); //draw the cells in the grid
+        handler.addActions(grid, undo); //add actions to the undo stack when the undo button is pressed
+
+        //create the bottom button menu to change the font size of the numbers in the cells
+        HBox sizes = new HBox(5);
+        sizes.setAlignment(Pos.CENTER);
+
+        //create the buttons for the bottom menu buttons which will change the font size of the numbers in the cells
+        Button small = new Button("Small");
+        Button medium = new Button("Medium");
+        Button large = new Button("Large");
+
+        //set properties for the buttons from the bottom button menu
+        small.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;" +
+                " -fx-border-color: black; -fx-border-width: 4 4 4 4;");
+        medium.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen; " +
+                "-fx-border-color: black; -fx-border-width: 4 4 4 4;");
+        large.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen; " +
+                "-fx-border-color: black; -fx-border-width: 4 4 4 4;");
+
+        sizes.getChildren().addAll(small, medium, large); //add elements to the bottom menu of buttons
+
+        //add functionality to the font size changers
+        handler.changeFont(small, 20);
+        handler.changeFont(medium, 30);
+        handler.changeFont(large, 40);
+
+        Label note = new Label("Double click the space provided for text in cell"); //message for the player to
+        //be aware of the functionality
+
+        Button submit = new Button("Submit"); //submit button to check the answer
+        Button solve = new Button("Solve");
+
+        //set properties for the note and the submit button
+        note.setStyle("-fx-font-size: 15px; -fx-font-weight:bold;");
+        submit.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: pink; " +
+                "-fx-border-color: black; -fx-border-width: 4 4 4 4;");
+
+        //add functionalities to the submit button
+        handler.submitButton(submit, stage);
+        if((n != 6) && (n != 7) && (n != 8)) {
+            handler.solveBoard(grid);
+        } else {
+            hint.setDisable(true);
+        }
+
+        root.getChildren().addAll(buttons, grid, sizes, note, submit, solve); //add the elements to the root
+
+        handler.resize(root, grid); //resize the board of the game
+
+        //create the scene with the root the vertical box and set it to the stage
+        Scene scene = new Scene(root);
+        stage.setScene(scene);
+
+        //set properties for the stage
+        stage.setTitle("Mathdoku");
+        stage.initStyle(StageStyle.DECORATED);
+        stage.setX(700);
+        stage.setY(200);
+        stage.setMinHeight(700);
+        stage.setMinWidth(700);
+
+        return stage; //return the stage created
+    }
+
     /**
      * this method shows a window which will be displayed when the player double clicks on a cell to introduce
      * or delete values via mouse
@@ -183,126 +309,5 @@ public class Window {
 
         return alert; //return the warning alert created
     }
-
-    /**
-     * window that will create the game board and the buttons specific to it
-     * all the options for the game are accessed from this window
-     * @param n -> the size of the board nxn
-     * @param cages -> the cages that were extracted when a file was opened from the menu window
-     * @return Stage -> the Mathdoku window where a a user can play the game
-     */
-    public Stage mathdoku(int n, ArrayList<Cage> cages) {
-
-        Window.n = n; //set the size of the board to the n selected by the player in the menu window
-        Handler handler = new Handler(cages); //create a handler object to handle the functionalities of the game
-
-        Stage stage = new Stage(); //create the stage for the game
-
-        //create the root for the elements that will be added to the scene; set properties of the root
-        VBox root = new VBox(5);
-        root.setStyle("-fx-background-color: SeaShell");
-        root.setAlignment(Pos.CENTER);
-        root.setPadding(new Insets(20));
-
-        //create the top button menu -> horizontal box
-        HBox buttons = new HBox();
-        buttons.setAlignment(Pos.CENTER);
-
-        //create the grid where the cells of the game will be added; set properties
-        GridPane grid = new GridPane();
-        grid.setAlignment(Pos.CENTER);
-        grid.setStyle("-fx-border-color: black; -fx-border-width: 4 4 4 4;");
-
-        //create the buttons to be added to the top menu of buttons
-        Button undo = new Button("Undo");
-        Button redo = new Button("Redo");
-        Button help = new Button("Enable Help");
-        Button clear = new Button("Clear");
-        Button hint = new Button("Hint");
-
-        //set properties for the buttons
-        undo.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;" +
-                "-fx-border-color: black; -fx-border-width: 4 4 4 4;");
-        redo.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;" +
-                "-fx-border-color: black; -fx-border-width: 4 4 4 4;");
-        help.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;" +
-                "-fx-border-color: black; -fx-border-width: 4 4 4 4;");
-        clear.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;" +
-                "-fx-border-color: black; -fx-border-width: 4 4 4 4;");
-        hint.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;" +
-                "-fx-border-color: black; -fx-border-width: 4 4 4 4;");
-
-        //disable the redo and undo buttons (there is nothing to undo or redo yet)
-        undo.setDisable(true);
-        redo.setDisable(true);
-
-        //set the functionality for each button from the top menu of buttons
-        handler.helpButton(help, grid);
-        handler.clearBoard(clear, grid, undo, redo);
-        handler.undoAction(undo, redo, grid);
-        handler.redoAction(redo, grid);
-
-        buttons.getChildren().addAll(undo, redo, help, clear, hint); //add the buttons to the top button menu
-
-        handler.drawGrid(grid); //draw the cells in the grid
-        handler.addActions(grid, undo); //add actions to the undo stack when the undo button is pressed
-
-        //create the bottom button menu to change the font size of the numbers in the cells
-        HBox sizes = new HBox(5);
-        sizes.setAlignment(Pos.CENTER);
-
-        //create the buttons for the bottom menu buttons which will change the font size of the numbers in the cells
-        Button small = new Button("Small");
-        Button medium = new Button("Medium");
-        Button large = new Button("Large");
-
-        //set properties for the buttons from the bottom button menu
-        small.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;" +
-                " -fx-border-color: black; -fx-border-width: 4 4 4 4;");
-        medium.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen; " +
-                "-fx-border-color: black; -fx-border-width: 4 4 4 4;");
-        large.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen; " +
-                "-fx-border-color: black; -fx-border-width: 4 4 4 4;");
-
-        sizes.getChildren().addAll(small, medium, large); //add elements to the bottom menu of buttons
-
-        //add functionality to the font size changers
-        handler.changeFont(small, 20);
-        handler.changeFont(medium, 30);
-        handler.changeFont(large, 40);
-
-        Label note = new Label("Double click the space provided for text in cell"); //message for the player to
-                                                                                    //be aware of the functionality
-
-        Button submit = new Button("Submit"); //submit button to check the answer
-        Button solve = new Button("Solve");
-
-        //set properties for the note and the submit button
-        note.setStyle("-fx-font-size: 15px; -fx-font-weight:bold;");
-        submit.setStyle("-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: pink; " +
-                "-fx-border-color: black; -fx-border-width: 4 4 4 4;");
-
-        //add functionalities to the submit button
-        handler.submitButton(submit, stage);
-        handler.solveBoard(solve, grid, n);
-
-        root.getChildren().addAll(buttons, grid, sizes, note, submit); //add the elements to the root
-
-        handler.resize(root, grid); //resize the board of the game
-
-        //create the scene with the root the vertical box and set it to the stage
-        Scene scene = new Scene(root);
-        stage.setScene(scene);
-
-        //set properties for the stage
-        stage.setTitle("Mathdoku");
-        stage.initStyle(StageStyle.DECORATED);
-        stage.setX(700);
-        stage.setY(200);
-        stage.setMinHeight(700);
-        stage.setMinWidth(700);
-
-        return stage; //return the stage created
-    }
 }
 
-- 
GitLab