SAE21_2022/These.java

87 lines
2.4 KiB
Java

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;
}
// 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;
}
}