To clarify, it will NOT make the move selected UNLESS a matching set is created by the move.
private int getHorizontalMatchCount(int x, int y, Class cls)
{
int count = 0;
for (int n=1; n<3 && x-n >= 0; n++)
{
if (getObjectsAt(x-n, y, Tile.class).get(0).getClass() == cls) count++;
else break;
}
for (int n=1; n<3 && x+n < getWidth(); n++)
{
if (getObjectsAt(x+n, y, Tile.class).get(0).getClass() == cls) count++;
else break;
}
return count;
}
private int getVerticalMatchCount(int x, int y, Class cls)
{
int count = 0;
for (int n=1; n<3 && y-n >= 0; n++)
{
if (getObjectsAt(x, y-n, Tile.class).get(0).getClass() == cls) count++;
else break;
}
for (int n=1; n<3 && y+n < getHeight(); n++)
{
if (getObjectsAt(x, y+n, Tile.class).get(0).getClass() == cls) count++;
else break;
}
return count;
}// ABCACBA // BACACAB // AA CC // CBACABC // BCACACB