well it feels good to fell like it's close heheh
if (y > 1 && getObjectsAt(x, y-2, Actor.class).get(0).getClass() == actor.getClass() && getObjectsAt(x, y-1, Actor.class).get(0).getClass() == actor.getClass())
{ return false;} Tile tile2 = makeSwap(tile, dx, dy);
Tile tile2 = (Tile)getObjectsAt(x+dx, y+dy, Tile.class).get(0);
return tile2;
Tile tile2 = makeSwap(tile, dx, dy);
public void moveSelected(Tile tile, int dx, int dy)
{
Tile tile2 = makeSwap(tile, dx, dy);
}
private void makeSwap(Tile tile, int dx, int dy)
{
int x = tile.getX();
int y = tile.getY();
Tile tile2 = (Tile)getObjectsAt(x+dx, y+dy, Tile.class).get(0);
tile.setLocation(x+dx,y+dy);
tile2.setLocation(x, y);
return tile2;
} private Tile makeSwap(Tile tile, int dx, int dy)
// add as the second line in the 'moveSelected' method (or insert at line 4 of your last code posting)
if (matchingSetFound(tile) || matchingSetFound(tile2)) Tile.setSelected(null); else makeSwap(tile2, dx, dy);
// then add these methods
private boolean matchingSetFound(Tile tile)
{
int x = tile.getX();
int y = tile.getY();
Class cls = tile.getClass();
return getHorizontalMatchCount(x, y, cls) > 1 || getVerticalMatchCount(x, y, cls) > 1;
}
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++;
}
for (int n=1; n<3 && x+n < getWidth(); n++)
{
if (getObjectsAt(x+n, y, Tile.class).get(0).getClass() == cls) count++;
}
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++;
}
for (int n=1; n<3 && y+n < getHeight(); n++)
{
if (getObjectsAt(x, y+n, Tile.class).get(0).getClass() == cls) count++;
}
return count;
}