entourage presque opérationel

This commit is contained in:
Haïssous Kayyissa 2022-04-29 10:03:05 +02:00
parent d4f8e33c51
commit cbddb740c6
5 changed files with 43 additions and 16 deletions

View File

@ -3,16 +3,19 @@ import java.awt.*;
public class Case extends JComponent { public class Case extends JComponent {
private JPanel panel = new JPanel(); private JPanel panel = new JPanel();
private int entourage=0; private int entourage;
private boolean visible=false; private boolean visible;
private boolean minee=false; private boolean minee;
public Case(Dimension caseSize, boolean visible, boolean minee, int entourage) { public Case(Dimension caseSize, boolean visible, boolean minee, int entourage) {
super(); super();
this.panel.setSize(caseSize);
this.entourage=entourage; this.entourage=entourage;
this.visible=visible; this.visible=visible;
this.minee=minee; this.minee=minee;
this.panel.setSize(caseSize);
GridLayout unique = new GridLayout(1,1);
this.panel.setLayout(unique);
if (this.visible == false) { if (this.visible == false) {
Color gray2 = new Color(70, 70, 70); Color gray2 = new Color(70, 70, 70);
@ -25,16 +28,12 @@ public class Case extends JComponent {
this.panel.setBackground(rose); this.panel.setBackground(rose);
} else if (this.entourage>0){ } else if (this.entourage>0){
System.out.println(""+ this.entourage); System.out.println(""+ this.entourage);
this.panel.add(new Chiffre(entourage,caseSize));
} }
} }
} }
@Override
protected void paintComponent(Graphics pinceau) {
System.out.println("coucou");
}
public JPanel getCase() { public JPanel getCase() {
return this.panel; return this.panel;
} }

22
Chiffre.java Normal file
View File

@ -0,0 +1,22 @@
import javax.swing.JComponent;
import java.awt.*;
public class Chiffre extends JComponent {
private int entourage;
private Dimension caseSize;
public Chiffre(int entourage, Dimension caseSize) {
super();
this.entourage = entourage;
this.caseSize=caseSize;
}
@Override
protected void paintComponent(Graphics pinceau) {
Graphics chiffre = pinceau.create();
Font font = new Font("Arial", Font.BOLD, 40);
chiffre.setFont(font);
Color jaune = new Color(236, 214, 0);
chiffre.setColor(jaune);
chiffre.drawString(Integer.toString(this.entourage),caseSize.width/3,caseSize.height*8/10);
System.out.println(""+caseSize);
}
}

View File

@ -5,13 +5,15 @@ import java.awt.*;
// Création d'un Jcomponent Etoile, qui sert pour le marquage des mines // Création d'un Jcomponent Etoile, qui sert pour le marquage des mines
public class Etoile extends JComponent { public class Etoile extends JComponent {
private Image etoileImage; private Image etoileImage;
public Etoile() { private Dimension caseSize;
public Etoile(Dimension caseSize) {
super(); super();
this.caseSize=caseSize;
this.etoileImage = Toolkit.getDefaultToolkit().getImage("etoile.png"); this.etoileImage = Toolkit.getDefaultToolkit().getImage("etoile.png");
} }
@Override @Override
protected void paintComponent(Graphics pinceau) { protected void paintComponent(Graphics pinceau) {
Graphics etoile = pinceau.create(); Graphics etoile = pinceau.create();
etoile.drawImage(this.etoileImage,5,10,90,80,this); etoile.drawImage(this.etoileImage,this.caseSize.width*1/20,this.caseSize.height*1/10,this.caseSize.width*9/10,this.caseSize.height*8/10,this);
} }
} }

View File

@ -6,7 +6,7 @@ public class Grille extends JComponent {
private Dimension grilleSize=new Dimension(0,0); private Dimension grilleSize=new Dimension(0,0);
private JPanel grille= new JPanel(); private JPanel grille= new JPanel();
// On créer La grille de jeu // On crée La grille de jeu
public Grille(int lignes, int colonnes, int mines){ public Grille(int lignes, int colonnes, int mines){
// Découpage de l'espace en fonction des paramètres pour la mise en place de la grille // Découpage de l'espace en fonction des paramètres pour la mise en place de la grille
@ -90,8 +90,12 @@ public class Grille extends JComponent {
} }
} }
// Affichage des cases AffichePlateau(lignes*colonnes, caseSize, entourage, visible, minee);
for (int i=0;i<lignes*colonnes;i++){ }
// Méthode pour afficher l'état des cases
protected void AffichePlateau(int taille, Dimension caseSize, int[] entourage, boolean[] visible, boolean[] minee){
for (int i=0;i<taille;i++){
Case panel = new Case(caseSize,visible[i],minee[i],entourage[i]); Case panel = new Case(caseSize,visible[i],minee[i],entourage[i]);
this.grille.add(panel.getCase()); this.grille.add(panel.getCase());
} }

View File

@ -1,6 +1,6 @@
public class Test { public class Test {
public static void main(String[] args) { public static void main(String[] args) {
Grille grille=new Grille(20,25,50); Grille grille=new Grille(4,8,10);
new FrameJeu(grille, 15); new FrameJeu(grille, 15);
} }
} }