make button join the level
This commit is contained in:
parent
2ac53b399f
commit
587e2bf699
@ -7,6 +7,11 @@ 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.Parsers.FileParserFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MenuLevel extends GridPane {
|
||||
private int StartLevel;
|
||||
@ -60,30 +65,38 @@ public class MenuLevel extends GridPane {
|
||||
//It's here that I put all buttons where I need (base on column not row)
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 1; j < 5; j++) {
|
||||
Button levelButton = new Button("level "+(StartLevel));
|
||||
levelButton.setOnAction(event -> {
|
||||
try {
|
||||
String levelName = ((Button)event.getSource()).getText().replace(" ", "") + ".level";
|
||||
System.out.println(levelName);
|
||||
GameUI level = new GameUI(FileParserFactory.loadMapFromFile(new File(Controller.class.getResource("levels/" + levelName).getFile())));
|
||||
Controller.switchRoot(level);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Le niveau " + StartLevel + "n'existe pas.");
|
||||
}
|
||||
});
|
||||
if(i==0){
|
||||
Button Level = new Button("level "+(StartLevel));
|
||||
StartLevel+=3;
|
||||
add(Level,i,j);
|
||||
setHalignment(Level,HPos.CENTER);
|
||||
add(levelButton,i,j);
|
||||
setHalignment(levelButton,HPos.CENTER);
|
||||
if(j==4){
|
||||
StartLevel-=11;
|
||||
}
|
||||
}
|
||||
else if(i==1&&j!=4) {
|
||||
Button Level = new Button("level "+(StartLevel));
|
||||
StartLevel += 3;
|
||||
add(Level, i, j);
|
||||
setHalignment(Level,HPos.CENTER);
|
||||
add(levelButton, i, j);
|
||||
setHalignment(levelButton,HPos.CENTER);
|
||||
if (j == 3) {
|
||||
StartLevel -=8;
|
||||
|
||||
}
|
||||
}
|
||||
else if(i==2&&j!=4){
|
||||
Button Level = new Button("level "+(StartLevel));
|
||||
StartLevel+=3;
|
||||
add(Level,i,j);
|
||||
setHalignment(Level,HPos.CENTER);
|
||||
add(levelButton,i,j);
|
||||
setHalignment(levelButton,HPos.CENTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user