diff --git a/src/ihm/Main.java b/src/ihm/Main.java index 14c9a12..5c04127 100644 --- a/src/ihm/Main.java +++ b/src/ihm/Main.java @@ -5,10 +5,12 @@ import java.util.Locale; import java.util.ResourceBundle; import javafx.application.Application; +import javafx.event.EventHandler; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.stage.Stage; +import javafx.stage.WindowEvent; import main.GestionnaireJeu; public class Main extends Application { @@ -23,14 +25,21 @@ public class Main extends Application { primaryStage.setTitle("Shadow Hunters"); primaryStage.setScene(new Scene(root)); primaryStage.centerOnScreen(); + primaryStage.setOnCloseRequest(new EventHandler() { + @Override + public void handle(WindowEvent arg0) { + System.exit(0); + } + }); primaryStage.setMaximized(true); primaryStage.show(); } public static void main(String[] args) { - System.err.close(); + //System.err.close(); GestionnaireJeu gj = GestionnaireJeu.getGestionnaireJeu(); launch(args); + } } \ No newline at end of file diff --git a/src/ihm/Musique.java b/src/ihm/Musique.java index 536554d..d3f8a91 100644 --- a/src/ihm/Musique.java +++ b/src/ihm/Musique.java @@ -1,27 +1,28 @@ package ihm; -import java.io.File; +import java.io.BufferedInputStream; +import java.io.InputStream; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; -import ihm.controller.ParametreController; public class Musique { public static Clip clip; public static long clipTimePosition = 0; - public static void playMusique(String path) { + public static void playMusique(InputStream path) { try { - File musicPath = new File(path); + InputStream musicPath = path; - if (musicPath.exists()) { + if (musicPath!=null) { + InputStream bufferedIn = new BufferedInputStream(musicPath); - AudioInputStream audioInput = AudioSystem.getAudioInputStream(musicPath); + AudioInputStream audioInput = AudioSystem.getAudioInputStream(bufferedIn); clip = AudioSystem.getClip(); clip.open(audioInput); clip.start(); diff --git a/src/ihm/controller/ParametreController.java b/src/ihm/controller/ParametreController.java index 3f86b4b..8f3d5f8 100644 --- a/src/ihm/controller/ParametreController.java +++ b/src/ihm/controller/ParametreController.java @@ -2,6 +2,7 @@ package ihm.controller; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.net.URL; import java.util.Locale; import java.util.ResourceBundle; @@ -32,8 +33,8 @@ public class ParametreController implements Initializable { public EffetSonore soundEffects = new EffetSonore(); - String filepathMusique = "src//ihm//ressources//musique//The_Red_Fox_Tavern.wav"; // lien vers la musique : https://www.youtube.com/watch?v=LBpKUIyOHdo - File fileMusique = new File("src//ihm//ressources//musique//The_Red_Fox_Tavern.wav"); + String filepathMusique = "/ihm/ressources/musique/The_Red_Fox_Tavern.wav"; // lien vers la musique : https://www.youtube.com/watch?v=LBpKUIyOHdo + InputStream fileMusique = getClass().getResourceAsStream("/ihm/ressources/musique/The_Red_Fox_Tavern.wav"); File repertoire = new File("src//ihm//ressources"); File repertoire2; @@ -57,12 +58,12 @@ public class ParametreController implements Initializable { public void enregistre(MouseEvent mouseEvent) throws IOException, Exception { //Pour la musique - if (fileMusique.exists()) { + if (fileMusique!=null) { if (cmusique.isSelected() == true) { coche = true; if (Musique.clipTimePosition == 0 && MusiqueLancee == false) { // si la musique n'a jamais été lancé - Musique.playMusique(filepathMusique); + Musique.playMusique(fileMusique); MusiqueLancee = true; } else { @@ -78,6 +79,7 @@ public class ParametreController implements Initializable { } } + else System.out.println("asd"); //Pour les effets sonores if (cbEffetSonore.isSelected() == true) { diff --git a/src/ihm/controller/PlateauControllerTest.java b/src/ihm/controller/PlateauControllerTest.java index a551adc..d39e303 100644 --- a/src/ihm/controller/PlateauControllerTest.java +++ b/src/ihm/controller/PlateauControllerTest.java @@ -38,7 +38,7 @@ public class PlateauControllerTest implements Initializable { AnchorPane ap = getAnchorPaneJoueur(i); Pane p; try { - p = FXMLLoader.load(getClass().getResource("../ressources/MenuJoueur.fxml")); + p = FXMLLoader.load(getClass().getResource("/ihm/ressources/MenuJoueur.fxml")); if(i > 1 && i < 3) { rotateContent(p, 90); }