示例#1
0
    public override void OnEndDrag(PointerEventData eventData)
    {
        base.OnEndDrag(eventData);

        Vyhodenie = false;
        if (mColor == Color.white && mTargetCell != null)
        {
            if ((mTargetCell.mBoardPosition.y - mCurrentCell.mBoardPosition.y) == 2)
            {
                int x = mCurrentCell.mBoardPosition.x;
                int y = mCurrentCell.mBoardPosition.y;
                y += 1;
                if (mCurrentCell.mBoardPosition.x < mTargetCell.mBoardPosition.x)
                {
                    x += 1;
                }
                else
                {
                    x -= 1;
                }
                Cell destCell = mTargetCell.mBoard.mAllCells[x, y];
                destCell.RemovePiece();
                Vyhodenie = true;
                mPieceManager.BlackLeft -= 1;
            }

            if ((mTargetCell.mBoardPosition.y - mCurrentCell.mBoardPosition.y) == -2)
            {
                int x = mCurrentCell.mBoardPosition.x;
                int y = mCurrentCell.mBoardPosition.y;
                y -= 1;
                if (mCurrentCell.mBoardPosition.x < mTargetCell.mBoardPosition.x)
                {
                    x += 1;
                }
                else
                {
                    x -= 1;
                }
                Cell destCell = mTargetCell.mBoard.mAllCells[x, y];
                destCell.RemovePiece();
                Vyhodenie = true;
                mPieceManager.BlackLeft -= 1;
            }
        }

        if (mColor == Color.black && mTargetCell != null)
        {
            if ((mCurrentCell.mBoardPosition.y - mTargetCell.mBoardPosition.y) == 2)
            {
                int x = mCurrentCell.mBoardPosition.x;
                int y = mCurrentCell.mBoardPosition.y;
                y -= 1;
                if (mCurrentCell.mBoardPosition.x < mTargetCell.mBoardPosition.x)
                {
                    x += 1;
                }
                else
                {
                    x -= 1;
                }
                Cell destCell = mTargetCell.mBoard.mAllCells[x, y];
                destCell.RemovePiece();
                Vyhodenie = true;
                mPieceManager.WhiteLeft -= 1;
            }

            if ((mCurrentCell.mBoardPosition.y - mTargetCell.mBoardPosition.y) == -2)
            {
                int x = mCurrentCell.mBoardPosition.x;
                int y = mCurrentCell.mBoardPosition.y;
                y += 1;
                if (mCurrentCell.mBoardPosition.x < mTargetCell.mBoardPosition.x)
                {
                    x += 1;
                }
                else
                {
                    x -= 1;
                }
                Cell destCell = mTargetCell.mBoard.mAllCells[x, y];
                destCell.RemovePiece();
                Vyhodenie = true;
                mPieceManager.WhiteLeft -= 1;
            }
        }

        ClearCells();
        ClearCellsDrop();
        mHighlightedCells.Clear();

        if (!mTargetCell)
        {
            transform.position = mCurrentCell.gameObject.transform.position;
            return;
        }

        mDropOutCells.Clear();


        Move();


        if (Vyhodenie == true && (mCurrentCell.mCurrentPiece.GetType() == typeof(Queen)))
        {
            int curentX = mCurrentCell.mBoardPosition.x;
            int curentY = mCurrentCell.mBoardPosition.y;

            CellState cellState    = CellState.None;
            CellState cellState2   = CellState.None;
            CellState cellState3   = CellState.None;
            CellState cellState4   = CellState.None;
            CellState cellStatetmp = CellState.None;

            int col = 0;

            cellState  = mCurrentCell.mBoard.ValidateCell(curentX + mMovement.z, curentY + mMovement.z, this);
            cellState2 = mCurrentCell.mBoard.ValidateCell(curentX - mMovement.z, curentY + mMovement.z, this);
            cellState3 = mCurrentCell.mBoard.ValidateCell(curentX + mMovement.z, curentY - mMovement.z, this);
            cellState4 = mCurrentCell.mBoard.ValidateCell(curentX - mMovement.z, curentY - mMovement.z, this);


            if (cellState == CellState.Enemy)
            {
                col = 1;

                if (col == 1 && mColor == Color.white)
                {
                    cellStatetmp = mCurrentCell.mBoard.ValidateCell(curentX + mMovement.z + mMovement.z, curentY + mMovement.z + mMovement.z, this);
                    if (cellStatetmp == CellState.Free)
                    {
                        mDropOutCells.Add(mCurrentCell.mBoard.mAllCells[curentX + mMovement.z + mMovement.z, curentY + mMovement.z + mMovement.z]);
                    }
                }

                if (col == 1 && mColor == Color.black)
                {
                    cellStatetmp = mCurrentCell.mBoard.ValidateCell(curentX + mMovement.z + mMovement.z, curentY + mMovement.z + mMovement.z, this);
                    if (cellStatetmp == CellState.Free)
                    {
                        mDropOutCells.Add(mCurrentCell.mBoard.mAllCells[curentX + mMovement.z + mMovement.z, curentY + mMovement.z + mMovement.z]);
                    }
                }
            }

            if (cellState2 == CellState.Enemy)
            {
                col = 2;

                if (col == 2 && mColor == Color.white)
                {
                    cellStatetmp = mCurrentCell.mBoard.ValidateCell(curentX - mMovement.z - mMovement.z, curentY + mMovement.z + mMovement.z, this);

                    if (cellStatetmp == CellState.Free)
                    {
                        mDropOutCells.Add(mCurrentCell.mBoard.mAllCells[curentX - mMovement.z - mMovement.z, curentY + mMovement.z + mMovement.z]);
                    }
                }

                if (col == 2 && mColor == Color.black)
                {
                    cellStatetmp = mCurrentCell.mBoard.ValidateCell(curentX - mMovement.z - mMovement.z, curentY + mMovement.z + mMovement.z, this);

                    if (cellStatetmp == CellState.Free)
                    {
                        mDropOutCells.Add(mCurrentCell.mBoard.mAllCells[curentX - mMovement.z - mMovement.z, curentY + mMovement.z + mMovement.z]);
                    }
                }
            }

            if (cellState3 == CellState.Enemy)
            {
                col = 3;

                if (col == 2 && mColor == Color.white)
                {
                    cellStatetmp = mCurrentCell.mBoard.ValidateCell(curentX + mMovement.z + mMovement.z, curentY - mMovement.z - mMovement.z, this);

                    if (cellStatetmp == CellState.Free)
                    {
                        mDropOutCells.Add(mCurrentCell.mBoard.mAllCells[curentX + mMovement.z + mMovement.z, curentY - mMovement.z - mMovement.z]);
                    }
                }

                if (col == 2 && mColor == Color.black)
                {
                    cellStatetmp = mCurrentCell.mBoard.ValidateCell(curentX + mMovement.z + mMovement.z, curentY - mMovement.z - mMovement.z, this);

                    if (cellStatetmp == CellState.Free)
                    {
                        mDropOutCells.Add(mCurrentCell.mBoard.mAllCells[curentX + mMovement.z + mMovement.z, curentY - mMovement.z - mMovement.z]);
                    }
                }
            }

            if (cellState4 == CellState.Enemy)
            {
                col = 4;

                if (col == 2 && mColor == Color.white)
                {
                    cellStatetmp = mCurrentCell.mBoard.ValidateCell(curentX - mMovement.z - mMovement.z, curentY - mMovement.z - mMovement.z, this);

                    if (cellStatetmp == CellState.Free)
                    {
                        mDropOutCells.Add(mCurrentCell.mBoard.mAllCells[curentX - mMovement.z - mMovement.z, curentY - mMovement.z - mMovement.z]);
                    }
                }

                if (col == 2 && mColor == Color.black)
                {
                    cellStatetmp = mCurrentCell.mBoard.ValidateCell(curentX - mMovement.z - mMovement.z, curentY - mMovement.z - mMovement.z, this);

                    if (cellStatetmp == CellState.Free)
                    {
                        mDropOutCells.Add(mCurrentCell.mBoard.mAllCells[curentX - mMovement.z - mMovement.z, curentY - mMovement.z - mMovement.z]);
                    }
                }
            }
        }

        if (Vyhodenie == true && (mCurrentCell.mCurrentPiece.GetType() == typeof(Pawn)))
        {
            int curentX = mCurrentCell.mBoardPosition.x;
            int curentY = mCurrentCell.mBoardPosition.y;

            CellState cellState    = CellState.None;
            CellState cellState2   = CellState.None;
            CellState cellStatetmp = CellState.None;

            int col = 0;

            cellState  = mCurrentCell.mBoard.ValidateCell(curentX + mMovement.z, curentY + mMovement.z, this);
            cellState2 = mCurrentCell.mBoard.ValidateCell(curentX - mMovement.z, curentY + mMovement.z, this);


            if (cellState == CellState.Enemy)
            {
                col = 1;

                if (col == 1 && mColor == Color.white)
                {
                    cellStatetmp = mCurrentCell.mBoard.ValidateCell(curentX + mMovement.z + mMovement.z, curentY + mMovement.z + mMovement.z, this);
                    if (cellStatetmp == CellState.Free)
                    {
                        mDropOutCells.Add(mCurrentCell.mBoard.mAllCells[curentX + mMovement.z + mMovement.z, curentY + mMovement.z + mMovement.z]);
                    }
                }

                if (col == 1 && mColor == Color.black)
                {
                    cellStatetmp = mCurrentCell.mBoard.ValidateCell(curentX + mMovement.z + mMovement.z, curentY + mMovement.z + mMovement.z, this);
                    if (cellStatetmp == CellState.Free)
                    {
                        mDropOutCells.Add(mCurrentCell.mBoard.mAllCells[curentX + mMovement.z + mMovement.z, curentY + mMovement.z + mMovement.z]);
                    }
                }
            }

            if (cellState2 == CellState.Enemy)
            {
                col = 2;

                if (col == 2 && mColor == Color.white)
                {
                    cellStatetmp = mCurrentCell.mBoard.ValidateCell(curentX - mMovement.z - mMovement.z, curentY + mMovement.z + mMovement.z, this);

                    if (cellStatetmp == CellState.Free)
                    {
                        mDropOutCells.Add(mCurrentCell.mBoard.mAllCells[curentX - mMovement.z - mMovement.z, curentY + mMovement.z + mMovement.z]);
                    }
                }

                if (col == 2 && mColor == Color.black)
                {
                    cellStatetmp = mCurrentCell.mBoard.ValidateCell(curentX - mMovement.z - mMovement.z, curentY + mMovement.z + mMovement.z, this);

                    if (cellStatetmp == CellState.Free)
                    {
                        mDropOutCells.Add(mCurrentCell.mBoard.mAllCells[curentX - mMovement.z - mMovement.z, curentY + mMovement.z + mMovement.z]);
                    }
                }
            }
        }
        if (mDropOutCells.Count > 0)
        {
            mPieceManager.DeactivateAll(mCurrentCell.mCurrentPiece);
            next_jump = true;
        }
        else
        {
            next_jump = false;
            mPieceManager.SwitchSides(mColor);
        }
    }