public boolean newMap(int dificulty){
boolean out = true;
for( int y = 0; y < 100; y ++){
for( int x = 0; x < 100; x ++){
map[x][y] = 0;
if ( x%2 == 0 && y%2 == 0 ) map[x][y] = 1;
if ( x == 0 || y == 0 || x == 99 || y == 99 ) map[x][y] = 1;
if ( x%2 == 1 && y%2 == 0 ) if ( (int)(Math.random()*101) <= dificulty ) map[x][y] = 1;
if ( x%2 == 0 && y%2 == 1 ) if ( (int)(Math.random()*101) <= dificulty ) map[x][y] = 1;
}
}
int true_map[][] = new int[100][100];
for( int y = 0; y < 100; y ++){
for( int x = 0; x < 100; x ++){
true_map[x][y] = 0;
}
}
true_map[98][98] = 100000;
for( int ok = 0; ok == 0; ok = ok){
int temp = 0;
for( int y = 0; y < 100; y ++){
for( int x = 0; x < 100; x ++){
if ( true_map[x][y] > 0){
if ( x+1 < 100 ) if ( map[x+1][y] == 0 && true_map[x+1][y] == 0 ){
true_map[x+1][y] = true_map[x][y]-1;
temp ++;
}
if ( x-1 >= 0 ) if ( map[x-1][y] == 0 && true_map[x-1][y] == 0 ){
true_map[x-1][y] = true_map[x][y]-1;
temp ++;
}
if ( y+1 < 100 ) if ( map[x][y+1] == 0 && true_map[x][y+1] == 0 ){
true_map[x][y+1] = true_map[x][y]-1;
temp ++;
}
if ( y-1 >= 0 ) if ( map[x][y-1] == 0 && true_map[x][y-1] == 0 ){
true_map[x][y-1] = true_map[x][y]-1;
temp ++;
}
}
}
}
System.out.println( temp);
if ( temp == 0 ) ok = 1;
}
for( int y = 0; y < 100; y ++){
for( int x = 0; x < 100; x ++){
if ( true_map[x][y] == 0 ){
map[x][y] = 1;
}
}
}
int box_max = (int)(Math.random()*45)+5;
for( int i = 0 ; i < box_max; i ++ ){
int rx = (int)(Math.random()*49);
int ry = (int)(Math.random()*49);
if ( map[1+rx*2][1+ry*2] == 0 ) map[1+rx*2][1+ry*2] = 2;
}
System.out.println(true_map[1][1]);
if ( true_map[1][1] > 0 ) out = true;
if ( true_map[1][1] == 0 ) out = false;
zx = 1;
zy = 1;
map_x = 0;
map_y = 0;
return out;
}
ちなみに int difficultyは迷路の濃さを示しています。大体48~52くらいがいいと思います。
ちなみに濃すぎると、なかなか生成完了しません。(爆