réparation Vide Grille + création et enregistrement de grille
This commit is contained in:
parent
5c20b80167
commit
5fee4722cf
@ -1,9 +1,4 @@
|
||||
public class Affichage {
|
||||
public static final int COULOIR=0;
|
||||
public static final int MUR=1;
|
||||
public static final int ENTREE=2;
|
||||
public static final int SORTIE=3;
|
||||
|
||||
public static final boolean LIBRE = true;
|
||||
public static final boolean OCCUPE = false;
|
||||
|
||||
@ -40,8 +35,8 @@ public class Affichage {
|
||||
this.caseEntrortie[1]=0;
|
||||
}
|
||||
this.caseEntrortie[0]=1;
|
||||
this.cetteCellules.setType(ENTREE);
|
||||
this.cetteCellules.peindre(ENTREE);
|
||||
this.cetteCellules.setType(Cellules.ENTREE);
|
||||
this.cetteCellules.peindre(Cellules.ENTREE);
|
||||
} else if(radio3Selected==true && this.caseEntrortie[1]==0){
|
||||
if(this.caseEntrortie[0]==1){
|
||||
this.caseEntrortie[0]=0;
|
||||
@ -49,24 +44,24 @@ public class Affichage {
|
||||
this.caseEntrortie[1]=0;
|
||||
}
|
||||
this.caseEntrortie[1]=1;
|
||||
this.cetteCellules.setType(SORTIE);
|
||||
this.cetteCellules.peindre(SORTIE);
|
||||
this.cetteCellules.setType(Cellules.SORTIE);
|
||||
this.cetteCellules.peindre(Cellules.SORTIE);
|
||||
} else if(radio1Selected==true && this.cetEtat==true){
|
||||
if(this.caseEntrortie[0]==1){
|
||||
this.caseEntrortie[0]=0;
|
||||
} else if(this.caseEntrortie[1]==1){
|
||||
this.caseEntrortie[1]=0;
|
||||
}
|
||||
this.cetteCellules.setType(COULOIR);
|
||||
this.cetteCellules.peindre(COULOIR);
|
||||
this.cetteCellules.setType(Cellules.COULOIR);
|
||||
this.cetteCellules.peindre(Cellules.COULOIR);
|
||||
} else if(radio1Selected==true && this.cetEtat==OCCUPE){
|
||||
if(this.caseEntrortie[0]==1){
|
||||
this.caseEntrortie[0]=0;
|
||||
} else if(this.caseEntrortie[1]==1){
|
||||
this.caseEntrortie[1]=0;
|
||||
}
|
||||
this.cetteCellules.setType(MUR);
|
||||
this.cetteCellules.peindre(MUR);
|
||||
this.cetteCellules.setType(Cellules.MUR);
|
||||
this.cetteCellules.peindre(Cellules.MUR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class Ecriture {
|
||||
fichierSortie = new FileOutputStream(this.filePath);
|
||||
|
||||
// Ecriture du tableau de bytes dans le fichier
|
||||
fichierSortie.write(tabBytes);
|
||||
fichierSortie.write(this.tabHeader);
|
||||
|
||||
// Ecriture du tableau d'octets binaires dans le fichier
|
||||
for (String flags : this.tabOffSet) {
|
||||
|
@ -2,11 +2,6 @@ import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class FenetreRndmGrille 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;
|
||||
|
||||
public static final int RANDOM=1;
|
||||
|
||||
private int taille;
|
||||
@ -66,28 +61,28 @@ public class FenetreRndmGrille extends Fenetre{
|
||||
|
||||
if(compteur == ValeurEntre)
|
||||
{
|
||||
Cellules cellules = new Cellules(i,j, ENTREE);
|
||||
Cellules cellules = new Cellules(i,j, Cellules.ENTREE);
|
||||
this.fenetre.add(cellules);
|
||||
cellules.addMouseListener(modif);
|
||||
grilleCellules[i][j] = cellules;
|
||||
}
|
||||
else if(compteur == ValeurSortie)
|
||||
{
|
||||
Cellules cellules = new Cellules(i, j, SORTIE);
|
||||
Cellules cellules = new Cellules(i, j, Cellules.SORTIE);
|
||||
this.fenetre.add(cellules);
|
||||
cellules.addMouseListener(modif);
|
||||
grilleCellules[i][j] = cellules;
|
||||
}
|
||||
else if(grille[i][j] == true)
|
||||
{
|
||||
Cellules cellules = new Cellules(i, j, COULOIR);
|
||||
Cellules cellules = new Cellules(i, j, Cellules.COULOIR);
|
||||
this.fenetre.add(cellules);
|
||||
cellules.addMouseListener(modif);
|
||||
grilleCellules[i][j] = cellules;
|
||||
}
|
||||
else
|
||||
{
|
||||
Cellules cellules = new Cellules(i, j, MUR);
|
||||
Cellules cellules = new Cellules(i, j, Cellules.MUR);
|
||||
this.fenetre.add(cellules);
|
||||
cellules.addMouseListener(modif);
|
||||
grilleCellules[i][j] = cellules;
|
||||
|
@ -1,22 +1,21 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class FenetreVideGrille 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 int taille;
|
||||
|
||||
private int[] tabCouleur;
|
||||
private boolean[][] grille;
|
||||
private Cellules[][] grilleCellules;
|
||||
private int[] tabCouleur;
|
||||
|
||||
private Modifications modif;
|
||||
|
||||
public FenetreVideGrille(int taille){
|
||||
super();
|
||||
this.taille = taille;
|
||||
this.grille = new boolean[this.taille][this.taille];
|
||||
this.grilleCellules = new Cellules[this.taille][this.taille];
|
||||
this.tabCouleur = new int[] {0, 0};
|
||||
}
|
||||
|
||||
public void videGrille(){
|
||||
@ -30,25 +29,22 @@ public class FenetreVideGrille extends Fenetre{
|
||||
PanneauModification interfacePanel = new PanneauModification(this.grille, this.taille, this.grilleCellules, this.fenetre);
|
||||
interfacePanel.SetUp();
|
||||
|
||||
/* =============================================================== */
|
||||
|
||||
|
||||
/* =============================================================== */
|
||||
|
||||
/* ======= Valeurs aléatoire pour l'entre et la sortie ========== */
|
||||
|
||||
for(int i=0; i<taille; i++){
|
||||
for(int j=0; j<taille; j++){
|
||||
Modifications modif = new Modifications(interfacePanel, this.grille, this.tabCouleur);
|
||||
|
||||
grille[i][j] = true;
|
||||
Cellules cellules = new Cellules(i, j, COULOIR);
|
||||
|
||||
this.modif = new Modifications(interfacePanel, grille,this.tabCouleur);
|
||||
|
||||
Cellules cellules = new Cellules(i,j, Cellules.COULOIR);
|
||||
this.fenetre.add(cellules);
|
||||
cellules.addMouseListener(modif);
|
||||
grilleCellules[i][j] = cellules;
|
||||
|
||||
this.tabCouleur = modif.getGateState();
|
||||
}
|
||||
}
|
||||
|
||||
this.fenetre.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,10 @@ import java.awt.event.MouseEvent;
|
||||
|
||||
public class ModificationsTab {
|
||||
// --------------------------------------------
|
||||
|
||||
public static final boolean LIBRE = true;
|
||||
public static final boolean OCCUPE = false;
|
||||
|
||||
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[][] cetteGrille;
|
||||
@ -36,9 +32,10 @@ public class ModificationsTab {
|
||||
this.tabEtat = unTab;
|
||||
|
||||
/* ========================================= */
|
||||
boolean radio1Selected = this.cePanel.GetButtonBW().isSelected(); // MUR / COULOIR
|
||||
|
||||
boolean radio2Selected = this.cePanel.GetButtonE().isSelected(); // ENTREE
|
||||
boolean radio3Selected = this.cePanel.GetButtonS().isSelected(); //SORTIE
|
||||
|
||||
/* ========================================= */
|
||||
|
||||
if(this.cetteGrille[this.cetteLigne][this.cetteColone] == LIBRE && radio2Selected==false && radio3Selected==false ){
|
||||
|
@ -1,16 +1,11 @@
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
|
||||
public class PreEcriture {
|
||||
private int cetteTaille;
|
||||
private String path;
|
||||
private int ceCompteur;
|
||||
private int octetRemaining;
|
||||
|
||||
private boolean[][] cetteGrille;
|
||||
@ -19,7 +14,6 @@ public class PreEcriture {
|
||||
private int[] resultat;
|
||||
private String[] tabTemp;
|
||||
private byte[] resultatByte;
|
||||
private byte[] resultatOffsetByte;
|
||||
|
||||
|
||||
public PreEcriture(boolean[][] uneGrille, Cellules[][] uneGrilleCell , int uneTaille){
|
||||
@ -46,11 +40,9 @@ public class PreEcriture {
|
||||
|
||||
if((this.cetteTaille*this.cetteTaille)%8 == 0){ //définit les tailles s'il y a besoin d'un octet en plus ou pas
|
||||
this.tabTemp = new String[(this.cetteTaille*this.cetteTaille)/8];
|
||||
this.ceCompteur = (this.cetteTaille*this.cetteTaille)/8;
|
||||
this.octetRemaining = this.cetteTaille*this.cetteTaille;
|
||||
} else if((this.cetteTaille*this.cetteTaille)%8 > 0){
|
||||
this.tabTemp = new String[(this.cetteTaille*this.cetteTaille)/8+1];
|
||||
this.ceCompteur = ((this.cetteTaille*this.cetteTaille)/8)+1;
|
||||
this.octetRemaining = (this.cetteTaille*this.cetteTaille)+(this.cetteTaille*this.cetteTaille)%8;
|
||||
}
|
||||
|
||||
@ -58,8 +50,6 @@ public class PreEcriture {
|
||||
boolean[] tabHorizontal = new boolean[this.cetteTaille*this.cetteTaille];
|
||||
tabHorizontal = outils.PutToVertical(this.cetteGrille, this.cetteTaille);
|
||||
|
||||
outils.printBool(tabHorizontal, this.cetteTaille);
|
||||
|
||||
// Transformation du tableau de boolean en un tableau de chaine de String qui stock des nombre sous formes de byte
|
||||
int compteur1=0;
|
||||
for(boolean cetteIteration : tabHorizontal){
|
||||
@ -86,13 +76,12 @@ public class PreEcriture {
|
||||
FileNameExtensionFilter filter = new FileNameExtensionFilter("Fichiers .lab", "lab");
|
||||
chooser.setFileFilter(filter);
|
||||
int returnVal = chooser.showSaveDialog(null);
|
||||
if(returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
String nomFichier = chooser.getSelectedFile().getName();
|
||||
if(!nomFichier.endsWith(".lab")) {
|
||||
nomFichier += ".lab";
|
||||
}
|
||||
String contenu = "Contenu du fichier .lab";
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File fichier = chooser.getSelectedFile();
|
||||
String nomFichier = fichier.getName();
|
||||
if (!nomFichier.endsWith(".lab")) {
|
||||
fichier = new File(fichier.getAbsolutePath() + ".lab");
|
||||
}
|
||||
return fichier.getAbsolutePath();
|
||||
}
|
||||
return null;
|
||||
|
118
SAVE.txt
118
SAVE.txt
@ -1,118 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
82
TEMP.txt
82
TEMP.txt
@ -1,82 +0,0 @@
|
||||
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Modifications implements MouseListener {
|
||||
// Def Constante
|
||||
public static final int COULOIR=0;
|
||||
public static final int MUR=1;
|
||||
public static final int ENTREE=2;
|
||||
public static final int SORTIE=3;
|
||||
|
||||
public static final boolean OCCUPE = false;
|
||||
public static final boolean LIBRE = true;
|
||||
|
||||
// Def variable
|
||||
|
||||
private boolean[][] grilleTab ;
|
||||
private int[] ceTab ;
|
||||
private PanneauModification options;
|
||||
|
||||
private int cetteLigne = 0;
|
||||
private int cetteColone = 0;
|
||||
private int ceType = 0;
|
||||
|
||||
private int grilleType;
|
||||
|
||||
private int cellulesBleu = 0;
|
||||
private int cellulesRouge = 0;
|
||||
|
||||
public Modifications(PanneauModification panneauModification, boolean[][] grilleTab, int[] unTab){
|
||||
this.options = panneauModification;
|
||||
this.grilleTab = grilleTab;
|
||||
this.ceTab = unTab;
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
Cellules notreCellule = (Cellules) e.getSource();
|
||||
|
||||
this.cetteLigne = notreCellule.getLigne();
|
||||
this.cetteColone = notreCellule.getColone();
|
||||
this.ceType = notreCellule.getType();
|
||||
|
||||
// Accéder aux boutons radios de l'objet Options
|
||||
boolean radio1Selected = options.GetButtonBW().isSelected(); // MUR / COULOIR
|
||||
boolean radio2Selected = options.GetButtonE().isSelected(); // ENTREE
|
||||
boolean radio3Selected = options.GetButtonS().isSelected(); //SORTIE
|
||||
|
||||
if(this.grilleTab[this.cetteLigne][this.cetteColone] == false && this.ceType==MUR && radio1Selected==true){
|
||||
this.grilleTab[this.cetteLigne][this.cetteColone] = LIBRE;
|
||||
notreCellule.setType(COULOIR);
|
||||
System.out.println("voici le type de la case : "+ notreCellule.getType());
|
||||
} else if(this.grilleTab[this.cetteLigne][this.cetteColone] == true && this.ceType==COULOIR && radio1Selected==true){
|
||||
this.grilleTab[this.cetteLigne][this.cetteColone] = OCCUPE;
|
||||
notreCellule.setType(MUR);
|
||||
} else if(radio2Selected==true && this.ceTab[0] == 0){
|
||||
this.grilleTab[this.cetteLigne][this.cetteColone] = LIBRE;
|
||||
notreCellule.setType(ENTREE);
|
||||
this.ceTab[0] = 1;
|
||||
} else if(radio3Selected==true && this.ceTab[1] == 0){
|
||||
this.grilleTab[this.cetteLigne][this.cetteColone] = LIBRE;
|
||||
notreCellule.setType(SORTIE);
|
||||
this.ceTab[0] = 1;
|
||||
} else if(this.ceTab[0] == 1 && this.ceType==ENTREE && radio1Selected==true){
|
||||
this.ceTab[0] = 0;
|
||||
} else if(this.ceTab[1] == 1 && this.ceType==SORTIE && radio1Selected==true){
|
||||
this.ceTab[1] = 0;
|
||||
}
|
||||
|
||||
|
||||
System.out.println("etat de la case maintenant : "+this.grilleTab[this.cetteLigne][this.cetteColone]);
|
||||
|
||||
}
|
||||
|
||||
public int[] getValues(){
|
||||
return this.ceTab;
|
||||
}
|
||||
|
||||
// Les méthodes suivantes ne sont pas utilisées dans cet exemple, donc nous les laissons vides
|
||||
public void mouseExited(MouseEvent e) {}
|
||||
public void mouseReleased(MouseEvent e) {}
|
||||
public void mousePressed(MouseEvent e) {}
|
||||
public void mouseEntered(MouseEvent e) {}
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
import javax.swing.plaf.metal.OceanTheme;
|
||||
|
||||
public class outils {
|
||||
public static final int COULOIR=0;
|
||||
public static final int MUR=1;
|
||||
|
Loading…
Reference in New Issue
Block a user