import javax.swing.JOptionPane; /** * La class Attente inclu un KeyListener, cette classe a pour objectif d'attendre une entré sur la touche espace du clavier * pour regarder le parcours qu'emprunte l'algorithme * @version 1.1 * @author Matthis Fauvet */ public class ParcoursManuel { private int taille; private int ceCompteur = 0; private Cellules[][] labyrinthe; public ParcoursManuel(Cellules[][] tableau, int X, int Y, int len){ this.taille = len; this.labyrinthe = tableau; this.Parcourir(X, Y); } public boolean Parcourir(int coordX, int coordY){ boolean done = false; if(estValide(coordX, coordY)) { if (this.labyrinthe[coordX][coordY].getType() == Cellules.SORTIE){ JOptionPane.showMessageDialog(null, "Nous avons trouvé un chemin en "+this.ceCompteur+" coups pour ce labyrinthe", "Information", JOptionPane.INFORMATION_MESSAGE); return true; } else { this.labyrinthe[coordX][coordY].setType(Cellules.MUR); //Appels récursifs if(done != true){ done = Parcourir(coordX + 1, coordY); done = Parcourir(coordX, coordY + 1); done = Parcourir(coordX - 1, coordY); done = Parcourir(coordX, coordY - 1); } } } return done; } private boolean estValide(int pos_x, int pos_y) { this.ceCompteur++; boolean result = false; //Si la case passée en paramètre est dans les dimensions du labyrinthe if (pos_x >= 0 && pos_x < this.taille && pos_y >= 0 && pos_y < this.taille){ //Et si la case est un espace vide if (this.labyrinthe[pos_x][pos_y].getType() != Cellules.SORTIE && this.labyrinthe[pos_x][pos_y].getType() != Cellules.MUR && this.labyrinthe[pos_x][pos_y].getType() != Cellules.ENTREE){ this.labyrinthe[pos_x][pos_y].peindre(Cellules.VUE); } if (this.labyrinthe[pos_x][pos_y].getType() == Cellules.COULOIR || this.labyrinthe[pos_x][pos_y].getType() == Cellules.ENTREE || this.labyrinthe[pos_x][pos_y].getType() == Cellules.SORTIE){ result = true; } if (this.labyrinthe[pos_x][pos_y].getType() != Cellules.SORTIE && this.labyrinthe[pos_x][pos_y].getType() != Cellules.MUR && this.labyrinthe[pos_x][pos_y].getType() != Cellules.ENTREE){ this.labyrinthe[pos_x][pos_y].peindre(Cellules.DESSUS); } } return result; } //Fin estValide() }