サイズ: 689
コメント:
|
サイズ: 547
コメント:
|
削除された箇所はこのように表示されます。 | 追加された箇所はこのように表示されます。 |
行 4: | 行 4: |
void mazeru() | int spx, spy; }}} {{{ public void paintComponent(Graphics g) |
行 6: | 行 10: |
int i, j, x1, y1, x2, y2, w; ban = new int[nx][ny]; for(i = 0; i < nx; i++) // 元の位置 for(j = 0; j < ny; j++) ban[i][j] =i + j * nx; spx = nx-1; // 空白の位置 spy = ny-1; for(i = 0; i < (nx*ny*2); i++) // 偶数回置換 |
... g.setColor(Color.lightGray); g.fillRect(spx*haba, spy*haba, haba, haba); } }}} {{{ void shokika() { ... spx = yoko-1; spy = tate-1; for (cnt = 0; cnt < (tate*yoko*2); ) // 偶数回置換 |
行 16: | 行 24: |
do | x = (int)(Math.random() * yoko); y = (int)(Math.random() * tate); if(x != spx || y != spy) |
行 18: | 行 28: |
x1 = (int)(Math.random() * nx); y1 = (int)(Math.random() * ny); x2 = (int)(Math.random() * nx); y2 = (int)(Math.random() * ny); } while ( (x1 == x2 && y1 == y2) || (x1 == spx && y1 == spy) || (x2 == spx && y2 == spy) ); w = ban[x1][y1]; ban[x1][y1] = ban[x2][y2]; ban[x2][y2] = w; |
ban[spx][spy] = ban[x][y]; spx = x; spy = y; cnt++; } |
ばらばらにする
int spx, spy;
public void paintComponent(Graphics g) { ... g.setColor(Color.lightGray); g.fillRect(spx*haba, spy*haba, haba, haba); }
void shokika() { ... spx = yoko-1; spy = tate-1; for (cnt = 0; cnt < (tate*yoko*2); ) // 偶数回置換 { x = (int)(Math.random() * yoko); y = (int)(Math.random() * tate); if(x != spx || y != spy) { ban[spx][spy] = ban[x][y]; spx = x; spy = y; cnt++; } } }