119 lines
4.0 KiB
Plaintext
119 lines
4.0 KiB
Plaintext
|
import javax.swing.*;
|
||
|
import java.awt.*;
|
||
|
import java.util.Random;
|
||
|
import javax.swing.border.Border;
|
||
|
|
||
|
public class FenetreRndmGrille extends Fenetre{
|
||
|
private int[] tab_de_int;
|
||
|
private int taille;
|
||
|
private int ValeurEntre;
|
||
|
private int ValeurSortie;
|
||
|
|
||
|
private int[][] grille;
|
||
|
|
||
|
public FenetreRndmGrille(int taille){
|
||
|
super();
|
||
|
this.tab_de_int = new int[] {1, 1};
|
||
|
this.taille = taille;
|
||
|
this.grille = new int[this.taille][this.taille];
|
||
|
}
|
||
|
|
||
|
public void randomGrille(){
|
||
|
this.fenetre.setSize(600, 600);
|
||
|
this.fenetre.setLocation(450, 200);
|
||
|
|
||
|
GridLayout gestionnaire = new GridLayout(this.taille,this.taille);
|
||
|
this.fenetre.setLayout(gestionnaire);
|
||
|
|
||
|
OptionsFRG un_Test = new OptionsFRG(this);
|
||
|
un_Test.SetUp();
|
||
|
|
||
|
/* ======= Valeurs aléatoire pour l'entre et la sortie ========== */
|
||
|
|
||
|
Random rand = new Random();
|
||
|
this.ValeurEntre = rand.nextInt(this.taille*this.taille);
|
||
|
this.ValeurSortie = rand.nextInt(this.taille*this.taille);
|
||
|
if(this.ValeurSortie == this.ValeurEntre){
|
||
|
while(this.ValeurSortie == this.ValeurEntre){
|
||
|
this.ValeurSortie = rand.nextInt(this.taille*this.taille);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* =============================================================== */
|
||
|
|
||
|
int compteur=0;
|
||
|
|
||
|
for(int i=0; i<taille; i++){
|
||
|
for(int j=0; j<taille; j++){
|
||
|
int nombreAleatoire = rand.nextInt(3); // génère un nombre entre 0 et 10
|
||
|
|
||
|
Cellules cellules = new Cellules(i, j);
|
||
|
|
||
|
if(compteur==this.ValeurEntre){
|
||
|
Border border = BorderFactory.createLineBorder(Color.BLACK, 1);
|
||
|
ce_panel.setBorder(border);
|
||
|
ce_panel.setBackground(Color.BLUE);
|
||
|
this.fenetre.add(ce_panel);
|
||
|
|
||
|
ModificationsFRG testee = new ModificationsFRG(un_Test, this.tab_de_int);
|
||
|
ce_panel.addMouseListener(testee);
|
||
|
|
||
|
this.tab_de_int=testee.getValues();
|
||
|
|
||
|
} else if(compteur==this.ValeurSortie){
|
||
|
Border border = BorderFactory.createLineBorder(Color.BLACK, 1);
|
||
|
ce_panel.setBorder(border);
|
||
|
ce_panel.setBackground(Color.RED);
|
||
|
this.fenetre.add(ce_panel);
|
||
|
|
||
|
ModificationsFRG testee = new ModificationsFRG(un_Test, this.tab_de_int);
|
||
|
ce_panel.addMouseListener(testee);
|
||
|
|
||
|
this.tab_de_int=testee.getValues();
|
||
|
|
||
|
} else if(nombreAleatoire == 0){
|
||
|
Border border = BorderFactory.createLineBorder(Color.BLACK, 1);
|
||
|
ce_panel.setBorder(border);
|
||
|
ce_panel.setBackground(Color.BLACK);
|
||
|
this.fenetre.add(ce_panel);
|
||
|
|
||
|
ModificationsFRG testee = new ModificationsFRG(un_Test, this.tab_de_int);
|
||
|
ce_panel.addMouseListener(testee);
|
||
|
|
||
|
this.tab_de_int=testee.getValues();
|
||
|
|
||
|
} else{
|
||
|
Border border = BorderFactory.createLineBorder(Color.BLACK, 1);
|
||
|
ce_panel.setBorder(border);
|
||
|
ce_panel.setBackground(Color.WHITE);
|
||
|
this.fenetre.add(ce_panel);
|
||
|
|
||
|
ModificationsFRG testee = new ModificationsFRG(un_Test, this.tab_de_int);
|
||
|
ce_panel.addMouseListener(testee);
|
||
|
|
||
|
this.tab_de_int=testee.getValues();
|
||
|
}
|
||
|
|
||
|
compteur++;
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
this.fenetre.setVisible(true);
|
||
|
}
|
||
|
|
||
|
public int[] get_info(){
|
||
|
int[] infos_grille = new int[5];
|
||
|
infos_grille[0] = this.taille;
|
||
|
infos_grille[1] = (this.ValeurEntre/this.taille);
|
||
|
infos_grille[2] = (this.ValeurEntre%this.taille);
|
||
|
infos_grille[3] = (this.ValeurSortie/this.taille);
|
||
|
infos_grille[4] = (this.ValeurSortie%this.taille);
|
||
|
return infos_grille;
|
||
|
}
|
||
|
|
||
|
public JPanel[][] getGrille(){
|
||
|
return this.TabDePanel;
|
||
|
}
|
||
|
}
|