diff --git a/Case.java b/Case.java index 873c043..3823f6d 100644 --- a/Case.java +++ b/Case.java @@ -2,42 +2,54 @@ import javax.swing.*; import java.awt.*; public class Case extends JPanel { - private JPanel panel = new JPanel(); + private Dimension caseSize; private int entourage; private boolean visible; private boolean minee; private Listener listener; - public Case(Dimension caseSize, boolean visible, boolean minee, int entourage) { + public Case(Dimension caseSize, boolean minee, int entourage) { super(); this.entourage=entourage; - this.visible=visible; + this.visible=false; this.minee=minee; - this.panel.setSize(caseSize); + this.caseSize= caseSize; + + this.setSize(caseSize); + this.listener = new Listener(); - panel.addMouseListener(listener); - + this.addMouseListener(this.listener); + GridLayout unique = new GridLayout(1,1); - this.panel.setLayout(unique); + this.setLayout(unique); + } + public void setVisible(){ + this.visible=true; + this.updateUI(); + } + + public boolean getVisible(){ + return this.visible; + } + + public Case getCase(){ if (this.visible == false) { - Color gray2 = new Color(70, 70, 70); - this.panel.setBackground(gray2); + this.setBackground(new Color(70, 70, 70)); } else if (this.visible == true) { - Color gray1 = new Color(80, 80, 80); - this.panel.setBackground(gray1); if (this.minee == true) { - Color rose = new Color(236, 0, 140); - this.panel.setBackground(rose); - } else if (this.entourage>0){ - this.panel.add(new Chiffre(entourage,caseSize)); + this.setBackground(new Color(236, 0, 140)); + } else { + this.setBackground(new Color(80, 80, 80)); + if (this.entourage>0){ + this.add(new Chiffre(entourage,caseSize)); + } } } - + return this; } - public JPanel getCase() { - return this.panel; + public boolean getMine(){ + return this.minee; } - } diff --git a/FrameJeu.java b/FrameJeu.java index 59f9eb1..48f2d36 100644 --- a/FrameJeu.java +++ b/FrameJeu.java @@ -42,7 +42,7 @@ public class FrameJeu{ miseEnPage.weightx =1; miseEnPage.weighty = 0.85; miseEnPage.fill = GridBagConstraints.BOTH; - fenetre.add(grille.getGrille(), miseEnPage); + fenetre.add(grille, miseEnPage); // Mise en place de la fenêtre et affichage fenetre.pack(); diff --git a/Grille.java b/Grille.java index 67f22c1..547be4b 100644 --- a/Grille.java +++ b/Grille.java @@ -4,7 +4,7 @@ import java.util.Random; public class Grille extends JPanel { private Dimension grilleSize=new Dimension(0,0); - private JPanel grille= new JPanel(); + private Case[] plateau; // On crée La grille de jeu public Grille(int lignes, int colonnes, int mines){ @@ -16,8 +16,9 @@ public class Grille extends JPanel { GridLayout damier = new GridLayout(lignes,colonnes); System.out.println("Taille des cases : "+caseSize); System.out.println("Taille de la Grille : "+grilleSize); - this.grille.setLayout(damier); - this.grille.setSize(grilleSize); + this.setLayout(damier); + this.setSize(grilleSize); + this.plateau= new Case[lignes*colonnes]; // Initialisation : les cases sont cachées @@ -42,6 +43,7 @@ public class Grille extends JPanel { } } } + // On place maintenant les mines sur la plateau boolean[] minee = new boolean[lignes*colonnes]; for (int i=0; i