サイズ: 459
コメント:
|
サイズ: 453
コメント:
|
削除された箇所はこのように表示されます。 | 追加された箇所はこのように表示されます。 |
行 3: | 行 3: |
{{{ int spx, spy; |
{{{#!java void shokika() { int x, y, x2, y2, w, cnt; ... ... for (cnt = 0; cnt < (tate*yoko*2); cnt++) { x = (int)(Math.random() * (yoko-1)); y = (int)(Math.random() * (tate-1)); if(Math.random() < 0.5) { x2 = x; y2 = y + 1; } else { x2 = x + 1; y2 = y; } w = ban[x][y]; ban[x][y] = ban[x2][y2]; ban[x2][y2] = w; } } |
行 6: | 行 30: |
{{{ g.setColor(Color.lightGray); g.fillRect(spx*haba, spy*haba, haba, haba); }}} {{{ 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++; } } }}} |
ばらばらにする
1 void shokika()
2 {
3 int x, y, x2, y2, w, cnt;
4 ...
5 ...
6 for (cnt = 0; cnt < (tate*yoko*2); cnt++)
7 {
8 x = (int)(Math.random() * (yoko-1));
9 y = (int)(Math.random() * (tate-1));
10 if(Math.random() < 0.5)
11 {
12 x2 = x;
13 y2 = y + 1;
14 }
15 else
16 {
17 x2 = x + 1;
18 y2 = y;
19 }
20 w = ban[x][y];
21 ban[x][y] = ban[x2][y2];
22 ban[x2][y2] = w;
23 }
24 }