protected void CheckMatch(Match3Tile currentTile, ref Match3Tile targetTile, bool isVerticalPass) { // Debug.Log("Current tile: " + currentTile + "\n" + "targetTile: " + targetTile); if (targetTile == null || !targetTile.CanBeMatched) { // If there is no target tile to check matches with yet, try to set the currentTile as the targetTile and // get back to the loop so we can move to the next tile to compare it with the new targetTile. if (currentTile != null && currentTile.CanBeMatched) { targetTile = currentTile; if (matchesBatch.Count > 0) { matchesBatch.Clear(); } matchesBatch.Add(targetTile); } } else if (currentTile != null && currentTile.IsMatchWith(targetTile)) { // If we found a matching tile with the targetTile add it to our temporary matches buffer. matchesBatch.Add(currentTile); } else { // If we found a tile different from the targetTile then we finished collecting tiles for the current batch and // we must check if we found at least 3 to add to our final "lastFoundMatches" result. // We also make the current tile the new targetTile because it belongs in a different batch of matches. targetTile = currentTile; if (matchesBatch.Count >= 3) { CollectNewFoundMatches(matchesBatch, isVerticalPass); } // Clear the current temporary matches buffer. matchesBatch.Clear(); // We check here if the new target tile can be matched then we already add it to the new batch of matches. if (targetTile != null && targetTile.CanBeMatched) { matchesBatch.Add(currentTile); } } }
/// <summary> /// Find the neighbor pieces of the specified "currentPiece" in the direction "direction" that match between them. /// This method is called by <see cref="ProcessBoardPiece(AbstractBoardPiece boardPiece)"/>. /// </summary> /// <returns> /// The neighbor pieces for. /// </returns> /// <param name='currentPiece'> /// If set to <c>true</c> current piece. /// </param> /// <param name='direction'> /// If set to <c>true</c> direction. /// </param> protected bool FindMatchingNeighborPiecesFor(Match3BoardPiece currentPiece, Match3BoardPiece.LinkType direction) { Match3BoardPiece prevPiece = null; // // Reference to the piece who's neighbors we're about to process. // Match3BoardPiece originPiece = currentPiece; // Look at the next 2 neighbors in the specified "direction". for (int i = 0; i < 2; i++) { currentPiece = currentPiece.GetNeighbor(direction); // If this board piece is invalid or contains an invalid tile, stop the current neighbor lookup for the "currentPiece" // but continue the search with the next board pieces. if (currentPiece == null || currentPiece.Tile == null || currentPiece.Tile.IsDestroying || (currentPiece.Tile as NormalTile).IsTileSwitching || (currentPiece.Tile as NormalTile).IsFrozen() || !(currentPiece.Tile as Match3Tile).CanBeMatched && !(currentPiece.Tile is TriggerTile) || (currentPiece.Tile is TriggerTile) && !currentPiece.Tile.IsUserMoveable) { return(true); } Match3Tile currentTile = currentPiece.Tile as Match3Tile; if (prevPiece != null) { Match3Tile prevTile = prevPiece.Tile as Match3Tile; if (prevTile.IsMatchWith(currentTile)) { // Add this tile because it matches the previous one. AddNewPossibleMatchTile(currentTile); if (HasFoundPossibleMatchForColor(currentTile.TileColor)) { // Stop looking for other possible matches. return(false); } } } else { // int lastTriggerTileIdx = triggerTileMatchFound.Count - 1; // if (lastTriggerTileIdx >= 0 && triggerTileMatchFound[lastTriggerTileIdx] is ColorBombTile) { // Debug.LogWarning("[PossibleMatchesFinder] originalPiece = " + originalPiece + "\n -> search direction: " + direction + "\n -> " + " currentTile = " + currentTile); // } // Add this tile to the partial matches buffer because it's the first one AddNewPossibleMatchTile(currentTile); if (HasFoundPossibleMatchForColor(currentTile.TileColor)) { // Stop looking for other possible matches. return(false); } } prevPiece = currentPiece; } // Can continue to the next board piece. return(true); }
protected TileColorType GetMatchingColorBetweenDirections(Match3BoardPiece startPiece, Match3BoardPiece.LinkType dirA, Match3BoardPiece.LinkType dirB) { Match3BoardPiece pieceDirA = startPiece.GetNeighbor(dirA); Match3BoardPiece pieceDirB = null; if (dirA != dirB) { pieceDirB = startPiece.GetNeighbor(dirB); } else if (pieceDirA != null) { pieceDirB = pieceDirA.GetNeighbor(dirA); } if (pieceDirA != null && pieceDirB != null) { Match3Tile tileDirA = pieceDirA.Tile as Match3Tile; Match3Tile tileDirB = pieceDirB.Tile as Match3Tile; if (tileDirA != null && tileDirB != null && tileDirA.CanBeMatched && tileDirB.CanBeMatched && tileDirA.IsMatchWith(tileDirB)) { return(tileDirA.TileColor); } } return(TileColorType.None); }
protected void CheckMatch(Match3Tile currentTile, ref Match3Tile targetTile, bool isVerticalPass) { // Debug.Log("Current tile: " + currentTile + "\n" + "targetTile: " + targetTile); if ( targetTile == null || !targetTile.CanBeMatched ) { // If there is no target tile to check matches with yet, try to set the currentTile as the targetTile and // get back to the loop so we can move to the next tile to compare it with the new targetTile. if (currentTile != null && currentTile.CanBeMatched) { targetTile = currentTile; if (matchesBatch.Count > 0) { matchesBatch.Clear(); } matchesBatch.Add(targetTile); } } else if (currentTile != null && currentTile.IsMatchWith(targetTile)) { // If we found a matching tile with the targetTile add it to our temporary matches buffer. matchesBatch.Add(currentTile); } else { // If we found a tile different from the targetTile then we finished collecting tiles for the current batch and // we must check if we found at least 3 to add to our final "lastFoundMatches" result. // We also make the current tile the new targetTile because it belongs in a different batch of matches. targetTile = currentTile; if (matchesBatch.Count >= 3) { CollectNewFoundMatches(matchesBatch, isVerticalPass); } // Clear the current temporary matches buffer. matchesBatch.Clear(); // We check here if the new target tile can be matched then we already add it to the new batch of matches. if (targetTile != null && targetTile.CanBeMatched) { matchesBatch.Add(currentTile); } } }