diff --git a/src/main/java/launcher/Launcher.java b/src/main/java/launcher/Launcher.java index c03236b..32d8552 100644 --- a/src/main/java/launcher/Launcher.java +++ b/src/main/java/launcher/Launcher.java @@ -2,6 +2,7 @@ package launcher; import gameplay.match.*; import javafx.application.Application; +import javafx.application.Platform; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Parent; @@ -9,10 +10,12 @@ import javafx.scene.Scene; import javafx.scene.control.ChoiceBox; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.control.CheckBox; import javafx.stage.Stage; import javafx.stage.StageStyle; +import javafx.stage.Window; import javafx.fxml.*; import java.io.IOException; @@ -166,9 +169,22 @@ public class Launcher extends Application { try { fillArraySettings(); setter.setSettings(); - match.main(null); + hideWindow(); + Thread t = new Thread() { + public void run() { + try { + match.main(null); + } catch (Exception e) { + e.printStackTrace(); + } + } + }; + t.start(); + t.join(); + showWindow(); } catch (Exception e) { - System.out.println("Fill all boxes to launch the game"); + e.printStackTrace(); + System.exit(1); } } @@ -245,6 +261,28 @@ public class Launcher extends Application { arraysettings.put("stage", "default"); } + /** + * hides the launcher + */ + @FXML + private void hideWindow() { + HBox hb = (HBox) namespace.get("window"); + Scene sc = hb.getScene(); + Window win = sc.getWindow(); + win.hide(); + } + + /** + * shows the launcher + * @throws Exception + */ + @FXML + private void showWindow() throws Exception { + setter.parse(); + Stage st = new Stage(); + start(st); + } + /** * quits the launcher and the game */ diff --git a/src/main/java/launcher/Settings.java b/src/main/java/launcher/Settings.java index 6a3e12e..ad9085e 100644 --- a/src/main/java/launcher/Settings.java +++ b/src/main/java/launcher/Settings.java @@ -41,7 +41,7 @@ public class Settings { * @author François Autin * @author Indy Boyeau */ - private void parse() throws Exception { + protected void parse() throws Exception { // Initializing the parser JSONParser jsonP = new JSONParser(); @@ -93,7 +93,7 @@ public class Settings { } catch (IOException e) { e.printStackTrace(); System.exit(1); - } catch (ParseException e) { + } catch (Exception e) { rounds = 3; p1 = "default"; p2 = "default";