手続き型生成マップをシードする作業をしていますが、実行すると別の色の四角形のマップを表示するはずです。方法は私が助けを必要とする地図上のいくつかのランダムな場所を選択し、ランダムなタイプを出発点として割り当てます。ここ Javaのループで問題が発生しました
は、私は、コードをテストし、私はこのブロックを削除したら、それがうまく働いたpublic void seed(){//seeds the map
double seedNum = (mapWidth*mapHeight*.02);//determine number of seed positions needed
if((int)seedNum < 1){//will always seed at least 1 square
seedNum = 1;
}
int seedListX[]= new int[(int)seedNum];//list of seeded coordinates to check for dupilcates
int seedListY[]= new int[(int)seedNum];
int seedX = (int)Math.random()*mapWidth;
int seedY = (int)Math.random()*mapHeight;
seedListX[0] = seedX;
seedListY[0] = seedY;
for(int i =1; i < (int)seedNum; i++){
int error = 0;
seedX = (int)Math.random()*mapWidth;
seedY = (int)Math.random()*mapHeight;
seedListX[i] = seedX;
seedListY[i] = seedY;
for(int j = 0; j < seedNum;j++){//goes through seed coordinates list to check for duplicates
if(seedX == seedListX[j] || seedY == seedListY[j]){
error = 1;
}
}
int type = (int)Math.random()*5+1;//choose random type
if(error != 1){
this.setType(seedX,seedY,type);
}else{
i--;
}//end inner loop
}
}//end outer loop
全体の方法です
for(int j = 0; j < seedNum;j++){//goes through seed coordinates list to check for duplicates
if(seedX == seedListX[j] || seedY == seedListY[j]){
error = 1;
}
}
int type = (int)Math.random()*5+1;//this line is fine
if(error != 1){
this.setType(seedX,seedY,type);
}else{
i--;
}//end inner loop
イムその無限ループが、私はそれを見ていないです、必ずいずれかの助けを感謝します。
CHループ – qaispak
の閉じ括弧も忘れないでください。小さなコードブロックを使わずに実行すると、常に最初の正方形がタイプ1になります。 –