Exemplo n.º 1
0
    //IF MOUSECLICK THEN set SelectePiece as above, check if null (if not null then move to raycasted square)
    private void PieceSelector(RaycastHit hitinfo, Dictionary <string, BoardSquare> boardArray)
    {
        BoardSquare hitSq   = hitinfo.collider.GetComponent <BoardSquare>();
        Piece       myPiece = hitinfo.collider.GetComponent <Piece>();

        //No piece selected AND we are NOT clicking a square
        if (SelectedPiece == null && hitSq == null)
        {
            if (playerMatch(myPiece))
            {
                SelectedPiece = myPiece;
                PieceSelectorLight.transform.position = SelectedPiece.transform.position;
                PSLtoggle.enabled = true;

                //Now get valid moves and highlight them
                moveSet = MoveCalc.GetValidMoves(SelectedPiece);
                HighLightMoves();
            }
        }

        //If we have a piece selected AND we click a square, check if valid, then move if so.
        if (SelectedPiece != null && hitSq != null)
        {
            if (moveSet.Contains(hitSq))
            {
                MovePiece(hitSq);
                changeTurn();
            }
        }

        //Otherwise, if we have a piece selected, we are clicking a piece AND that piece ISN'T
        //the one we just selected, we can capture it (if it's a valid move)
        //The logic for valid moves, e.g. can't capture same color piece, will be in movecalc
        if (SelectedPiece != null && myPiece != null && myPiece != SelectedPiece)
        {
            print(myPiece.name);
            if (moveSet.Contains(myPiece.GetSquare()))
            {
                CapturePiece(myPiece);
                changeTurn();
            }
        }
    }