/** * 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 These { public static final boolean LIBRE = false; public static final boolean OCCUPE = true; public static final boolean ARRIVE = true; public static final boolean CHEMIN = false; private int coordX; private int coordY; private int cetteTaille; private boolean[][] cetteGrille; public These(int x, int y, int taille, boolean[][] grille){ this.coordX = x; this.coordY = y; this.cetteGrille = grille; this.cetteTaille = taille; } public boolean goRight(){ if(coordY+1 < this.cetteTaille){ //System.out.println("etat case droite :"+this.cetteGrille[coordX][coordY+1]+" pose :"+(coordX+1)+" "+coordY); if(this.cetteGrille[coordX][coordY+1] == LIBRE){ this.coordY = this.coordY+1; return true; } } return false; } public boolean goDown(){ if(coordX+1 < this.cetteTaille){ if(this.cetteGrille[coordX+1][coordY] == LIBRE){ this.coordX = this.coordX+1; return true; } } return false; } public boolean goLeft(){ if(coordY-1 >= 0){ //System.out.println("etat case gauche :"+this.cetteGrille[coordX-1][coordY]+" pose :"+(coordX-1)+" "+coordY); if(this.cetteGrille[coordX][coordY-1] == LIBRE){ this.coordY = this.coordY-1; return true; } } return false; } public boolean goTop(){ if(coordX-1 >= 0){ //System.out.println("etat case top : "+this.cetteGrille[coordX][coordY-1] +" pose : "+coordX+" "+(coordY-1)); if(this.cetteGrille[coordX-1][coordY] == LIBRE){ this.coordX = this.coordX-1; return true; } } return false; } /* ======================== regarder ======================== */ public boolean debordementVerticaux(){ //renvoie true s'il y a débordement sinon false if(coordY < 0 && coordY > this.cetteTaille){ return true; } return LIBRE; } public boolean lookBot(){ if(coordY+1 < this.cetteTaille){ if(this.cetteGrille[coordX+1][coordY] == OCCUPE){ return OCCUPE; } } return LIBRE; } public boolean lookLeft(){ if(coordY+1 < this.cetteTaille){ if(this.cetteGrille[coordX][coordY-1] == OCCUPE){ return OCCUPE; } } return LIBRE; } public boolean lookTop(){ if(coordY+1 < this.cetteTaille){ if(this.cetteGrille[coordX-1][coordY] == OCCUPE){ return OCCUPE; } } return LIBRE; } // Gestion Fin public boolean isArrived(int finalX, int finalY){ // renvoie un boolean if(this.coordX == finalX && this.coordY == finalY){ return ARRIVE; } else { return CHEMIN; } } // Miscelaneous public void printPlacement(){ System.out.println("La position en X vaut : "+coordX+" et en y : "+coordY); } public int[] getCoord(){ int[] coordonnes = new int[2]; coordonnes[0] = coordX; coordonnes[1]=coordY; return coordonnes; } }