// 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())); } }
IEnumerator IETryMatch(BaseGem from, BaseGem to) { EnableUpdateBoard(true); yield return(StartCoroutine(IESwapGems(from, to))); MatchInfo matchFrom = from.GetMatch(); MatchInfo matchTo = to.GetMatch(); if (!(matchFrom.isValid || matchTo.isValid)) { yield return(StartCoroutine(IESwapGems(from, to))); EnableUpdateBoard(false); } else { HintController.StopCurrentHint(); HintController.StopHinting(); List <MatchInfo> matches = new List <MatchInfo>(); List <Vector2Int> fallPositions = new List <Vector2Int>(); matches.Add(matchFrom); matches.Add(matchTo); if (from.type == GemType.Special) { foreach (MatchInfo specialMatch in matchFrom.specialMatches) { matches.Add(specialMatch); } } if (to.type == GemType.Special) { foreach (MatchInfo specialMatch in matchTo.specialMatches) { matches.Add(specialMatch); } } foreach (var matchInfo in new List <MatchInfo>(matches)) { if (matchInfo.isValid) { fallPositions = MatchInfo.JoinFallPositions( fallPositions, matchInfo.GetFallPositions() ); } else { matches.Remove(matchInfo); } } // if(matchFrom.isValid) { // matches.Add(matchFrom); // fallPositions = MatchInfo.JoinFallPositions( // fallPositions, matchFrom.GetFallPositions() // ); // } // if(matchTo.isValid) { // matches.Add(matchTo); // fallPositions = MatchInfo.JoinFallPositions( // fallPositions, matchTo.GetFallPositions() // ); // } yield return(StartCoroutine(DestroyMatchedGems(matches))); yield return(StartCoroutine(FallGems(fallPositions))); UpdateBoard(); } }