Exemplo n.º 1
0
    //Grabs all pieces of same type adjacent to lowest piece in column
    public void Grab(int playerPosition)
    {
        //Access each tile from bottom up only in player's column
        for (int i = 11; i >= 0; i--)
        {
            GameObject      currentTile  = boardArray[playerPosition, i];
            int             childCount   = currentTile.transform.childCount;
            PieceController currentPiece = null;

            //Gets the child piece, the first condition is for when it's on the same tile as player
            if (childCount > 1)
            {
                currentPiece = currentTile.transform.GetChild(1).gameObject.GetComponent <PieceController>();
            }
            else if (childCount > 0)
            {
                GameObject currentChild = currentTile.transform.GetChild(0).gameObject;

                if (currentChild.transform.tag != "Player")
                {
                    currentPiece = currentChild.GetComponent <PieceController>();
                }
            }
            //Update basketSize and basketType based on pickups and state of basketType
            //This discriminates between pieces of the current basketType and other types
            if (currentPiece != null)
            {
                if (matchingCoordinates.Contains(new int[] { playerPosition, i }))
                {
                    matchingCoordinates.Clear();
                }
                PieceType currentPieceType = currentPiece.GetType();
                if (basketSize == 0)
                {
                    basketType = currentPieceType;
                }
                else if (currentPieceType != basketType)
                {
                    break;
                }
                basketSize++;
                currentPiece.beingGrabbed = true;

                basketDisplay.SetType(currentPieceType);
                ui.SetBasketText(basketSize);

                StartCoroutine(MovePiece(currentPiece.gameObject, new int[] { playerPosition, 11 }, 11 - i, true));
            }
        }
        print(basketSize);
    }