コード例 #1
0
ファイル: Board.cs プロジェクト: onuregeunaldi/Match3
    // Actual switching function.
    IEnumerator SwitchTilesRoutine(Tile clickedTile, Tile targetTile)
    {
        Drop clickedDrop = m_allDrops[clickedTile.xIndex, clickedTile.yIndex];
        Drop targetDrop  = m_allDrops[targetTile.xIndex, targetTile.yIndex];

        if (targetDrop != null && clickedDrop != null)
        {
            clickedDrop.Move(targetTile.xIndex, targetTile.yIndex, swapTime);                       // Moves the clickedTile to position of taget tile
            targetDrop.Move(clickedTile.xIndex, clickedTile.yIndex, swapTime);                      // Moves the targerTile to position of clicked tile

            yield return(new WaitForSeconds(swapTime));                                             // Waits until Drops switch movement ends.

            List <Drop> clickeddropMatches = FindMatchesAt(clickedTile.xIndex, clickedTile.yIndex); // Check for matches
            List <Drop> targetdropMatches  = FindMatchesAt(targetTile.xIndex, targetTile.yIndex);   // Check for matches

            if (targetdropMatches.Count == 0 && clickeddropMatches.Count == 0)                      // Swich back if there is no match.
            {
                clickedDrop.Move(clickedTile.xIndex, clickedTile.yIndex, swapTime);
                targetDrop.Move(targetTile.xIndex, targetTile.yIndex, swapTime);
            }
            else
            {
                yield return(new WaitForSeconds(swapTime));

                ClearBoard(clickeddropMatches.Union(targetdropMatches).ToList());
            }
        }
    }