✅ Ajout de la musique de fond (crédits : DorfRomantik)
This commit is contained in:
parent
f05622747d
commit
69661d2398
Binary file not shown.
@ -0,0 +1,39 @@
|
||||
package com.charpentierbalocchi.dorfjavatik.util;
|
||||
|
||||
import javax.sound.sampled.*;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
public class MusicPlayer {
|
||||
|
||||
private Clip clip;
|
||||
|
||||
public MusicPlayer(String musicPath) {
|
||||
try {
|
||||
// Charger le fichier audio
|
||||
URL url = getClass().getResource(musicPath);
|
||||
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(url);
|
||||
|
||||
// Obtenir un clip audio
|
||||
clip = AudioSystem.getClip();
|
||||
clip.open(audioInputStream);
|
||||
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Méthode pour démarrer la lecture
|
||||
public void play() {
|
||||
if (clip != null) {
|
||||
clip.start();
|
||||
clip.loop(Clip.LOOP_CONTINUOUSLY); // Boucler continuellement la musique
|
||||
}
|
||||
}
|
||||
|
||||
// Méthode pour arrêter la lecture
|
||||
public void stop() {
|
||||
if (clip != null && clip.isRunning()) {
|
||||
clip.stop();
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.charpentierbalocchi.dorfjavatik.view;
|
||||
|
||||
import com.charpentierbalocchi.dorfjavatik.controller.ControleurJeu;
|
||||
import com.charpentierbalocchi.dorfjavatik.model.Tuile;
|
||||
import com.charpentierbalocchi.dorfjavatik.util.MusicPlayer;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@ -18,6 +19,7 @@ public class FenetreJeu extends JFrame {
|
||||
private ControleurJeu controleurJeu; // Instance du contrôleur de jeu
|
||||
private JPanel panelPlateau; // Panneau pour le plateau de jeu
|
||||
private JPanel panelTuileCourante; // Panneau pour la tuile courante
|
||||
private MusicPlayer musicPlayer; // Instance du lecteur de musique
|
||||
|
||||
public FenetreJeu(int taillePlateau) {
|
||||
super("DorfJavaTik"); // Titre de la fenêtre
|
||||
@ -30,6 +32,9 @@ public class FenetreJeu extends JFrame {
|
||||
setSize(1300, 1000); // Fixe la taille de la fenêtre à 1300 x 1000
|
||||
setLocationRelativeTo(null); // Centre la fenêtre sur l'écran
|
||||
setVisible(true); // Rendre la fenêtre visible
|
||||
// Démarrer la musique de fond
|
||||
musicPlayer = new MusicPlayer("/com/charpentierbalocchi/dorfjavatik/resources/PleasantHill.wav");
|
||||
musicPlayer.play();
|
||||
}
|
||||
|
||||
private void initUI() {
|
||||
@ -167,6 +172,13 @@ public class FenetreJeu extends JFrame {
|
||||
labelScore.setText("Score: " + score);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
super.dispose();
|
||||
if (musicPlayer != null) {
|
||||
musicPlayer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
public Tuile getTuileCourante() {
|
||||
return tuileCourante;
|
||||
}
|
||||
|
@ -1,35 +0,0 @@
|
||||
package tests;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class Debut {
|
||||
public static void main(String[] args) {
|
||||
|
||||
JFrame fenetre = new JFrame();
|
||||
fenetre.setSize(500, 300);
|
||||
fenetre.setLocation(0, 0);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
JLabel etiquette = new JLabel();
|
||||
etiquette.setHorizontalAlignment(JLabel.RIGHT);
|
||||
etiquette.setVerticalAlignment(JLabel.BOTTOM);
|
||||
fenetre.add(etiquette, BorderLayout.CENTER);
|
||||
|
||||
JButton Nouveau = new JButton("Nouvelle Partie");
|
||||
etiquette.setHorizontalAlignment(JLabel.RIGHT);
|
||||
etiquette.setVerticalAlignment(JLabel.BOTTOM);
|
||||
fenetre.add(etiquette, BorderLayout.SOUTH);
|
||||
|
||||
fenetre.setVisible(true);
|
||||
|
||||
/*
|
||||
* public void actionPerformed(ActionEvent e){
|
||||
* String action=e.getActionCommand();
|
||||
* if(action.equals("Nouvelle Partie")){
|
||||
* // Do something
|
||||
* }
|
||||
*/
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user