add_loadbutton #68
@ -9,6 +9,7 @@ import javafx.stage.Screen;
 | 
				
			|||||||
import javafx.stage.Stage;
 | 
					import javafx.stage.Stage;
 | 
				
			||||||
import school_project.Menu.MenuAccueil;
 | 
					import school_project.Menu.MenuAccueil;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.File;
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -19,6 +20,7 @@ public class Controller extends Application {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void start(Stage primaryStage) throws IOException {
 | 
					    public void start(Stage primaryStage) throws IOException {
 | 
				
			||||||
 | 
					        new File("save.slevel");
 | 
				
			||||||
        stage = primaryStage;
 | 
					        stage = primaryStage;
 | 
				
			||||||
        screen_size = new Vec2(
 | 
					        screen_size = new Vec2(
 | 
				
			||||||
            (int) Screen.getPrimary().getBounds().getWidth(),
 | 
					            (int) Screen.getPrimary().getBounds().getWidth(),
 | 
				
			||||||
 | 
				
			|||||||
@ -2,41 +2,88 @@ package school_project.Menu;
 | 
				
			|||||||
import javafx.geometry.Insets;
 | 
					import javafx.geometry.Insets;
 | 
				
			||||||
import javafx.geometry.Pos;
 | 
					import javafx.geometry.Pos;
 | 
				
			||||||
import javafx.scene.control.Button;
 | 
					import javafx.scene.control.Button;
 | 
				
			||||||
 | 
					import javafx.scene.control.ChoiceBox;
 | 
				
			||||||
import javafx.scene.control.Label;
 | 
					import javafx.scene.control.Label;
 | 
				
			||||||
import javafx.scene.layout.BorderPane;
 | 
					import javafx.scene.layout.StackPane;
 | 
				
			||||||
import javafx.scene.paint.Color;
 | 
					import javafx.scene.paint.Color;
 | 
				
			||||||
import javafx.scene.text.Font;
 | 
					import javafx.scene.text.Font;
 | 
				
			||||||
import school_project.Controller;
 | 
					import school_project.Controller;
 | 
				
			||||||
public class MenuAccueil extends BorderPane {
 | 
					import school_project.GameUI;
 | 
				
			||||||
 | 
					import school_project.MapGenerator;
 | 
				
			||||||
 | 
					import school_project.Parsers.FileParserFactory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.File;
 | 
				
			||||||
 | 
					import java.io.FileNotFoundException;
 | 
				
			||||||
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class MenuAccueil extends StackPane {
 | 
				
			||||||
    public MenuAccueil(){
 | 
					    public MenuAccueil(){
 | 
				
			||||||
        super();
 | 
					        super();
 | 
				
			||||||
        //create all the objet that i need
 | 
					        //create all the objet that I need
 | 
				
			||||||
        Button Play = new Button("Play");
 | 
					        ChoiceBox<String> SlctDifficulty = new ChoiceBox<>();
 | 
				
			||||||
 | 
					        SlctDifficulty.getItems().addAll("Easy", "Medium", "Difficult");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Label RdmLvl = new Label("Random Level : ");
 | 
				
			||||||
 | 
					        Button LoadLvl = new Button("Load game");
 | 
				
			||||||
        Button SelectLevel= new Button("Select Level");
 | 
					        Button SelectLevel= new Button("Select Level");
 | 
				
			||||||
        Button Trophy = new Button("Trophy");
 | 
					
 | 
				
			||||||
        Label Title = new Label("Welcome to Road to Master");
 | 
					        Label Title = new Label("Welcome to Road to Master");
 | 
				
			||||||
        //set up all the Button where i need
 | 
					            SlctDifficulty.setOnAction(event -> {
 | 
				
			||||||
        setTop(Title);
 | 
					                String choosediff = SlctDifficulty.getSelectionModel().getSelectedItem();
 | 
				
			||||||
        setLeft(Play);
 | 
					                System.out.println(choosediff);
 | 
				
			||||||
        setRight(SelectLevel);
 | 
					                switch (choosediff) {
 | 
				
			||||||
        setBottom(Trophy);
 | 
					                    case "Easy":
 | 
				
			||||||
        Title.setFont(Font.font(20));
 | 
					                        try {
 | 
				
			||||||
        Title.setTextFill(Color.GOLD);
 | 
					                            Controller.switchRoot(new GameUI(MapGenerator.generate(MapGenerator.Difficulty.Easy)));
 | 
				
			||||||
        setAlignment(Title, Pos.CENTER);
 | 
					                        } catch (FileNotFoundException e) {
 | 
				
			||||||
        setAlignment(Play,Pos.CENTER);
 | 
					                            throw new RuntimeException(e);
 | 
				
			||||||
        setAlignment(SelectLevel,Pos.CENTER);
 | 
					                        }
 | 
				
			||||||
        setAlignment(Trophy,Pos.CENTER);
 | 
					                        break;
 | 
				
			||||||
        setPadding(new Insets(20,60,20,60));
 | 
					                    case "Medium":
 | 
				
			||||||
 | 
					                            try {
 | 
				
			||||||
 | 
					                                Controller.switchRoot(new GameUI(MapGenerator.generate(MapGenerator.Difficulty.Medium)));
 | 
				
			||||||
 | 
					                            } catch (FileNotFoundException e) {
 | 
				
			||||||
 | 
					                                throw new RuntimeException(e);
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                        break;
 | 
				
			||||||
 | 
					                    case "Difficult":
 | 
				
			||||||
 | 
					                            try {
 | 
				
			||||||
 | 
					                                Controller.switchRoot(new GameUI(MapGenerator.generate(MapGenerator.Difficulty.Difficult)));
 | 
				
			||||||
 | 
					                            } catch (FileNotFoundException e) {
 | 
				
			||||||
 | 
					                                throw new RuntimeException(e);
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                        break;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //set up all the Button where I need
 | 
				
			||||||
 | 
					        getChildren().addAll(Title,SlctDifficulty,SelectLevel,RdmLvl,LoadLvl);
 | 
				
			||||||
 | 
					        RdmLvl.setFont(Font.font(25));
 | 
				
			||||||
 | 
					        RdmLvl.setTextFill(Color.GOLD);
 | 
				
			||||||
 | 
					        Title.setFont(Font.font(40));
 | 
				
			||||||
 | 
					        Title.setTextFill(Color.RED);
 | 
				
			||||||
 | 
					        setAlignment(Title, Pos.TOP_CENTER);
 | 
				
			||||||
 | 
					        setAlignment(LoadLvl,Pos.BOTTOM_CENTER);
 | 
				
			||||||
 | 
					        setAlignment(SlctDifficulty,Pos.CENTER_LEFT);
 | 
				
			||||||
 | 
					        setAlignment(SelectLevel,Pos.CENTER_RIGHT);
 | 
				
			||||||
 | 
					        setAlignment(RdmLvl, Pos.CENTER_LEFT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        setMargin(RdmLvl,new Insets(0,0,0,100));
 | 
				
			||||||
 | 
					        setMargin(SlctDifficulty,new Insets(0,0,0,300));
 | 
				
			||||||
 | 
					        setMargin(SelectLevel,new Insets(0,300,0,0));
 | 
				
			||||||
 | 
					        setMargin(Title,new Insets(200,0,0,0));
 | 
				
			||||||
 | 
					        setMargin(LoadLvl,new Insets(0,0,200,0));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        SelectLevel.setOnAction(event ->  Controller.switchRoot(new MenuLevel(1)));
 | 
					        SelectLevel.setOnAction(event ->  Controller.switchRoot(new MenuLevel(1)));
 | 
				
			||||||
 | 
					        LoadLvl.setOnAction(event -> {
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                FileParserFactory.loadMapFromFile(new File("save.slevel"));
 | 
				
			||||||
 | 
					            } catch (IOException e) {
 | 
				
			||||||
 | 
					                throw new RuntimeException(e);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        getStyleClass().add("BorderPane");
 | 
					        getStyleClass().add("BorderPane");
 | 
				
			||||||
        getStylesheets().add(String.valueOf(getClass().getResource("StyleMenuAcceuil.css")));
 | 
					        getStylesheets().add(String.valueOf(getClass().getResource("StyleMenuAcceuil.css")));
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user