Exemplo n.º 1
0
    private bool IsValidMove(Piece currentPiece)
    {
        MovesBoardController.Instance.HideAllMessages();

        if(currentPiece.tile.posX == initialPieceTile.posX && currentPiece.tile.posY == initialPieceTile.posY)
            return false;

        if(movesOverEmptyTiles != 0){
            return false;
        }

        if(selectedPiece.tile.IsCrossPositionPoint(currentPiece.tile))
        {
            if(currentPiece.IsSameColor(selectedPiece) || currentPiece.IsSameSymbol(selectedPiece) || currentPiece.IsSameSize(selectedPiece))
            {
                if(currentPiece.IsSameColor(selectedPiece))
                    MovesBoardController.Instance.ShowSameColorOK();
                if(currentPiece.IsSameSymbol(selectedPiece))
                    MovesBoardController.Instance.ShowSameSymbolOK();
                if(currentPiece.IsSameSize(selectedPiece))
                    MovesBoardController.Instance.ShowSameSizeOK();

                return true;
            }
            else{
                MovesBoardController.Instance.ShowSameSizeError();
                MovesBoardController.Instance.ShowSameColorError();
                MovesBoardController.Instance.ShowSameSymbolError();
                //Debug.Log("Invalid cross move: Pieces are NEITHER same color NOR same symbol NOR same size");
                return false;
            }
        }
        else if(selectedPiece.tile.IsCornerPositionPoint(currentPiece.tile))
        {
            if(currentPiece.IsSameColor(selectedPiece) && currentPiece.IsSameSymbol(selectedPiece))
            {
                MovesBoardController.Instance.ShowSameColorOK();
                MovesBoardController.Instance.ShowSameSymbolOK();
                Debug.Log("valid corner move: Pieces are same color and symbol");
                return true;
            }
            else if(currentPiece.IsSameColor(selectedPiece) && currentPiece.IsSameSize(selectedPiece))
            {
                MovesBoardController.Instance.ShowSameColorOK();
                MovesBoardController.Instance.ShowSameSizeOK();
                Debug.Log("valid corner move: Pieces are same color and size");
                return true;
            }
            else if(currentPiece.IsSameSymbol(selectedPiece) && currentPiece.IsSameSize(selectedPiece))
            {
                MovesBoardController.Instance.ShowSameSymbolOK();
                MovesBoardController.Instance.ShowSameSizeOK();
                Debug.Log("valid corner move: Pieces are same symbol and size");
                return true;
            }
            else{

                if(currentPiece.IsSameColor(selectedPiece))
                    MovesBoardController.Instance.ShowSameColorOK();
                else
                    MovesBoardController.Instance.ShowSameColorError();

                if(currentPiece.IsSameSize(selectedPiece))
                    MovesBoardController.Instance.ShowSameSizeOK();
                else
                    MovesBoardController.Instance.ShowSameSizeError();

                if(currentPiece.IsSameSymbol(selectedPiece))
                    MovesBoardController.Instance.ShowSameSymbolOK();
                else
                    MovesBoardController.Instance.ShowSameSymbolError();

                return false;
            }
        }
        else{
            MovesBoardController.Instance.ShowInvalidMovementError();
            Debug.Log("Invalid move: Neither corner NOR cross move");
            return false;
        }
    }