diff --git a/Banniere.java b/Banniere.java index 5b7c955..4e40cf9 100644 --- a/Banniere.java +++ b/Banniere.java @@ -1,5 +1,6 @@ import javax.swing.*; import java.awt.*; +import java.awt.event.*; public class Banniere extends JPanel { // Définition du constructeur @@ -8,7 +9,7 @@ public class Banniere extends JPanel { // On défini un style à la bannière this.setBackground( new Color(0, 236, 96)); - + // TODO : Bouton sauver et quitter } @@ -17,6 +18,31 @@ public class Banniere extends JPanel { this.removeAll(); this.add(new MineLeft(minesLeft,this.getSize())); this.repaint(); - this.updateUI(); + } + + // Méthode pour indiquer au joueur sa Victoire + public void setVictoire(){ + this.add(new Fin("Victoire !",this.getSize())); + this.repaint(); + JButton menu = new JButton("Revenir au menu"); + menu.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) { + new FrameMenu(); + } + }); + this.add(menu); + } + + // Méthode pour indiquer au joueur sa Défaite + public void setDefaite(){ + this.add(new Fin("Défaite !",this.getSize())); + this.repaint(); + JButton menu = new JButton("Revenir au menu"); + menu.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) { + new FrameMenu(); + } + }); + this.add(menu); } } \ No newline at end of file diff --git a/Case.java b/Case.java index 42f8f9b..b9090da 100644 --- a/Case.java +++ b/Case.java @@ -125,4 +125,7 @@ public class Case extends JPanel { public boolean getEnJeu(){ return this.grille.getEnJeu(); } + + // TODO : Override toString() pour avoir 3 bits désignants l'état de la case + // } diff --git a/Fin.java b/Fin.java new file mode 100644 index 0000000..9769cf2 --- /dev/null +++ b/Fin.java @@ -0,0 +1,21 @@ +import javax.swing.JComponent; +import java.awt.*; + +public class Fin extends JComponent { + private String message; + private Dimension banniereSize; + public Fin(String message, Dimension banniereSize) { + super(); + this.message = message; + this.banniereSize=banniereSize; + } + @Override + protected void paintComponent(Graphics pinceau) { + this.setSize(banniereSize); + Graphics chiffre = pinceau.create(); + Font font = new Font("Arial", Font.BOLD, banniereSize.width/50); + chiffre.setFont(font); + chiffre.setColor(new Color(0, 22, 236)); + chiffre.drawString(message,banniereSize.width/100,banniereSize.height*2/3); + } +} diff --git a/Grille.java b/Grille.java index 570d675..1e32832 100644 --- a/Grille.java +++ b/Grille.java @@ -2,7 +2,7 @@ import javax.swing.*; import java.awt.*; import java.util.Random; -public class Grille extends JPanel { +public class Grille extends JPanel{ private Banniere banniere; private Dimension grilleSize=new Dimension(0,0); private Case[] plateau; @@ -12,6 +12,9 @@ public class Grille extends JPanel { private int minesLeft; private boolean enJeu; + // TODO : entourage dans une méthode + // TODO : Recréer un tableau avec les cases minees + // Définition du constructeur qui correspond à une grille de jeu public Grille(int lignes, int colonnes, int mines){ @@ -159,6 +162,7 @@ public class Grille extends JPanel { this.plateau[i].setVisible(); } System.out.println("Défaite !"); + this.banniere.setDefaite(); } // Méthode pour obtenir la taille de la grille de jeu @@ -188,10 +192,11 @@ public class Grille extends JPanel { } // Lance la victoire si toutes les cases non minées sont révélées if (taille-mines==casesVisibles){ - System.out.println("Victoire !"); for (int i=0;i