2023-02-25 13:55:35 +01:00
|
|
|
package school_project;
|
|
|
|
|
|
|
|
import javafx.application.Application;
|
2023-05-04 23:24:18 +02:00
|
|
|
import javafx.scene.Parent;
|
2023-02-25 13:55:35 +01:00
|
|
|
import javafx.scene.Scene;
|
2023-05-04 23:24:18 +02:00
|
|
|
|
2023-05-18 18:32:16 +02:00
|
|
|
import javafx.scene.input.KeyCode;
|
2023-05-04 23:24:18 +02:00
|
|
|
import javafx.scene.input.KeyCombination;
|
|
|
|
import javafx.stage.Screen;
|
2023-02-25 13:55:35 +01:00
|
|
|
import javafx.stage.Stage;
|
2023-05-15 23:58:12 +02:00
|
|
|
import school_project.Menu.MenuAccueil;
|
2023-05-18 18:32:16 +02:00
|
|
|
import school_project.Parsers.FileParserFactory;
|
2023-05-04 23:24:18 +02:00
|
|
|
|
2023-05-18 18:32:16 +02:00
|
|
|
import java.io.File;
|
2023-05-04 23:24:18 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2023-02-25 13:55:35 +01:00
|
|
|
|
|
|
|
public class Controller extends Application {
|
2023-05-04 18:22:23 +02:00
|
|
|
private static Stage stage;
|
2023-05-04 23:24:18 +02:00
|
|
|
Parent root;
|
|
|
|
public static Vec2 screen_size;
|
2023-02-25 13:55:35 +01:00
|
|
|
|
|
|
|
@Override
|
2023-05-04 23:24:18 +02:00
|
|
|
public void start(Stage primaryStage) throws IOException {
|
2023-05-18 18:36:25 +02:00
|
|
|
new File("save.slevel");
|
2023-05-04 23:24:18 +02:00
|
|
|
stage = primaryStage;
|
|
|
|
screen_size = new Vec2(
|
|
|
|
(int) Screen.getPrimary().getBounds().getWidth(),
|
|
|
|
(int) Screen.getPrimary().getBounds().getHeight()
|
|
|
|
);
|
|
|
|
|
|
|
|
stage.setTitle("ROAD TO MASTER YOU");
|
2023-02-25 13:55:35 +01:00
|
|
|
|
2023-05-04 23:24:18 +02:00
|
|
|
// Full Screen mode
|
|
|
|
stage.setFullScreen(true);
|
|
|
|
stage.setFullScreenExitHint("");
|
|
|
|
primaryStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
|
2023-02-25 13:55:35 +01:00
|
|
|
|
2023-05-15 23:58:12 +02:00
|
|
|
root = new MenuAccueil();
|
2023-02-25 13:55:35 +01:00
|
|
|
|
2023-05-09 12:56:33 +02:00
|
|
|
switchRoot(root);
|
2023-05-04 23:24:18 +02:00
|
|
|
stage.show();
|
2023-02-25 13:55:35 +01:00
|
|
|
}
|
|
|
|
|
2023-05-04 18:22:23 +02:00
|
|
|
|
|
|
|
public static void switchRoot(Parent root){
|
2023-05-09 12:56:33 +02:00
|
|
|
Scene scene = new Scene(root);
|
2023-05-18 18:32:16 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-05-09 12:56:33 +02:00
|
|
|
stage.setScene(scene);
|
2023-04-28 11:28:10 +02:00
|
|
|
}
|
2023-02-25 13:55:35 +01:00
|
|
|
public static void main(String[] args) {
|
2023-05-06 21:45:56 +02:00
|
|
|
launch();
|
2023-02-25 13:55:35 +01:00
|
|
|
}
|
|
|
|
}
|
2023-04-28 11:28:10 +02:00
|
|
|
|
|
|
|
|