Ejemplo n.º 1
0
    public void HandleDragFinnish()
    {
        bool currentPlayerColor = Constants.COLOR_MAPPING[piece.GetColor()];

        if (destinationSquare)
        {
            destinationSquare.ResetSprite();
            Piece destinationSquarePiece = destinationSquare.GetPiece();

            if (destinationSquare.CanMoveTo == true)
            {
                BoardConfiguration.Instance.MovePiece(currentSquare.GetAlgebraicCoordinates(), destinationSquare.GetAlgebraicCoordinates());

                if (MovesManager.Instance.IsCheckForPlayer(currentPlayerColor))
                {
                    //Debug.Log("You put yourself in check");
                    BoardConfiguration.Instance.MovePiece(destinationSquare.GetAlgebraicCoordinates(), currentSquare.GetAlgebraicCoordinates());
                    piece.RevertToPreviousPosition(parentTransform);
                    if (destinationSquarePiece != null)
                    {
                        destinationSquarePiece.AddPieceToBoardConfiguration();
                    }
                }
                else
                {
                    if (destinationSquarePiece != null)
                    {
                        Debug.Log("Found piece on the destination square");
                        destinationSquarePiece.RemoveFromGame();
                    }
                    piece.PlaceOnSquare(destinationSquare, parentTransform);
                    currentSquare = piece.GetSquare();
                    EndTurnEvent.Invoke(FindObjectOfType <GameManager>().AtMove, MovesManager.Instance.IsCheckForPlayer(!currentPlayerColor));
                }
            }
            else
            {
                piece.RevertToPreviousPosition(parentTransform);
            }
        }

        Board.ClearGreenSquares();
        Board.SetGreenSquares(null);
    }