コード例 #1
0
    private IEnumerator ScrambleBoardIfNecessary(Board board, int attempts = 0)
    {
        if (attempts >= 5)
        {
            foreach (Tile tile in board.Tiles)
            {
                if (tile.HasContents)
                {
                    GameObject contents = tile.PushContents(null);
                    AnimatorUtils.Trigger(contents, "Matched");
                }
            }
            yield return(new WaitForSeconds(1.5f));

            yield return(FillBoard(board));
        }

        if (BoardHasNoMatches(board))
        {
            yield return(new WaitForSeconds(1.5f));

            yield return(ScrambleBoard(board));

            yield return(ScrambleBoardIfNecessary(board, attempts + 1));
        }
    }
コード例 #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));
        }
    }
コード例 #3
0
    IEnumerator OnTileClickedCoroutine(Board board, Tile tile)
    {
        try
        {
            if (tile.HasContents && RemainingTurns > 0)
            {
                List <Tile>       matchTiles = GetAdjacentMatches(board, tile, true);
                List <MatchPiece> matches    = (from match in matchTiles
                                                select match.Contents.GetComponent <MatchPiece>())
                                               .ToList();

                if (matches.Count < minimumMatches || !matches[0].CanMatch)
                {
                    matches.ForEach(match => AnimatorUtils.Trigger(match.gameObject, "NoMatch"));
                    AudioManager.Instance.PlaySound("NoMatch");
                    yield break;
                }

                AudioManager.Instance.PlaySound("Match");

                ChangeRemainingTurns(-1, false);

                matches.ForEach(match =>
                {
                    AnimatorUtils.Trigger(match.gameObject, "IsMatching");
                });

                yield return(new WaitForSeconds(waitBeforeProcessingMatch));

                yield return(matches[0].ProcessMatch(matches, matchTiles, board));

                ChangeScore(matches[0].ScoreMatch(matches));

                matchTiles.ForEach(matchedTile =>
                {
                    GameObject piece = matchedTile.PushContents(null);

                    if (!AnimatorUtils.Trigger(piece, "Matched"))
                    {
                        Destroy(piece);
                    }
                });

                yield return(FillBoard(board));

                if (RemainingTurns <= 0)
                {
                    EndGame();
                }
            }
        }
        finally
        {
            board.Unlock();
        }
    }