Esempio n. 1
0
    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 bool LookupPossibleNeighborSlotsFor(Match3BoardPiece piece)
    {
        int numNeighborDirections = (int)Match3BoardPiece.LinkType.Count;

        possibleMatchSlots.Clear();

        for (int i = 0; i < numNeighborDirections; i += 2)
        {
            // Count max 2 neighbors in each direction
            Match3BoardPiece neighborIterator = piece;

            for (int j = 0; j < 2; j++)
            {
                neighborIterator = neighborIterator.GetNeighbor((Match3BoardPiece.LinkType)i);

                if (neighborIterator != null && neighborIterator.Tile != null && neighborIterator.Tile.GetType() == typeof(NormalTile) &&
                    (!isBoardSetup || !(neighborIterator.Tile as NormalTile).IsTileIgnoredByAntiMatchSystems))
                {
                    possibleMatchSlots.Add(neighborIterator);
                    if (possibleMatchSlots.Count == 3)
                    {
                        return(true);
                    }
                }
                else
                {
                    break;
                }
            }
        }

        return(false);
    }
Esempio n. 3
0
    public void ApplyPunchEffectToNeighbors(int xSign, int ySign, int zSign)
    {
        // Apply punch effect to neighbors at the end of the current frame
        Match3BoardPiece boardPiece = BoardPiece as Match3BoardPiece;

        if (boardPiece != null)
        {
            int numNeighbors          = (int)Match3BoardPiece.LinkType.Count;
            Match3BoardPiece neighbor = null;

            for (int i = 0; i < numNeighbors; i++)
            {
                neighbor = boardPiece.GetNeighbor((Match3BoardPiece.LinkType)i);
                if (neighbor != null && neighbor.Tile != null && !neighbor.Tile.IsDestroying)
                {
                    Vector3 punchHeading = neighbor.Tile.LocalPosition - LocalPosition;
                    // Some of the tile model axis don't correspond with their parent axis and so the calculated direction must changed.
                    punchHeading.x = punchHeading.x * xSign;
                    punchHeading.y = punchHeading.y * ySign;
                    punchHeading.z = punchHeading.z * zSign;

                    // Apply the punch effect at the end of the current frame
                    (neighbor.Tile as NormalTile).ApplyLateUpdatePunchEffect(punchHeading);
                }
            }
        }
    }
    public void GetValidTargetNeighborTilesFor(Match3BoardPiece piece)
    {
        possibleTargetTiles.Clear();

        for (int i = 0; i < (int)Match3BoardPiece.LinkType.Count; i += 2)
        {
            Match3BoardPiece neighbor = piece.GetNeighbor((Match3BoardPiece.LinkType)i);

            if (neighbor != null && neighbor.Tile != null && neighbor.Tile.IsUserMoveable)
            {
                possibleTargetTiles.Add(neighbor.Tile as Match3Tile);
            }
        }
    }
    /// <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);
    }
Esempio n. 6
0
	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;
	}		
	/// <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;
	}
	public void GetValidTargetNeighborTilesFor(Match3BoardPiece piece)
	{
		possibleTargetTiles.Clear();
		
		for(int i = 0; i < (int)Match3BoardPiece.LinkType.Count; i += 2) 
		{
			Match3BoardPiece neighbor = piece.GetNeighbor( (Match3BoardPiece.LinkType)i );
			
			if (neighbor != null && neighbor.Tile != null && neighbor.Tile.IsUserMoveable) {
				possibleTargetTiles.Add(neighbor.Tile as Match3Tile);
			}
		}
	}