예제 #1
0
    IEnumerator SwitchTilesRoutine(Tile_Network clickedTile, Tile_Network targetTile)
    {
        m_playerInputEnabled = false;

        GamePiece_Network clickedPiece = m_allGamePieces[clickedTile.xIndex, clickedTile.yIndex];
        GamePiece_Network targetPiece  = m_allGamePieces[targetTile.xIndex, targetTile.yIndex];

        if (targetPiece != null && clickedPiece != null)
        {
            clickedPiece.Move(targetTile.xIndex, targetTile.yIndex, swapTime);
            targetPiece.Move(clickedTile.xIndex, clickedTile.yIndex, swapTime);

            pieceMoveSound.Play();

            yield return(new WaitForSeconds(swapTime));

            List <GamePiece_Network> clickedPieceMatches = FindMatchesAt(clickedTile.xIndex, clickedTile.yIndex);
            List <GamePiece_Network> targetPieceMatches  = FindMatchesAt(targetTile.xIndex, targetTile.yIndex);

            if (targetPieceMatches.Count == 0 && clickedPieceMatches.Count == 0)
            {
                clickedPiece.Move(clickedTile.xIndex, clickedTile.yIndex, swapTime);
                targetPiece.Move(targetTile.xIndex, targetTile.yIndex, swapTime);
                yield return(new WaitForSeconds(swapTime));

                m_playerInputEnabled = true;
            }
            else
            {
                yield return(new WaitForSeconds(swapTime));

                ClearAndRefillBoard(clickedPieceMatches.Union(targetPieceMatches).ToList());
            }
        }
    }
예제 #2
0
 public void DragToTile(Tile_Network tile)
 {
     if (m_clickedTile != null && IsNextTo(tile, m_clickedTile))
     {
         m_targetTile = tile;
     }
 }
예제 #3
0
 public void ClickTile(Tile_Network tile)
 {
     if (m_clickedTile == null)
     {
         m_clickedTile = tile;
     }
 }
예제 #4
0
    public void ReleaseTile()
    {
        if (m_clickedTile != null && m_targetTile != null)
        {
            SwitchTiles(m_clickedTile, m_targetTile);
        }

        m_clickedTile = null;
        m_targetTile  = null;
    }
예제 #5
0
    bool IsNextTo(Tile_Network start, Tile_Network end)
    {
        if (Mathf.Abs(start.xIndex - end.xIndex) == 1 && start.yIndex == end.yIndex)
        {
            return(true);
        }

        if (Mathf.Abs(start.yIndex - end.yIndex) == 1 && start.xIndex == end.xIndex)
        {
            return(true);
        }

        return(false);
    }
예제 #6
0
 void SwitchTiles(Tile_Network clickedTile, Tile_Network targetTile)
 {
     StartCoroutine(SwitchTilesRoutine(clickedTile, targetTile));
 }