ajout des effets sonores
This commit is contained in:
parent
1bc6fd188d
commit
11bf281ea3
56
src/ihm/EffetSonore.java
Normal file
56
src/ihm/EffetSonore.java
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package ihm;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import javax.sound.sampled.AudioInputStream;
|
||||||
|
import javax.sound.sampled.AudioSystem;
|
||||||
|
import javax.sound.sampled.Clip;
|
||||||
|
|
||||||
|
public class EffetSonore {
|
||||||
|
|
||||||
|
boolean soundOK;
|
||||||
|
|
||||||
|
public EffetSonore() {
|
||||||
|
this.soundOK = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playSoundEffect(String path) {
|
||||||
|
|
||||||
|
if (this.soundOK == true) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
File soundPath = new File(path);
|
||||||
|
|
||||||
|
if (soundPath.exists()) {
|
||||||
|
|
||||||
|
AudioInputStream audioInput = AudioSystem.getAudioInputStream(soundPath);
|
||||||
|
Clip clipSound = AudioSystem.getClip();
|
||||||
|
clipSound.open(audioInput);
|
||||||
|
clipSound.start();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
System.out.println("le fichier audio n'est pas trouvé");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSoundOK() {
|
||||||
|
return soundOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSoundOK(boolean soundOK) {
|
||||||
|
this.soundOK = soundOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -6,6 +6,8 @@ import javax.sound.sampled.AudioInputStream;
|
|||||||
import javax.sound.sampled.AudioSystem;
|
import javax.sound.sampled.AudioSystem;
|
||||||
import javax.sound.sampled.Clip;
|
import javax.sound.sampled.Clip;
|
||||||
|
|
||||||
|
import ihm.controller.ParametreController;
|
||||||
|
|
||||||
public class Musique {
|
public class Musique {
|
||||||
|
|
||||||
public static Clip clip;
|
public static Clip clip;
|
||||||
|
@ -6,6 +6,7 @@ import java.net.URL;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
import ihm.EffetSonore;
|
||||||
import ihm.Musique;
|
import ihm.Musique;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
@ -21,20 +22,28 @@ public class ParametreController implements Initializable {
|
|||||||
@FXML
|
@FXML
|
||||||
private CheckBox cmusique;
|
private CheckBox cmusique;
|
||||||
@FXML
|
@FXML
|
||||||
|
private CheckBox cbEffetSonore;
|
||||||
|
@FXML
|
||||||
private CheckBox clair;
|
private CheckBox clair;
|
||||||
@FXML
|
@FXML
|
||||||
private ComboBox<String> langues;
|
private ComboBox<String> langues;
|
||||||
boolean coche = false; // verifi si la checbox musical est coche
|
boolean coche = false; // verifi si la checbox musical est coche
|
||||||
boolean MusiqueLancee = false; //verifi si la musique a déja été lancé une première fois
|
boolean MusiqueLancee = false; //verifi si la musique a déja été lancé une première fois
|
||||||
|
|
||||||
String filepath = "src//ihm//ressources//musique//The_Red_Fox_Tavern.wav"; // lien vers la musique :
|
public EffetSonore soundEffects = new EffetSonore();
|
||||||
// https://www.youtube.com/watch?v=LBpKUIyOHdo
|
|
||||||
File files = new File("src//ihm//ressources//musique//The_Red_Fox_Tavern.wav");
|
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");
|
||||||
|
|
||||||
File repertoire = new File("src//ihm//ressources");
|
File repertoire = new File("src//ihm//ressources");
|
||||||
|
File repertoire2;
|
||||||
String liste[] = repertoire.list();
|
String liste[] = repertoire.list();
|
||||||
|
|
||||||
|
/*
|
||||||
|
public void ParametreController() {
|
||||||
|
EffetSonore sound = soundEffects;
|
||||||
|
}*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL arg0, ResourceBundle arg1) {
|
public void initialize(URL arg0, ResourceBundle arg1) {
|
||||||
langues.getItems().add("Anglais");
|
langues.getItems().add("Anglais");
|
||||||
@ -47,12 +56,13 @@ public class ParametreController implements Initializable {
|
|||||||
@FXML
|
@FXML
|
||||||
public void enregistre(MouseEvent mouseEvent) throws IOException, Exception {
|
public void enregistre(MouseEvent mouseEvent) throws IOException, Exception {
|
||||||
|
|
||||||
if (files.exists()) {
|
//Pour la musique
|
||||||
|
if (fileMusique.exists()) {
|
||||||
|
|
||||||
if (cmusique.isSelected() == true) {
|
if (cmusique.isSelected() == true) {
|
||||||
coche = true;
|
coche = true;
|
||||||
if (Musique.clipTimePosition == 0 && MusiqueLancee == false) { // si la musique n'a jamais été lancé
|
if (Musique.clipTimePosition == 0 && MusiqueLancee == false) { // si la musique n'a jamais été lancé
|
||||||
Musique.playMusique(filepath);
|
Musique.playMusique(filepathMusique);
|
||||||
MusiqueLancee = true;
|
MusiqueLancee = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -69,25 +79,74 @@ public class ParametreController implements Initializable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Pour les effets sonores
|
||||||
|
if (cbEffetSonore.isSelected() == true) {
|
||||||
|
soundEffects.setSoundOK(true);
|
||||||
|
|
||||||
/*
|
System.out.println(soundEffects.isSoundOK());
|
||||||
* if(clair.isSelected()) { Pane root =
|
}
|
||||||
* FXMLLoader.load(getClass().getResource("ressources/parametre.fxml"));
|
|
||||||
* root.setStyle("ressources/style/menuLight.css"); if (liste != null) { for
|
|
||||||
* (int i = 0; i < liste.length; i++) { System.out.println(liste[i]); Pane root1
|
|
||||||
* = FXMLLoader.load(getClass().getResource(liste[i]));
|
|
||||||
* root1.setStyle("ressources/style/menuLight.css"); } }
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
|
|
||||||
final URL fxmlURL = getClass().getResource("../ressources/Jouer_tour(3)attaquer.fxml");
|
else {
|
||||||
|
soundEffects.setSoundOK(false);
|
||||||
|
System.out.println(soundEffects.isSoundOK());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Pour la couleur du theme
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (clair.isSelected()) {
|
||||||
|
//Pane root = FXMLLoader.load(getClass().getResource("../ressources/parametre.fxml"));
|
||||||
|
//root.setStyle("ressources/style/menuLight.css");
|
||||||
|
|
||||||
|
if (liste != null) {
|
||||||
|
for (int i = 0; i < liste.length; i++) {
|
||||||
|
|
||||||
|
System.out.println(liste[i]);
|
||||||
|
System.out.println(i);
|
||||||
|
repertoire2 = new File("../ressources/" + liste[i]);
|
||||||
|
|
||||||
|
if (repertoire.isDirectory() == false) {
|
||||||
|
if (liste[i] == "Plateau.fxml") {
|
||||||
|
Pane root1 = FXMLLoader.load(getClass().getResource("../ressources/" + liste[i]));
|
||||||
|
root1.setStyle("../ressources/style/plateau.css");
|
||||||
|
|
||||||
|
}
|
||||||
|
Pane root1 = FXMLLoader.load(getClass().getResource("../ressources/" + liste[i]));
|
||||||
|
root1.setStyle("../ressources/style/menuLight.css");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
soundEffects.playSoundEffect("src//ihm//ressources//musique//BEEP1.wav"); //emet un bruit sur le bouton si les effets sonores sont activés
|
||||||
|
|
||||||
|
// Quitter les paramètres
|
||||||
|
final URL fxmlURL = getClass().getResource("../ressources/Menu.fxml");
|
||||||
final ResourceBundle bundle = ResourceBundle.getBundle("domaine.properties.langue", Locale.FRANCE);
|
final ResourceBundle bundle = ResourceBundle.getBundle("domaine.properties.langue", Locale.FRANCE);
|
||||||
final FXMLLoader fxmlLoader = new FXMLLoader(fxmlURL, bundle);
|
final FXMLLoader fxmlLoader = new FXMLLoader(fxmlURL, bundle);
|
||||||
Pane pane = fxmlLoader.load();
|
Pane pane = fxmlLoader.load();
|
||||||
|
|
||||||
rootPane.getChildren().setAll(pane);
|
rootPane.getChildren().setAll(pane);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//getters and setters
|
||||||
|
public EffetSonore getSoundEffects() {
|
||||||
|
return soundEffects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSoundEffects(EffetSonore soundEffects) {
|
||||||
|
this.soundEffects = soundEffects;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
BIN
src/ihm/ressources/musique/BEEP1.wav
Normal file
BIN
src/ihm/ressources/musique/BEEP1.wav
Normal file
Binary file not shown.
@ -17,7 +17,7 @@
|
|||||||
<children>
|
<children>
|
||||||
<CheckBox fx:id="clair" mnemonicParsing="false" styleClass="checkBox" text="%mode.claire" />
|
<CheckBox fx:id="clair" mnemonicParsing="false" styleClass="checkBox" text="%mode.claire" />
|
||||||
<CheckBox fx:id="cmusique" mnemonicParsing="false" styleClass="checkBox" text="%musique" />
|
<CheckBox fx:id="cmusique" mnemonicParsing="false" styleClass="checkBox" text="%musique" />
|
||||||
<CheckBox mnemonicParsing="false" styleClass="checkBox" text="%effet" />
|
<CheckBox fx:id="cbEffetSonore" mnemonicParsing="false" styleClass="checkBox" text="%effet" />
|
||||||
<VBox prefHeight="200.0" prefWidth="100.0" spacing="10.0">
|
<VBox prefHeight="200.0" prefWidth="100.0" spacing="10.0">
|
||||||
<children>
|
<children>
|
||||||
<Label styleClass="titre" text="%langue">
|
<Label styleClass="titre" text="%langue">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user