Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider 4d80ecb3 rédigé par Pierrick Lermite's avatar Pierrick Lermite
Parcourir les fichiers

audio victoire

parent a1e7f140
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Fichier ajouté
Fichier ajouté
Fichier ajouté
......@@ -8,6 +8,7 @@ import javax.swing.JPanel;
import App.Display.*;
import App.Player.GhostPlayer;
import App.Sound.SoundFile;
/**
* La classe GamePanel représente le panneau principal du jeu, héritant de JPanel et implémentant Runnable.
......@@ -34,6 +35,11 @@ public class GamePanel extends JPanel implements Runnable{
// Set Player's default position
Ground game = new Ground(15, 13);
// Chargement Audio
SoundFile s_p1win = new SoundFile("./Audio/Player1win.wav");
SoundFile s_p2win = new SoundFile("./Audio/Player2win.wav");
SoundFile s_draw = new SoundFile("./Audio/DrawYouAllDied.wav");
/**
* Constructeur de la classe GamePanel.
* Initialise les paramètres de la fenêtre et ajoute le gestionnaire d'événements clavier.
......@@ -258,7 +264,7 @@ public class GamePanel extends JPanel implements Runnable{
TextDisplay p2_bombl_t = new TextDisplay(text, 25, c, game.getnbX() * 60, 60 * 9, g);
p2_bombl_t.draw();
//Winner Display
//Winner Display + sound
if((game.getPlayerFromList(0) instanceof GhostPlayer) && (game.getPlayerFromList(1) instanceof GhostPlayer)){
text = "DRAW";
TextDisplay p1_winner_t = new TextDisplay(text, 100, c, 60 * 5, 60 * 6, g);
......@@ -266,18 +272,26 @@ public class GamePanel extends JPanel implements Runnable{
text = "YOU ALL DIED";
TextDisplay p1_winner_t_l2 = new TextDisplay(text, 100, c, 60 * 2, 60 * 8, g);
p1_winner_t_l2.draw();
s_p2win.stop();
s_p1win.stop();
s_draw.readSound();
}
else if (game.getPlayerFromList(0) instanceof GhostPlayer){
text = "PLAYER2 WIN";
c = Color.blue;
TextDisplay p1_winner_t = new TextDisplay(text, 125, c, 45, 60 * 7, g);
p1_winner_t.draw();
s_p2win.readSound();
}
else if (game.getPlayerFromList(1) instanceof GhostPlayer){
text = "PLAYER1 WIN";
c = Color.red;
TextDisplay p1_winner_t = new TextDisplay(text, 125, c, 45, 60 * 7, g);
p1_winner_t.draw();
s_p1win.readSound();
}
}
}
package App.Sound;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import java.io.File;
public class SoundFile {
private String path;
private boolean wasPlayed;
private boolean isPlaying;
private Clip clip;
public SoundFile(String path){
this.path = path;
this.wasPlayed = false;
this.isPlaying = false;
}
public void readSound() {
try {
if(!wasPlayed){
// Chargement du fichier audio
isPlaying = true;
File fichierAudio = new File(path);
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(fichierAudio);
// Lecture du fichier audio avec la classe Clip
clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
wasPlayed = true;
// Attente que le son se termine
new Thread() {
@Override
public void run() {
try {
Thread.sleep(clip.getMicrosecondLength() / 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
isPlaying = false;
}
}.start();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void reload(){
this.wasPlayed = false;
}
public void stop(){
if(isPlaying){
this.clip.stop();
}
isPlaying = false;
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter