I'm actually coding a maze in Java. My data are represented by a 2-dimensional boolean array (true if there is a wall,false if there is nothing).
When I want to move to another position I'm making an if statement to check if the destination where I want to go is not a wall.
Here's the if statement :
if((this.infogrille[this.thesee.getProchaineLigne(Dir.HAUT.getX())][this.thesee.getProchaineLigne(Dir.HAUT.getY())])==false){
System.out.println(this.infogrille[this.thesee.getProchaineLigne(Dir.BAS.getX())][this.thesee.getProchaineLigne(Dir.BAS.getY())]);
this.thesee.movePosition(Dir.HAUT.getX(),Dir.HAUT.getY());
this.fenetre.repaint();
try{
Thread.sleep(700);
} catch(InterruptedException e){}
movcount++;
}
The System.out.println(this.infogrille[this.thesee.getProchaineLigne(Dir.BAS.getX())][this.thesee.getProchaineLigne(Dir.BAS.getY())]); sometimes print false and sometimes print true so it means that the if statement is not making is job.
Before that I've tried to write it like this if(!(this.infogrille.......)) but it doesn't work too.
Thanks.
Aucun commentaire:
Enregistrer un commentaire