Esempio n. 1
0
    public static MatchInfo GetCrossMatch(
        BaseGem gem, Func <BaseGem, bool> validateGem
        )
    {
        List <BaseGem> matches = new List <BaseGem>();

        MatchInfo horizontal = GetHorizontalMatch(gem, validateGem);
        MatchInfo vertical   = GetVerticalMatch(gem, validateGem);

        MatchInfo matchInfo = new MatchInfo();

        int crossCheck = 0;

        while (!horizontal.isValid && crossCheck < vertical.matches.Count)
        {
            if (vertical.isValid)
            {
                horizontal = GetHorizontalMatch(
                    vertical.matches[crossCheck], validateGem
                    );
            }
            else
            {
                break;
            }
            crossCheck++;
        }

        crossCheck = 0;
        while (!vertical.isValid && crossCheck < horizontal.matches.Count)
        {
            if (horizontal.isValid)
            {
                vertical = GetVerticalMatch(
                    horizontal.matches[crossCheck], validateGem
                    );
            }
            else
            {
                break;
            }
            crossCheck++;
        }

        MatchInfo cross = MatchInfo.JoinCrossedMatches(horizontal, vertical);

        if (!cross.isValid)
        {
            if (horizontal.isValid)
            {
                return(horizontal);
            }
            else
            {
                return(vertical);
            }
        }

        return(cross);
    }
Esempio n. 2
0
    // Check for matches in all Board
    IEnumerator FindChainMatches()
    {
        List <BaseGem>   gems       = gemBoard.GetList();
        List <MatchInfo> matchInfos = new List <MatchInfo>();

        while (gems.Count > 0)
        {
            BaseGem current = gems[0];
            gems.Remove(current);

            if (current.type == GemType.Special)
            {
                continue;
            }

            MatchInfo matchInfo = current.GetMatch();
            if (matchInfo.isValid)
            {
                matchInfo.matches.ForEach(gem => gems.Remove(gem));

                MatchInfo matchInfoSameType = matchInfos.Find(
                    mi => mi.pivot.type == matchInfo.pivot.type
                    );

                if (matchInfoSameType != null)
                {
                    matchInfoSameType = MatchInfo.JoinCrossedMatches(
                        matchInfoSameType, matchInfo
                        );

                    if (matchInfoSameType.isValid)
                    {
                        matchInfos.Add(matchInfoSameType);
                        continue;
                    }
                }

                matchInfos.Add(matchInfo);
            }
        }

        if (matchInfos.Count > 0)
        {
            List <Vector2Int> fallPositions    = new List <Vector2Int>();
            List <MatchInfo>  matchesToDestroy = new List <MatchInfo>();
            foreach (MatchInfo matchInfo in matchInfos)
            {
                matchesToDestroy.Add(matchInfo);
                fallPositions = MatchInfo.JoinFallPositions(
                    fallPositions, matchInfo.GetFallPositions()
                    );
            }

            yield return(StartCoroutine(DestroyMatchedGems(matchesToDestroy)));

            yield return(StartCoroutine(FallGems(fallPositions)));

            yield return(StartCoroutine(FindChainMatches()));
        }
    }