Exemple #1
0
    public void SwapPiece(GemPiece piece)
    {
        if (selectedPiece == null)
        { //First piece selected
            selectedPiece = piece;
            selectedPiece.selection.enabled = true;
        }
        else //Second piece selected
        {
            Point selectedLoc = selectedPiece.location;
            Point pieceLoc    = piece.location;

            //Same piece => deselect
            if (selectedLoc == piece.location)
            {
                selectedPiece.selection.enabled = false;
                selectedPiece = null;
            }
            //Different piece => check up range
            else if (selectedLoc + Point.up == pieceLoc ||
                     selectedLoc + Point.down == pieceLoc ||
                     selectedLoc + Point.left == pieceLoc ||
                     selectedLoc + Point.right == pieceLoc)
            {
                //Increment moves and deselect
                moves++;
                selectedPiece.selection.enabled = false;
                //swap gems in board
                SwapGems(selectedLoc, pieceLoc);
                //play "animation" then check board
                StartCoroutine(WaitForSwap(selectedPiece, piece));
                selectedPiece = null;
            }
        }
    }
Exemple #2
0
    IEnumerator WaitForSwap(GemPiece a, GemPiece b)
    {
        float swapSpeed = 5f;

        //play swaps
        a.StartCoroutine(a.FallToPos(swapSpeed));
        //wait the swap
        yield return(b.StartCoroutine(b.FallToPos(swapSpeed)));

        //Clean up matches
        CleanBoard();
    }