Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Labyrinthe
- {
- private int[][] aLab;
- public Labyrinthe()
- {
- this.aLab = new int[][] { { 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 },
- { 1 , 1 , 0 , 0 , 0 , 0 , 1 , 1 , 0 , 1 },
- { 1 , 1 , 0 , 1 , 0 , 1 , 1 , 0 , 0 , 1 },
- { 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 1 , 1 },
- { 1 , 0 , 1 , 0 , 0 , 1 , 1 , 0 , 0 , 1 },
- { 1 , 0 , 1 , 1 , 0 , 1 , 1 , 1 , 0 , 1 },
- { 1 , 0 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 },
- { 1 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 },
- { 1 , 0 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 1 },
- { 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 } };
- }
- public void afficher()
- {
- for(int[] ligne: this.aLab)
- {
- for(int chr: ligne)
- {
- switch(chr)
- {
- case 0:
- System.out.print(" ");
- break;
- case 1:
- System.out.print("*");
- break;
- case 2:
- System.out.print(".");
- break;
- default:
- }
- }
- System.out.println("");
- }
- }
- public Point getSortie()
- {
- for(int x=0; x<this.aLab.length; x++)
- {
- if(this.aLab[0][x] == 0)
- {
- return new Point(x, 0);
- }
- if(this.aLab[this.aLab.length - 1][x] == 0)
- {
- return new Point(x, aLab.length - 1);
- }
- if(this.aLab[x][0] == 0)
- {
- return new Point(0, x);
- }
- if(this.aLab[x][this.aLab.length - 1] == 0)
- {
- return new Point(this.aLab.length - 1, x);
- }
- }
- return new Point(-1, -1);
- }
- public int getValue(Point p)
- {
- return this.getValue(p.getX(), p.getY());
- }
- public int getValue(int x, int y)
- {
- if(x < 0 || x >= this.aLab.length || y < 0 || y >= this.aLab.length)
- {
- return 1;
- }
- return this.aLab[y][x];
- }
- public void setValue(int x, int y, int val)
- {
- this.aLab[y][x] = val;
- }
- public void setValue(Point p, int val)
- {
- this.setValue(p.getX(), p.getY(), val);
- }
- public boolean existeChemin(Point p)
- {
- return this.existeChemin(p.getX(), p.getY());
- }
- public boolean existeChemin(int iX, int iY)
- {
- if(this.getValue(iX, iY) != 0)
- {
- return false;
- }
- else if(this.getSortie().getX() == iX && this.getSortie().getY() == iY)
- return true;
- else
- {
- this.setValue(iX, iY, 2);
- if(existeChemin(iX + 1, iY))
- return true;
- if(existeChemin(iX - 1, iY))
- return true;
- if(existeChemin(iX, iY + 1))
- return true;
- if(existeChemin(iX, iY - 1))
- return true;
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement