Пример #1
0
    void takePieceCurrentlyIn(Position pos)
    {
        GameObject  takenPiece  = currentPos[pos];
        PiecesClass takenScript = takenPiece.GetComponent <PiecesClass>();

        if (takenScript.type == "King")
        {
            winSide = currentPlayer; //current player so=hould be the oppsite to the taken piece
            winFlag = true;
        }
        else if (takenScript.type == "Lord")
        {
            takenPiece  = turnLordToMan(takenPiece);
            takenScript = takenPiece.GetComponent <PiecesClass>();
        }

        if (takenScript.side == playerTurn.RED)
        {
            //TAKEN BY GREEN
            takenScript.side = playerTurn.GREEN;
            for (int i = 0; i < greenTaken.Length; i++)
            {
                if (greenTaken[i] == null)
                {
                    greenTaken[i] = takenPiece;
                    takenPiece.transform.position = new Vector3(-5 + (2 * i), -6);
                    takenPiece.transform.rotation = getSideRotate(playerTurn.GREEN);
                    currentPos[pos] = null;
                    takenScript.updateLocation(Position.TAKEN);
                    break;
                }
            }
        }
        else if (takenScript.side == playerTurn.GREEN)
        {
            //TAKEN BY RED
            takenScript.side = playerTurn.RED;
            for (int i = 0; i < redTaken.Length; i++)
            {
                if (redTaken[i] == null)
                {
                    redTaken[i] = takenPiece;
                    takenPiece.transform.position = new Vector3(-5 + (2 * i), 6);
                    takenPiece.transform.rotation = getSideRotate(playerTurn.RED);
                    currentPos[pos] = null;
                    takenScript.updateLocation(Position.TAKEN);
                    break;
                }
            }
        }
    }
Пример #2
0
    public void movePiece(Transform tran, PiecesClass piece)
    {
        bool  flag        = true;
        float currentPosX = tran.position.x;
        float currentPosY = tran.position.y;

        foreach (KeyValuePair <Position, Vector3> entry in posTransforms)
        {
            if (currentPosX >= entry.Value.x - 1 && currentPosX < entry.Value.x + 1 && currentPosY >= entry.Value.y - 1 && currentPosY < entry.Value.y + 1)
            {
                if (validateMove(entry.Key, piece))
                {
                    if (piece.positionOB == Position.TAKEN)
                    {
                        if (piece.side == playerTurn.GREEN)
                        {
                            removeFromTaken(piece.gameObject, greenTaken);
                        }
                        else if (piece.side == playerTurn.RED)
                        {
                            removeFromTaken(piece.gameObject, redTaken);
                        }
                    }
                    tran.position = entry.Value;
                    flag          = false;
                    updatePieceSide(piece, entry.Key, piece.side);
                    piece.updateLocation(entry.Key);

                    //CHANGE MAN TO LORD AT THE END LOGIC
                    if (piece.type == "Man" && endOfBoard(piece))
                    {
                        Position    tempPos  = piece.positionOB;
                        GameObject  lord     = turnManToLord(piece.gameObject);
                        PiecesClass lordInfo = lord.GetComponent <PiecesClass>();
                        lordInfo.positionOB = tempPos;
                        lordInfo.side       = currentPlayer;
                    }

                    if (winFlag)
                    {
                        win(winSide);         //A king has been taken
                    }
                    else if (currentPlayer == playerTurn.GREEN && endOfBoard(redKing))
                    {
                        win(redKing.side);                                                               // THE RED KING IS AT THE END AT THE END OF GREENS TRUN
                    }
                    else if (endOfBoard(greenKing))
                    {
                        win(greenKing.side);                            // THE GREEN KING IS AT THE END AT THE END OF REDS TRUN
                    }
                    else
                    {
                        changeTurn();
                    }
                }
                break;
            }
        }

        if (flag)
        {
            piece.resetPos();
        }
    }