Exemple #1
0
    public void PlayerTurn(Ray ray, Dictionary <string, BoardSquare> boardArray, Board.GameState gameState)
    {
        RaycastHit  hitinfo;
        GameObject  obj;
        BoardSquare bsq;

        this.whichPlayer = gameState;

        if (Physics.Raycast(ray, out hitinfo, Mathf.Infinity))
        {
            obj = hitinfo.collider.gameObject;
            if (boardArray.TryGetValue(obj.name, out bsq))
            {
                if (!SelectedSquare)                         //if there is no selected square
                {
                    SelectedSquare = bsq;                    //set it
                    bsq.SelectSquare();                      //highlight it
                }
                if (SelectedSquare && SelectedSquare != bsq) //if there is a new square
                {
                    bsq.SelectSquare();                      //highlight it
                    SelectedSquare.DeselectSquare();         //unhighlight old
                    SelectedSquare = bsq;
                }
            }

            /* else if (SelectedSquare)
             * {
             *   SelectedSquare.DeselectSquare();
             *   SelectedSquare = null;
             * }*/

            if (Input.GetMouseButtonDown(0))
            {
                PieceSelector(hitinfo, boardArray);
            }
        }
        else //Raycast returns false if not hitting a collider
        {
            if (SelectedSquare != null)
            {
                SelectedSquare.DeselectSquare();
                SelectedSquare = null;
            }
            if (Input.GetMouseButtonDown(0)) //besure to dehighlight before nulling
            {
                print("Piece deselected");
                DeselectPiece();
                PSLtoggle.enabled = false;
            }
        }
    }
Exemple #2
0
    private void changeTurn()
    {
        switch (whichPlayer)
        {
        case Board.GameState.PLAYER_1:
        {
            this.whichPlayer = Board.GameState.PLAYER_2;
            break;
        }

        case Board.GameState.PLAYER_2:
        {
            this.whichPlayer = Board.GameState.PLAYER_1;
            break;
        }
        }
    }