SAE21_2022/FenetreImpGrille.java

67 lines
2.7 KiB
Java

import java.awt.*;
public class FenetreImpGrille extends Fenetre {
public static final int COULOIR=0;
public static final int MUR=1;
public static final int ENTREE=2;
public static final int SORTIE=3;
private boolean[][] grille;
public FenetreImpGrille(){
super();
}
public void ImporterGrille(int taille, int Lentre, int Centre, int Lortie, int Cortie, int[] un_tab){
/* ================================================================ Déclaration des variables ============================================================================= */
int compteur=0;
int[][] ce_double_tab = new int[taille][taille];
this.grille = new boolean[taille][taille];
/* =============================================================== Gestion des paramètres de la fenètre ========================================================================== */
/*Création de la fenètre */
this.fenetre.setSize(600, 600);
/*Mise en place du grid layout */
GridLayout gestionnaire = new GridLayout(taille,taille);
this.fenetre.setLayout(gestionnaire);
/* ================================================================================================================================================================ */
/* remplissage du tab 1 */
for(int i=0; i<taille; i++){
for(int j=0; j<taille; j++){
ce_double_tab[j][i] = un_tab[compteur];
compteur++;
}
}
/* ======================================================================================================================================= */
// Gestion du remplissage des case
for(int i=0; i<taille; i++){
for(int j=0; j<taille; j++){
if(ce_double_tab[i][j] == 0){
this.grille[i][j] = false;
} else {
this.grille[i][j] = true;
}
if((i*taille+j)==(Lentre*taille+Centre)){
Cellules cellules = new Cellules(i, j, ENTREE);
this.fenetre.add(cellules);
} else if((i*taille+j)==(Lortie*taille+Cortie)){
Cellules cellules = new Cellules(i, j, SORTIE);
this.fenetre.add(cellules);
} else if(ce_double_tab[i][j] == 1){
Cellules cellules = new Cellules(i, j, MUR);
this.fenetre.add(cellules);
} else{
Cellules cellules = new Cellules(i, j, COULOIR);
this.fenetre.add(cellules);
}
}
}
this.fenetre.setVisible(true);
}
}