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 {
private JPanel panel = new JPanel();
private int entourage=0;
private boolean visible=false;
private boolean minee=false;
private int entourage;
private boolean visible;
private boolean minee;
public Case(Dimension caseSize, boolean visible, boolean minee, int entourage) {
super();
this.panel.setSize(caseSize);
this.entourage=entourage;
this.visible=visible;
this.minee=minee;
this.panel.setSize(caseSize);
GridLayout unique = new GridLayout(1,1);
this.panel.setLayout(unique);
if (this.visible == false) {
Color gray2 = new Color(70, 70, 70);
@ -25,16 +28,12 @@ public class Case extends JComponent {
this.panel.setBackground(rose);
} else if (this.entourage>0){
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() {
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
public class Etoile extends JComponent {
private Image etoileImage;
public Etoile() {
private Dimension caseSize;
public Etoile(Dimension caseSize) {
super();
this.caseSize=caseSize;
this.etoileImage = Toolkit.getDefaultToolkit().getImage("etoile.png");
}
@Override
protected void paintComponent(Graphics pinceau) {
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 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){
// Découpage de l'espace en fonction des paramètres pour la mise en place de la grille
@ -90,12 +90,16 @@ public class Grille extends JComponent {
}
}
// Affichage des cases
for (int i=0;i<lignes*colonnes;i++){
AffichePlateau(lignes*colonnes, caseSize, entourage, visible, minee);
}
// 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]);
this.grille.add(panel.getCase());
}
}
}
// Méthode pour obtenir la taille de la grille de jeu
public Dimension getGrilleSize() {

View File

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