示例#1
0
        public void SelectGamePiece(int x, int y)
        {
            //checks to see if there is a game piece on that square
            if (GamePiecesArray[x, y] == null)
            {
                return;
            }

            //if (GamePiecesArray[x, y].isPlayerX != isPlayerXTurn)
            //    return;

            //currentPlayer.turn

            if (GamePiecesArray[x, y].pieceIdentity != currentPlayer.getIdentity())
            {
                return;
            }


            currentMove.Begin.row = y;
            currentMove.Begin.col = x;

            selectedGamePiece = GamePiecesArray[x, y];

            //DO NOT DEBUG NEXT LINE
            previousMat             = selectedGamePiece.GetComponent <MeshRenderer>().material;
            selectedMat.mainTexture = previousMat.mainTexture;
            selectedGamePiece.GetComponent <MeshRenderer>().material = selectedMat;
        }
示例#2
0
        public void MoveGamePiece(int x, int y)
        {
            //if (selectedGamePiece.isMoveValid(x, y))
            //{
            //    GamePiecesArray[selectedGamePiece.CurrentX, selectedGamePiece.CurrentY] = null;

            //    //move the piece to the new location
            //    if (GamePiecesArray[x, y] != null)
            //        return;
            //    selectedGamePiece.transform.position = GetTileCenter(x, y);
            //    GamePiecesArray[x, y] = selectedGamePiece;
            //    isPlayerXTurn = !isPlayerXTurn;
            //}

            currentMove.End.row = y;
            currentMove.End.col = x;

            if (game.movePiece(currentPlayer.getIdentity(), currentMove))
            {
                if (game.pieceLastTaken != null)
                {
                    removedGamePiece = GamePiecesArray[game.pieceLastTaken.col, game.pieceLastTaken.row];

                    Destroy(removedGamePiece.GetComponent <MeshRenderer>());
                    //activeGamePieces.Remove();
                    GamePiecesArray[game.pieceLastTaken.col, game.pieceLastTaken.row] = selectedGamePiece;

                    Destroy(removedGamePiece.GetComponent <GamePieces>());
                    //GamePiecesArray[game.pieceLastTaken.X, game.pieceLastTaken.Y] = null;
                }

                GamePiecesArray[currentMove.Begin.col, currentMove.Begin.row] = null;
                //GamePiecesArray[currentMove.End.col, currentMove.End.row] = selectedGamePiece;

                StartCoroutine(AnimatePiece(selectedGamePiece, GetTileCenter(x, y).x, GetTileCenter(x, y).z));

                //selectedGamePiece.transform.localPosition = GetTileCenter(x, y);
                GamePiecesArray[x, y] = selectedGamePiece;



                selectedGamePiece.GetComponent <MeshRenderer>().material = previousMat;
                selectedGamePiece = null;


                if (currentPlayer.getIdentity() == identity.X)
                {
                    currentPlayer = PlayerO;
                }
                else
                {
                    currentPlayer = PlayerX;
                }
            }

            else
            {
                //Unhighlight the piece if we are playing locally
                if (!currentPlayer.isAI() && !currentPlayer.isNetwork())
                {
                    if (selectedGamePiece.GetComponent <MeshRenderer>())
                    {
                        selectedGamePiece.GetComponent <MeshRenderer>().material = previousMat;
                    }
                    selectedGamePiece = null;
                }
            }
        }