Ejemplo n.º 1
0
    public static NumberTile FindFloorTile(NumberTile tile)
    {
        NumberTile nextTile = tile.FindNeighbourTile(Direction.down);

        while (IsInactiveTile(nextTile))
        {
            tile     = nextTile;
            nextTile = tile.FindNeighbourTile(Direction.down);
        }

        return(tile);
    }
Ejemplo n.º 2
0
    bool MergeNeighbourTiles(NumberTile tile, ref List <NumberTile> mergedTiles)
    {
        int mergeCount = 0;

        foreach (Direction direction in mergeDirections)
        {
            NumberTile neighbour = tile.FindNeighbourTile(direction);
            if (NumberTile.IsActiveTile(neighbour) && tile.IsEqualNumber(neighbour))
            {
                neighbour.DeActivate();
                mergedTiles.Add(neighbour);
                mergeCount++;
            }
        }

        int multiplier = (int)Mathf.Pow(2, mergeCount);

        if (multiplier > 1)
        {
            tile.Multiply(multiplier);
            if (handler != null)
            {
                handler.OnTileMerged(tile);
            }

            return(true);
        }

        return(false);
    }
Ejemplo n.º 3
0
    public static NumberTile TryFindActiveTopTile(NumberTile tile)
    {
        NumberTile nextTile = tile.FindNeighbourTile(Direction.up);

        while (IsInactiveTile(nextTile))
        {
            tile     = nextTile;
            nextTile = tile.FindNeighbourTile(Direction.up);
        }

        if (IsActiveTile(nextTile))
        {
            return(nextTile);
        }


        return(null);
    }
Ejemplo n.º 4
0
    public static List <NumberTile> FindActiveTilesInDirection(NumberTile tile, Direction dir)
    {
        List <NumberTile> tiles = new List <NumberTile>();

        NumberTile nextTile = tile.FindNeighbourTile(dir);

        while (IsActiveTile(nextTile))
        {
            tiles.Add(nextTile);
            nextTile = nextTile.FindNeighbourTile(dir);
        }

        return(tiles);
    }