Ejemplo n.º 1
0
    //sets selectedPiece & legelMoves in BoardManager
    public void SelectPiece()
    {
        //Debug.Log ("Selecting piece at " + selectedX + ", " + selectedY);

        //selected coord is empty
        if (pieceStacks [selectedX, selectedY].Peek() == null)
        {
            Debug.Log("Slected Piece is null");
            return;
        }
        //return if not my piece
        if (pieceStacks [selectedX, selectedY].Peek().isPlayerOne != boardManager.isPlayerOnesTurn)
        {
            Debug.Log("Not my piece");
            //return;
        }

        //selected piece = top of stack at x, y
        boardManager.selectedPiece = pieceStacks [selectedX, selectedY].Peek();

        GetLegalMoves();
        HighlightManager.GetInstance().ShowLegalMoves(boardManager.legalMoves);

        //Debug.Log ("Piece at: " + selectedX + ", " + selectedY + " = ");
        //Debug.Log (pieceStacks [selectedX, selectedY].Peek ());

        //Debug.Log (board.selectedPiece);
    }
Ejemplo n.º 2
0
 void Start()
 {
     highlightManager = HighlightManager.GetInstance();
     client           = FindObjectOfType <Client> ();
     this.pieces      = new Piece[9, 9];
     SetUpBoard();
 }
Ejemplo n.º 3
0
 void Start()
 {
     highlightManager = HighlightManager.GetInstance();
     this.pieces      = new Piece[9, 9];
     SetUpBoard();
 }
Ejemplo n.º 4
0
    public void DropPiece(int x, int y)
    {
        //check for move is legal
        if (boardManager.legalMoves [x, y])
        {
            Debug.Log("SHOULD BE SENDING DROP TO SERVER");

            Vector3 coord = boardManager.selectedPiece.transform.localPosition;

            if (boardManager.client != null && boardManager.client.isHost == boardManager.isPlayerOnesTurn)
            {
                string msg = "CDROP|";

                msg += coord.x.ToString() + "|";
                msg += coord.y.ToString() + "|";
                msg += x.ToString() + "|";
                msg += y.ToString() + "|";

                boardManager.client.Send(msg);
            }

            pieceStacks [Mathf.RoundToInt(coord.x), Mathf.RoundToInt(coord.y)].Pop();

            //set newPos to selected coordinate
            boardManager.pieces [x, y] = boardManager.selectedPiece;
            //.5 compensation for truncated floats to ints
            boardManager.selectedPiece.transform.position = new Vector3(x + .5f, 0, y + .5f);
            //cache new position
            boardManager.selectedPiece.GetCurrentPos();
            //parent piece to the board object
            boardManager.selectedPiece.transform.SetParent(boardManager.transform);

            //switch turns
            boardManager.isPlayerOnesTurn = !boardManager.isPlayerOnesTurn;

            //organize piece gameobject
            if (boardManager.selectedPiece.isPlayerOne)
            {
                boardManager.selectedPiece.transform.SetParent(GameObject.Find("Player 1").transform);
            }
            else
            {
                boardManager.selectedPiece.transform.SetParent(GameObject.Find("Player 2").transform);
            }

            boardManager.selectedPiece.isCaptured = false;

            boardManager.GetComponent <AudioSource> ().Play();

            //update score
            if (Settings.GetInstance().showScore)
            {
                try{
                    Score.GetInstance().UpdateScore();
                } catch {
                    Debug.LogError("Trying to update the score while disabled");
                }
            }
        }
        else
        {
            Debug.Log("ILLEGAL DROP");
        }

        //un-select piece
        boardManager.selectedPiece = null;
        HighlightManager.GetInstance().HideMoves();

        //AI Go
        if (AI.GetInstance().isActive&& boardManager.isPlayerOnesTurn)
        {
            AI.GetInstance().Go();
        }
    }
Ejemplo n.º 5
0
    public void DropPiece(int x, int y)
    {
        //check for move is legal
        if (boardManager.legalMoves [x, y])
        {
            //pop top of stack
            //Debug.Log ((int)board.selectedPiece.transform.localPosition.x);
            //Debug.Log ((int)board.selectedPiece.transform.localPosition.y);

            Vector3 coord = boardManager.selectedPiece.transform.localPosition;
            pieceStacks [Mathf.RoundToInt(coord.x), Mathf.RoundToInt(coord.y)].Pop();

            //set newPos to selected coordinate
            boardManager.pieces [x, y] = boardManager.selectedPiece;
            //.5 compensation for truncated floats to ints
            boardManager.selectedPiece.transform.position = new Vector3(x + .5f, 0, y + .5f);
            //cache new position
            boardManager.selectedPiece.GetCurrentPos();
            //parent piece to the board object
            boardManager.selectedPiece.transform.SetParent(boardManager.transform);

            //switch turns
            boardManager.isPlayerOnesTurn = !boardManager.isPlayerOnesTurn;

            if (boardManager.selectedPiece.isPlayerOne)
            {
                boardManager.selectedPiece.transform.SetParent(GameObject.Find("Player 1").transform);
            }
            else
            {
                boardManager.selectedPiece.transform.SetParent(GameObject.Find("Player 2").transform);
            }

            boardManager.selectedPiece.isCaptured = false;

            boardManager.GetComponent <AudioSource> ().Play();

            if (Settings.GetInstance().showScore)
            {
                try{
                    Score.GetInstance().UpdateScore();
                } catch {
                    Debug.LogError("Trying to update the score while disabled");
                }
            }
        }
        else
        {
            Debug.Log("ILLEGAL DROP");
        }

        //un-select piece

        boardManager.selectedPiece = null;
        HighlightManager.GetInstance().HideMoves();

        if (AI.GetInstance().isActive&& boardManager.isPlayerOnesTurn)
        {
            AI.GetInstance().Go();
        }
    }