サイズ: 592
コメント:
|
サイズ: 453
コメント:
|
削除された箇所はこのように表示されます。 | 追加された箇所はこのように表示されます。 |
行 3: | 行 3: |
{{{ int spx, spy; }}} {{{ public void paintComponent(Graphics g) { for(...) for(...) { ... } g.setColor(Color.lightGray); g.fillRect(spx*haba, spy*haba, haba, haba); } }}} |
|
行 23: | 行 7: |
int x, y, x2, y2, w, cnt; | |
行 24: | 行 9: |
spx = yoko-1; spy = tate-1; for (cnt = 0; cnt < (tate*yoko*2); ) // 偶数回置換 |
... for (cnt = 0; cnt < (tate*yoko*2); cnt++) |
行 28: | 行 12: |
x = (int)(Math.random() * yoko); y = (int)(Math.random() * tate); if(x != spx || y != spy) |
x = (int)(Math.random() * (yoko-1)); y = (int)(Math.random() * (tate-1)); if(Math.random() < 0.5) |
行 32: | 行 16: |
ban[spx][spy] = ban[x][y]; spx = x; spy = y; cnt++; |
x2 = x; y2 = y + 1; |
行 37: | 行 19: |
else { x2 = x + 1; y2 = y; } w = ban[x][y]; ban[x][y] = ban[x2][y2]; ban[x2][y2] = w; |
ばらばらにする
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 }