コード例 #1
0
    // update is called once per frame
    private void Update()
    {
        List <NodePieces> finishedUpdating = new List <NodePieces>();

        for (int i = 0; i < update.Count; i++)
        {
            NodePieces piece = update[i];
            if (!piece.UpdatePiece())
            {
                finishedUpdating.Add(piece);
            }
        }

        for (int i = 0; i < finishedUpdating.Count; i++)
        {
            NodePieces    piece        = finishedUpdating[i];
            FlippedPieces flip         = getFlipped(piece);
            NodePieces    flippedPiece = null;
            int           x            = (int)piece.index.x;
            fills[x] = Mathf.Clamp(fills[x] - 1, 0, width);
            List <Point> connected  = isConnected(piece.index, true);
            bool         wasFlipped = (flip != null);
            if (wasFlipped)
            {
                flippedPiece = flip.getOtherPiece(piece);
                AddPoints(ref connected, isConnected(flippedPiece.index, true));
            }
            if (connected.Count == 0)                                   //If we didn't make a match
            {
                if (wasFlipped)                                         // If we flipped
                {
                    FlipPieces(piece.index, flippedPiece.index, false); //Flip back
                }
            }
            else //Being called if we made a match
            {
                combo.combo_count += 1;

                foreach (Point pnt in connected) //Remove the node pieces when connected
                {
                    KillPiece(pnt);
                    Node       node      = getNodeAtPoint(pnt);
                    NodePieces nodePiece = node.getPiece();
                    if (node.value == 3)
                    {
                        enemy.TakeDamage(5);
                    }
                    if (nodePiece != null)
                    {
                        nodePiece.gameObject.SetActive(false);
                        deadPieces.Add(nodePiece);
                    }

                    node.SetPiece(null);
                }

                BoardGravity();
            }
            flipped.Remove(flip); //remove the flip after update

            update.Remove(piece);
        }
    }