我正在尝试编写一种使用电路板的方法,并检查电路板上的任何给定点是否在一点到右点之间交换,导致电路板上发生“匹配”。然后将导致交换的点添加到Point []并返回。我的数组返回,但它只返回,[null],[null],[null]。为什么不回归?
由于
public static Point[] findPossibleSwaps(Board b)
{
Point[] swaps = new Point[3];
int x = 0;
int y = 0;
Point normal = new Point (x,y);
Point hor = new Point (x+1, y);
Point ver = new Point (x, y+1);
int count = 0;
for(y = 0; y < b.getSize()-1; y++)
{
for(x = 0; x < b.getSize()-1; x++)
{
b.swapSquares(normal,hor);
if (b.hasMatches() && (x)!=b.getSize()-1)
{
swaps[count] = new Point(x+1,y);
count++;
}
b.swapSquares(hor, normal);
b.swapSquares(normal, ver);
if (b.hasMatches() && y!=b.getSize()-1)
{
swaps[count] = new Point(x,y+1);
count++;
}
b.swapSquares(ver, normal);
}
}
return swaps;
}