SAE21_2021/Banniere.java

55 lines
1.8 KiB
Java
Raw Normal View History

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;
private JButton save;
2022-05-21 17:53:19 +02:00
// Définition du constructeur
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;
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));
this.setLayout(new BorderLayout());
2022-05-21 18:41:24 +02:00
2022-05-24 21:46:09 +02:00
// Bouton pour sauver et quitter
this.save = new JButton("Sauver et quitter");
2022-05-24 22:57:12 +02:00
save.addActionListener(new SaveListener(grille, fenetre));
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 21:46:09 +02:00
JLabel mines = new JLabel("Mines restantes : "+Integer.toString(minesLeft));
this.add(mines, BorderLayout.NORTH);
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() {
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));
this.add(victoire, BorderLayout.CENTER);
2022-05-24 21:46:09 +02:00
Timer timerMenu = new Timer(7000, new MenuListener(this.fenetre, this.menu));
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() {
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));
this.add(defaite, BorderLayout.CENTER);
2022-05-24 21:46:09 +02:00
Timer timerMenu = new Timer(7000, new MenuListener(this.fenetre, this.menu));
timerMenu.setRepeats(false);
timerMenu.start();
2022-05-21 17:53:19 +02:00
}
}