exemple de level loader
This commit is contained in:
parent
a472df26ed
commit
aa6e52ea6d
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user