コード例 #1
0
ファイル: GameManager.cs プロジェクト: vancisesam/tak
 public void nextTurn() // proceeds to the next players turn
 {
     currentDirection     = direction.neither;
     currentDirectionSign = directionSign.neither;
     allPiecesNonMovable();
     if (currentTurn == turn.round)
     {
         currentTurn = turn.square;
         turnText.GetComponent <Text>().text = "Square Turn";
         playersPieces = squarePieces;
         markMovable();
     }
     else if (currentTurn == turn.square)
     {
         currentTurn = turn.round;
         turnText.GetComponent <Text>().text = "Round Turn";
         playersPieces = roundPieces;
         markMovable();
     }
 }
コード例 #2
0
ファイル: GameManager.cs プロジェクト: vancisesam/tak
    bool isEligibleTarget(GameObject toHere)
    {
        Vector3 targetPos   = toHere.transform.position;
        Vector3 selectedPos = selected.transform.position;

        //Debug.Log("checking eligiblity");
        if (toHere.tag != "boardSquare")
        { //check if you are moving onto another piece
            DragPiece toHereData = toHere.GetComponent <DragPiece>();
            if (toHereData.isCap)
            {
                setErrorText("You cannot move onto a Cap Stone");
                return(false);
            }
            else if (toHereData.isWall)   //cannot move onto a wall
            {
                if (selected.GetComponent <DragPiece>().isCap)
                {
                    toHereData.crushWall();


                    return(true);
                }
                setErrorText("You cannot move onto a wall");
                return(false);
            }
        }
        if (selected.GetComponent <DragPiece>().inStack)
        {
            Debug.Log("selected is from stack");
            if (toHere.tag != "boardSquare")
            {
                setErrorText("Moving a piece from stack on top of another piece is not allowed");
                return(false);   //a move from the stack to another piece is not allowed
            }
            return(true);
        }

        else if (targetPos.x == selectedPos.x)
        {
            if (targetPos.z == selectedPos.z)   //the target and the selected are in the same position
            {
                setErrorText("Cannot move to the same position");
                return(false);
            }
            else if (currentDirection == direction.horizontal)
            {
                setErrorText("You can only move horizontally");
                return(false);
            }
            else if (targetPos.z == selectedPos.z + 1.0f || targetPos.z == selectedPos.z - 1.0f)
            {
                switch (currentDirectionSign)
                {
                case directionSign.neither:
                    currentDirectionSign = (targetPos.z == selectedPos.z + 1.0f) ? directionSign.positive : directionSign.negative;
                    currentDirection     = direction.vertical;
                    return(true);

                case directionSign.negative:
                    return(targetPos.z == selectedPos.z - 1.0f);

                case directionSign.positive:
                    return(targetPos.z == selectedPos.z + 1.0f);
                }
            }
            setErrorText("You can only move one square at a time");
            return(false);
        }
        else if (targetPos.z == selectedPos.z)
        {
            if (currentDirection == direction.vertical)
            {
                setErrorText("You can only move vertically");
                return(false);
            }
            else if (targetPos.x == selectedPos.x + 1.0f || targetPos.x == selectedPos.x - 1.0f)
            {
                switch (currentDirectionSign)
                {
                case directionSign.neither:
                    currentDirectionSign = (targetPos.x == selectedPos.x + 1.0f) ? directionSign.positive : directionSign.negative;
                    currentDirection     = direction.horizontal;
                    return(true);

                case directionSign.negative:
                    return(targetPos.x == selectedPos.x - 1.0f);

                case directionSign.positive:
                    return(targetPos.x == selectedPos.x + 1.0f);
                }
            }
            setErrorText("You can only move one square at a time");
            return(false);
        }
        setErrorText("You cannot move diagonally");
        return(false);
    }