Пример #1
0
    public bool IsValidMove(int row, int col, Constants.SwipeDirection swipeDirection = Constants.SwipeDirection.RIGHT)
    {
        if (shapes[row, col] == null)
        {
            return(false);
        }
        Shape swapShape = GetSwapShape(row, col, swipeDirection);
        bool  canSwap   = swapShape != null && swapShape.shape_type == Shape.ShapeType.NORMAL;

        //THIS SHOULDNT BE HERE, HANDLE THIS IN THE GAMEPLAY MANAGER

        /*
         * if (canSwap)
         * {
         *  if (swipeDirection == Constants.SwipeDirection.UP)
         *      gamePlayManager.AnimateSwap(swapShape.gameObject, Constants.SwipeDirection.DOWN);
         *  else if (swipeDirection == Constants.SwipeDirection.RIGHT)
         *      gamePlayManager.AnimateSwap(swapShape.gameObject, Constants.SwipeDirection.LEFT);
         *  else if (swipeDirection == Constants.SwipeDirection.DOWN)
         *      gamePlayManager.AnimateSwap(swapShape.gameObject, Constants.SwipeDirection.UP);
         *  else
         *      gamePlayManager.AnimateSwap(swapShape.gameObject, Constants.SwipeDirection.RIGHT);
         * }
         */
        return(canSwap);
    }
Пример #2
0
    public Shape GetSwapShape(Constants.SwipeDirection direction, int row, int col)
    {
        int nextRow = row;
        int nextCol = col;

        switch (direction)
        {
        case Constants.SwipeDirection.UP:
            nextRow -= 1;
            break;

        case Constants.SwipeDirection.RIGHT:
            nextCol += 1;
            break;

        case Constants.SwipeDirection.DOWN:
            nextRow += 1;
            break;

        case Constants.SwipeDirection.LEFT:
            nextCol -= 1;
            break;
        }
        return(shapes[nextRow, nextCol]);
    }
Пример #3
0
    public void SwipeDownEvent(object s)
    {
        PointerEventData ped = (PointerEventData)s;
        //Debug.Log("SwipeDownEvent:" + ped.delta);
        GameObject shapeObject = ped.pointerPress;

        currentSwipeDirection = Constants.SwipeDirection.DOWN;
        FireSwipeEvent(shapeObject, currentSwipeDirection);
    }
Пример #4
0
    public bool SwapPieces(int aRow, int aCol, int bRow, int bCol, Constants.SwipeDirection swipeDirection = Constants.SwipeDirection.RIGHT)
    {
        if (bRow < 0)
        {
            return(false);
        }
        if (bCol < 0)
        {
            return(false);
        }
        if (bRow >= shapes.GetLength(0))
        {
            return(false);
        }
        if (bCol >= shapes.GetLength(1))
        {
            return(false);
        }
        if (aRow >= shapes.GetLength(0))
        {
            return(false);
        }
        if (aCol >= shapes.GetLength(1))
        {
            return(false);
        }
        //Shape tempShape = shapes[bRow, bCol];
        //shapes[bRow, bCol] = shapes[aRow, aCol];
        //shapes[aRow, aCol] = tempShape;
        MovePiecePosition(aRow, aCol, bRow, bCol);
        MovePiecePosition(bRow, bCol, aRow, aCol);

        string    name     = shapes[aRow, aCol].gameObject.name;
        Transform parent   = shapes[aRow, aCol].gameObject.transform.parent.transform;
        Vector3   position = shapes[aRow, aCol].gameObject.transform.position;

        Debug.Log("Swap");
        GameObject clone = GameObject.Instantiate(shapes[aRow, aCol].gameObject);

        GameObject.Destroy(shapes[aRow, aCol].gameObject);
        clone.GetComponentInChildren <Shape>().AssignEvent();
        clone.transform.position = position;
        clone.name = name;
        clone.transform.SetParent(parent);
        clone.transform.localScale = Vector3.one;
        shapes[aRow, aCol]         = shapes[bRow, bCol];
        shapes[bRow, bCol]         = clone.GetComponent <Shape>();
        //CheckMatch(aRow,aCol);
        //CheckMatch(bRow, bCol);
        return(true);
    }
Пример #5
0
    public Shape GetSwapShape(int row, int col, Constants.SwipeDirection swipeDirection = Constants.SwipeDirection.RIGHT)
    {
        int swapRow = row, swapCol = col;

        if (swipeDirection == Constants.SwipeDirection.UP)
        {
            swapRow = row - 1;
        }
        else if (swipeDirection == Constants.SwipeDirection.RIGHT)
        {
            swapCol = col + 1;
        }
        else if (swipeDirection == Constants.SwipeDirection.DOWN)
        {
            swapRow = row + 1;
        }
        else // LEFT
        {
            swapCol = col - 1;
        }
        return(shapes[swapRow, swapCol]);
    }
Пример #6
0
    void FireSwipeEvent(GameObject shapeObject, Constants.SwipeDirection swipeDirection)
    {
        Vector2 vec = shapesManager.GetRowColFromGameObject(shapeObject.transform.parent.gameObject);

        if (vec.x == -10f)
        {
            Debug.LogError("Destroy Something is Seriously wrong ");
            //GameObject.Destroy(shapeObject.transform.parent.gameObject);
            return;
        }
        int row = (int)vec.x;
        int col = (int)vec.y;
        // ask shape manager if can attemp to swap
        // this is dependent on if there is an edge or untouchable terrain
        bool validMove = shapesManager.IsValidMove(row, col, swipeDirection);

        if (validMove)
        {
            SoundManager.PlaySound("short_whoosh");
            Shape   shape    = shapesManager.GetShape(row, col);
            Vector3 position = shapesManager.GetPositionOfBackgroundPiece(row, col);

            // get the other shape
            Vector2 nextRowCol   = Constants.GetNextRowCol(swipeDirection, row, col);
            Shape   nextShape    = shapesManager.GetShape((int)nextRowCol.x, (int)nextRowCol.y);
            Vector3 nextPosition = shapesManager.GetPositionOfBackgroundPiece((int)nextRowCol.x, (int)nextRowCol.y);

            StartCoroutine(
                shape.AnimatePosition(nextPosition, Constants.DEFAULT_SWAP_ANIMATION_DURATION, () =>
            {
                //CheckMatch(row, col, (int)nextRowCol.x, (int)nextRowCol.y);
                //CheckWholeBoard();
                int nRow            = (int)nextRowCol.x;
                int nCol            = (int)nextRowCol.y;
                bool successfulSwap = shapesManager.SwapPieces(row, col, nRow, nCol);
                ShapesManager.CheckResult leftResult  = shapesManager.CheckMatch(row, col);
                ShapesManager.CheckResult rightResult = shapesManager.CheckMatch(nRow, nCol);
                bool isMatch = CheckMatch(leftResult, rightResult);
                if (successfulSwap && !isMatch)
                {
                    // also make a function
                    SoundManager.PlaySound("button-29");
                    Constants.SwipeDirection oppositeDirection = Constants.GetOppositeDirection(currentSwipeDirection);
                    Shape currentShape      = shapesManager.GetShape(row, col);
                    Shape nextShape1        = shapesManager.GetShape(nRow, nCol);
                    Vector3 currentPosition = shapesManager.GetPositionOfBackgroundPiece(row, col);
                    Vector3 nextPosition1   = shapesManager.GetPositionOfBackgroundPiece(nRow, nCol);
                    StartCoroutine(
                        currentShape.AnimatePosition(nextPosition, Constants.DEFAULT_SWAP_ANIMATION_DURATION, () => {
                        shapesManager.SwapPieces(row, col, nRow, nCol);
                        blockEvent = false;
                    })
                        );

                    StartCoroutine(
                        nextShape1.AnimatePosition(currentPosition, Constants.DEFAULT_SWAP_ANIMATION_DURATION, () => {
                        Debug.Log("DAH");
                    })
                        );
                }
                else
                {
                    this.currentMoves--;
                    UIManager.UpdateMoveValue(this.currentMoves, this.maxMoves);
                    CheckWholeBoard();
                }
            })
                );
            StartCoroutine(
                nextShape.AnimatePosition(position, Constants.DEFAULT_SWAP_ANIMATION_DURATION, () => {  })
                );
        }
    }