ばらばらにする
ピースを1つ取り除いてできた空白部分を使って 移動するための処理を記述します。
int spx, spy;
public void paintComponent(Graphics g)
{
for(...)
for(...)
{
...
}
g.setColor(Color.lightGray);
g.fillRect(spx*haba, spy*haba, haba, haba);
}
1 void shokika()
2 {
3 ...
4 spx = yoko-1;
5 spy = tate-1;
6 for (cnt = 0; cnt < (tate*yoko*2); )
7 {
8 x = (int)(Math.random() * yoko);
9 y = (int)(Math.random() * tate);
10 if(x != spx || y != spy)
11 {
12 ban[spx][spy] = ban[x][y];
13 spx = x;
14 spy = y;
15 cnt++;
16 }
17 }
18 }