サイズ: 689
コメント:
|
サイズ: 712
コメント:
|
削除された箇所はこのように表示されます。 | 追加された箇所はこのように表示されます。 |
行 3: | 行 3: |
ピースを1つ取り除いてできた空白部分を使って 移動するための処理を記述します。 |
|
行 4: | 行 7: |
void mazeru() | int spx, spy; }}} {{{ public void paintComponent(Graphics g) |
行 6: | 行 13: |
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++) // 偶数回置換 |
for(...) for(...) { ... } g.setColor(Color.lightGray); g.fillRect(spx*haba, spy*haba, haba, haba); } }}} {{{#!java void shokika() { ... spx = yoko-1; spy = tate-1; for (cnt = 0; cnt < (tate*yoko*2); ) // 偶数回置換 |
行 16: | 行 31: |
do | x = (int)(Math.random() * yoko); y = (int)(Math.random() * tate); if(x != spx || y != spy) |
行 18: | 行 35: |
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++; } |
ばらばらにする
ピースを1つ取り除いてできた空白部分を使って 移動するための処理を記述します。
int spx, spy;
public void paintComponent(Graphics g) { for(...) for(...) { ... } g.setColor(Color.lightGray); g.fillRect(spx*haba, spy*haba, haba, haba); }