Save the level when pressing escape in a level
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Debucquoy Anthony 2023-05-18 17:55:58 +02:00
parent d611d52bb8
commit a394ad009f
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
2 changed files with 23 additions and 1 deletions

View File

@ -4,11 +4,14 @@ import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCombination;
import javafx.stage.Screen;
import javafx.stage.Stage;
import school_project.Menu.MenuAccueil;
import school_project.Parsers.FileParserFactory;
import java.io.File;
import java.io.IOException;
@ -41,6 +44,19 @@ public class Controller extends Application {
public static void switchRoot(Parent root){
Scene scene = new Scene(root);
if(root instanceof GameUI){
scene.setOnKeyPressed(event ->{
GameUI game = (GameUI) root;
if(event.getCode() == KeyCode.ESCAPE){
try {
FileParserFactory.saveFileFromMap(new File("save.slevel"), game.getLevel());
switchRoot(new MenuAccueil());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
}
stage.setScene(scene);
}
public static void main(String[] args) {

View File

@ -12,8 +12,11 @@ public class GameUI extends Group{
public final static int SPACE_SIZE = 5;
private final Vec2 piece_pos_click = new Vec2();
private Map level;
public GameUI(Map level) throws FileNotFoundException {
super();
this.level = level;
MatrixShape grid = new MatrixShape(level);
@ -77,8 +80,11 @@ public class GameUI extends Group{
}
}
});
getChildren().add(_piece);
}
}
public Map getLevel() {
return level;
}
}