JAVA - How to create my exit's maze? [closed]

2019-06-14 16:32发布

问题:

*I'm trying to open my RANDOM exit's maze in the right side from my maze there: Exit Maze and here is my code:

private int hauteur;
private int largeur;
private static final int LMURET = 8;
private static final int HMURET = 4;
private char[][] dessinLaby;

public Labyrinthe(int h, int w) //en nbre de cases
{
    this.hauteur = h;
    this.largeur = w;
    this.dessinLaby = new char[this.hauteur*HMURET+1][this.largeur*LMURET+1];       
}
public void dessineOuverture(int j)
    {
        for(int x=(j*LMURET+1)-1; x<j*LMURET+1; x++)
        {
            int a = (int) ( Math.random()*((hauteur*HMURET+1)-2) );

            if( (a%4) != 0)
            {
                for(int b=0; b<2; b++)
                {
                        System.out.println(this.dessinLaby[a][(j*LMURET+1)-1] = ' '); // dans le cas ou ca tombe sur 1
                }
            }
        }
    }

But nothing happening, can you help me please ?*

回答1:

This is from your other question but if you use this youll get an exit

int a = (int) ( Math.random()*((hauteur*HMURET+1)-2) );
for(int i=0; i<(this.hauteur*HMURET+1); i++)
{
System.out.print("|");
for(int j=0; j<(this.largeur*LMURET+1)-2; j++)
{
    System.out.print(" ");
}
  if(i<a){
     System.out.println("");
  }else{
    System.out.println(this.dessinLaby[i][0] = '|');
  }
}


标签: java maze