public PieceData ChooseAdjacentPiece(Tile tile, Board board, List <PieceData> pieceOptions)
    {
        List <Tile> shuffledTiles = board.GetAdjacentTiles(tile, false)
                                    .OrderBy(a => Random.value)
                                    .ToList();

        foreach (Tile randomTile in shuffledTiles)
        {
            if (!randomTile.HasContents)
            {
                continue;
            }

            MatchPiece matchPiece = randomTile.Contents.GetComponent <MatchPiece>();
            foreach (PieceData pieceOption in pieceOptions)
            {
                if (pieceOption.Matches(matchPiece))
                {
                    return(pieceOption);
                }
            }
        }

        return(null);
    }
Beispiel #2
0
    public override IEnumerator ProcessMatch(List <MatchPiece> matches, List <Tile> matchTiles, Board board)
    {
        bool destroyedFire = false;

        var adjacentTiles = board.GetAdjacentTiles(matchTiles, false);

        foreach (Tile tile in adjacentTiles)
        {
            if (!tile.HasContents)
            {
                continue;
            }

            MatchPiece piece = tile.Contents.GetComponent <MatchPiece>();
            if (piece.Matches(typeof(FirePiece)))
            {
                tile.PushContents(null);
                if (!AnimatorUtils.Trigger(piece.gameObject, "DestroyWithWater"))
                {
                    Destroy(piece.gameObject);
                }
                destroyedFire = true;
            }
        }

        if (destroyedFire)
        {
            AudioManager.Instance.PlaySound("DestroyWithWater");
            yield return(new WaitForSeconds(destroyFireWaitTime));
        }

        bool bloomed = false;

        foreach (Tile tile in adjacentTiles)
        {
            if (!tile.HasContents)
            {
                continue;
            }

            MatchPiece piece = tile.Contents.GetComponent <MatchPiece>();
            if (piece.Matches(typeof(SeedPiece)))
            {
                var flowerPrefab = ((SeedPiece)piece).FlowerPrefab.gameObject;
                tile.PushContentsFromPrefab(flowerPrefab);
                if (!AnimatorUtils.Trigger(piece.gameObject, "Bloom"))
                {
                    Destroy(piece.gameObject);
                }
                bloomed = true;
            }
        }

        if (bloomed)
        {
            AudioManager.Instance.PlaySound("BloomWithWater");
            yield return(new WaitForSeconds(bloomWaitTime));
        }
    }
    private List <Tile> GetAdjacentMatchesRecursive(List <Tile> result, Board board, Tile tile, bool ignoreCanMatch)
    {
        MatchPiece piece = tile.Contents.GetComponent <MatchPiece>();

        if (piece == null)
        {
            return(result);
        }

        List <Tile> adjacentTiles = board.GetAdjacentTiles(tile, false);

        foreach (Tile adjacentTile in adjacentTiles)
        {
            MatchPiece adjacentPiece = adjacentTile.HasContents ? adjacentTile.Contents.GetComponent <MatchPiece>() : null;
            if (adjacentPiece && (ignoreCanMatch || (piece.CanMatch && adjacentPiece.CanMatch)) &&
                piece.Matches(adjacentPiece) && !result.Contains(adjacentTile))
            {
                result.Add(adjacentTile);
                GetAdjacentMatchesRecursive(result, board, adjacentTile, ignoreCanMatch);
            }
        }

        return(result);
    }
Beispiel #4
0
 public bool Matches(MatchPiece otherPiece)
 {
     return(TileType.Equals(otherPiece.TileType));
 }
 public bool Matches(MatchPiece otherPiece)
 {
     return(piecePrefab.Matches(otherPiece));
 }