All checks were successful
continuous-integration/drone/push Build is passing
A simple button to load a previous game Co-authored-by: Mat <diletomatteo@gmail.com> Reviewed-on: #68 Reviewed-by: Debucquoy Anthony <d.tonitch@gmail.com>
69 lines
1.8 KiB
Java
69 lines
1.8 KiB
Java
package school_project;
|
|
|
|
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;
|
|
|
|
|
|
public class Controller extends Application {
|
|
private static Stage stage;
|
|
Parent root;
|
|
public static Vec2 screen_size;
|
|
|
|
@Override
|
|
public void start(Stage primaryStage) throws IOException {
|
|
new File("save.slevel");
|
|
stage = primaryStage;
|
|
screen_size = new Vec2(
|
|
(int) Screen.getPrimary().getBounds().getWidth(),
|
|
(int) Screen.getPrimary().getBounds().getHeight()
|
|
);
|
|
|
|
stage.setTitle("ROAD TO MASTER YOU");
|
|
|
|
// Full Screen mode
|
|
stage.setFullScreen(true);
|
|
stage.setFullScreenExitHint("");
|
|
primaryStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
|
|
|
|
root = new MenuAccueil();
|
|
|
|
switchRoot(root);
|
|
stage.show();
|
|
}
|
|
|
|
|
|
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) {
|
|
launch();
|
|
}
|
|
}
|
|
|
|
|