JAVA-如何创建出口迷宫? [英] JAVA - How to create my exit's maze?

查看:114
本文介绍了JAVA-如何创建出口迷宫?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

*我正在尝试从我的迷宫右侧打开我的RANDOM出口的迷宫: 退出迷宫 这是我的代码:

*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 ?*

推荐答案

这是您另一个问题的答案,但是如果您使用此方法,则会退出出口

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-如何创建出口迷宫?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆