From bde347d84c92218e9bef920f9e6142cd5e9a426d Mon Sep 17 00:00:00 2001 From: Mat Date: Thu, 18 May 2023 16:44:36 +0200 Subject: [PATCH] Almost work but the link to the difficulty doens't work everytime idk why --- .../java/school_project/Menu/MenuAccueil.java | 50 +++++++++++++------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/school_project/Menu/MenuAccueil.java b/app/src/main/java/school_project/Menu/MenuAccueil.java index 2135bfd..e07cb9d 100644 --- a/app/src/main/java/school_project/Menu/MenuAccueil.java +++ b/app/src/main/java/school_project/Menu/MenuAccueil.java @@ -8,7 +8,9 @@ import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.scene.text.Font; import school_project.Controller; +import school_project.GameUI; import school_project.MapGenerator; +import java.io.FileNotFoundException; public class MenuAccueil extends StackPane { @@ -21,21 +23,41 @@ public class MenuAccueil extends StackPane { Label RdmLvl = new Label("Random Level : "); Button SelectLevel= new Button("Select Level"); Label Title = new Label("Welcome to Road to Master"); - SlctDifficulty.setOnAction(event -> { - String choosediff = SlctDifficulty.getSelectionModel().getSelectedItem(); - System.out.println(choosediff); - switch(choosediff){ - case "Easy": - SlctDifficulty.setOnAction(event1 -> MapGenerator.generate(MapGenerator.Difficulty.Easy)); - break; - case "Medium": - SlctDifficulty.setOnAction(event1 -> MapGenerator.generate(MapGenerator.Difficulty.Medium)); - break; - case "Difficult": - SlctDifficulty.setOnAction(event1 -> MapGenerator.generate(MapGenerator.Difficulty.Difficult)); - break; - }}); + SlctDifficulty.setOnAction(event -> { + String choosediff = SlctDifficulty.getSelectionModel().getSelectedItem(); + System.out.println(choosediff); + switch (choosediff) { + case "Easy": + SlctDifficulty.setOnAction(event1 -> { + try { + Controller.switchRoot(new GameUI(MapGenerator.generate(MapGenerator.Difficulty.Easy))); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + }); + break; + case "Medium": + SlctDifficulty.setOnAction(event1 -> { + try { + Controller.switchRoot(new GameUI(MapGenerator.generate(MapGenerator.Difficulty.Medium))); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + }); + break; + case "Difficult": + SlctDifficulty.setOnAction(event1 -> { + try { + Controller.switchRoot(new GameUI(MapGenerator.generate(MapGenerator.Difficulty.Difficult))); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + }); + + break; + } + }); //set up all the Button where I need getChildren().addAll(Title,SlctDifficulty,SelectLevel,RdmLvl);