2022-05-21 17:53:19 +02:00
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
|
|
|
|
|
|
|
public class Banniere extends JPanel {
|
2022-05-21 22:17:25 +02:00
|
|
|
private FrameJeu fenetre;
|
2022-05-23 19:32:09 +02:00
|
|
|
private FrameMenu menu;
|
2022-05-24 22:32:34 +02:00
|
|
|
private JButton save;
|
2022-05-24 23:41:34 +02:00
|
|
|
private JLabel mines;
|
2022-05-21 17:53:19 +02:00
|
|
|
// Définition du constructeur
|
2022-05-24 22:32:34 +02:00
|
|
|
public Banniere(int mines, FrameJeu fenetre, FrameMenu menu, Grille grille) {
|
2022-05-21 17:53:19 +02:00
|
|
|
super();
|
2022-05-21 22:17:25 +02:00
|
|
|
this.fenetre=fenetre;
|
2022-05-23 19:32:09 +02:00
|
|
|
this.menu=menu;
|
2022-05-24 22:32:34 +02:00
|
|
|
this.setSize(grille.getWidth(),grille.getHeight()/8);
|
2022-05-21 17:53:19 +02:00
|
|
|
|
|
|
|
// On défini un style à la bannière
|
2022-05-23 23:02:19 +02:00
|
|
|
this.setBackground(new Color(0, 236, 96));
|
2022-05-24 22:32:34 +02:00
|
|
|
this.setLayout(new BorderLayout());
|
2022-05-21 18:41:24 +02:00
|
|
|
|
2022-05-24 23:41:34 +02:00
|
|
|
// Compteur de mines restantes
|
|
|
|
|
|
|
|
this.mines= new JLabel();
|
|
|
|
this.add(this.mines, BorderLayout.NORTH);
|
|
|
|
|
2022-05-24 21:46:09 +02:00
|
|
|
// Bouton pour sauver et quitter
|
2022-05-24 22:32:34 +02:00
|
|
|
this.save = new JButton("Sauver et quitter");
|
2022-05-24 22:57:12 +02:00
|
|
|
save.addActionListener(new SaveListener(grille, fenetre));
|
2022-05-24 22:32:34 +02:00
|
|
|
this.add(this.save, BorderLayout.EAST);
|
2022-05-21 17:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Méthode pour afficher le nombre de mines restantes
|
2022-05-24 16:15:21 +02:00
|
|
|
public void setMinesLeft(int minesLeft) {
|
2022-05-24 23:41:34 +02:00
|
|
|
this.mines.setText("Mines restantes : "+Integer.toString(minesLeft));
|
2022-05-21 17:53:19 +02:00
|
|
|
this.repaint();
|
2022-05-21 18:41:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Méthode pour indiquer au joueur sa Victoire
|
2022-05-24 16:15:21 +02:00
|
|
|
public void setVictoire() {
|
2022-05-24 22:32:34 +02:00
|
|
|
remove(this.save);
|
2022-05-24 16:15:21 +02:00
|
|
|
JLabel victoire = new JLabel("Victoire ! Retour au menu...");
|
|
|
|
victoire.setForeground(new Color(0, 22, 236));
|
2022-05-24 21:46:09 +02:00
|
|
|
victoire.setFont(new Font("Arial", Font.PLAIN, 30));
|
2022-05-24 22:32:34 +02:00
|
|
|
this.add(victoire, BorderLayout.CENTER);
|
2022-05-24 21:46:09 +02:00
|
|
|
Timer timerMenu = new Timer(7000, new MenuListener(this.fenetre, this.menu));
|
2022-05-23 16:10:45 +02:00
|
|
|
timerMenu.setRepeats(false);
|
|
|
|
timerMenu.start();
|
2022-05-21 18:41:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Méthode pour indiquer au joueur sa Défaite
|
2022-05-24 16:15:21 +02:00
|
|
|
public void setDefaite() {
|
2022-05-24 22:32:34 +02:00
|
|
|
remove(this.save);
|
2022-05-24 16:15:21 +02:00
|
|
|
JLabel defaite = new JLabel("Défaite ! Retour au menu...");
|
|
|
|
defaite.setForeground(new Color(0, 22, 236));
|
2022-05-24 21:46:09 +02:00
|
|
|
defaite.setFont(new Font("Arial", Font.PLAIN, 30));
|
2022-05-24 22:32:34 +02:00
|
|
|
this.add(defaite, BorderLayout.CENTER);
|
2022-05-24 21:46:09 +02:00
|
|
|
Timer timerMenu = new Timer(7000, new MenuListener(this.fenetre, this.menu));
|
2022-05-23 16:10:45 +02:00
|
|
|
timerMenu.setRepeats(false);
|
|
|
|
timerMenu.start();
|
2022-05-21 17:53:19 +02:00
|
|
|
}
|
|
|
|
}
|