From aa6e52ea6d12604b09f16d810c508b6422750abf Mon Sep 17 00:00:00 2001 From: Debucquoy Date: Tue, 9 May 2023 16:32:08 +0200 Subject: [PATCH] exemple de level loader --- .../main/java/school_project/Menu/MenuLevel.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/src/main/java/school_project/Menu/MenuLevel.java b/app/src/main/java/school_project/Menu/MenuLevel.java index f86f699..8c819c8 100644 --- a/app/src/main/java/school_project/Menu/MenuLevel.java +++ b/app/src/main/java/school_project/Menu/MenuLevel.java @@ -7,6 +7,12 @@ import javafx.scene.layout.ColumnConstraints; import javafx.scene.layout.GridPane; import javafx.scene.layout.RowConstraints; import school_project.Controller; +import school_project.GameUI; +import school_project.Map; +import school_project.Parsers.FileParserFactory; + +import java.io.File; +import java.io.IOException; public class MenuLevel extends GridPane { private int StartLevel; @@ -62,6 +68,16 @@ public class MenuLevel extends GridPane { for (int j = 1; j < 5; j++) { if(i==0){ Button Level = new Button("level "+(StartLevel)); + Level.setOnAction(event -> { + try { + String level_name = Level.getText().replace(" ", "") + ".level"; + Map map_file = FileParserFactory.loadMapFromFile(new File(Controller.class.getResource(level_name).getFile())); + GameUI root = new GameUI(map_file); + Controller.switchRoot(root); + } catch (IOException e) { + System.out.println("le niveau n'existe pas"); + } + }); StartLevel+=3; add(Level,i,j); setHalignment(Level,HPos.CENTER); -- 2.46.0