saveLevel #69

Merged
tonitch merged 2 commits from saveLevel into master 2023-05-18 18:32:18 +02:00
3 changed files with 24 additions and 1 deletions

1
.gitignore vendored
View File

@ -53,3 +53,4 @@ build
.idea/ .idea/
.settings/ .settings/
*.slevel

View File

@ -4,11 +4,14 @@ import javafx.application.Application;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCombination; import javafx.scene.input.KeyCombination;
import javafx.stage.Screen; import javafx.stage.Screen;
import javafx.stage.Stage; import javafx.stage.Stage;
import school_project.Menu.MenuAccueil; import school_project.Menu.MenuAccueil;
import school_project.Parsers.FileParserFactory;
import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -41,6 +44,19 @@ public class Controller extends Application {
public static void switchRoot(Parent root){ public static void switchRoot(Parent root){
Scene scene = new Scene(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); stage.setScene(scene);
} }
public static void main(String[] args) { public static void main(String[] args) {

View File

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