コード例 #1
0
    void ApplyGravityToBoard()
    {
        for (int x = 0; x < width; x++)
        {
            for (int y = height - 1; y >= 0; y--)
            {
                Point p    = new Point(x, y);
                Node  node = GetNodeAtPoint(p);
                int   val  = GetValueAtPoint(p);

                if (val != 0)
                {
                    continue;
                }

                for (int ny = y - 1; ny >= -1; ny--)
                {
                    Point next    = new Point(x, ny);
                    int   nextVal = GetValueAtPoint(next);

                    if (nextVal == 0)
                    {
                        continue;
                    }

                    if (nextVal != -1)
                    {
                        Node      got   = GetNodeAtPoint(next);
                        NodePiece piece = got.GetPiece();

                        node.SetPiece(piece);
                        update.Add(piece);

                        got.SetPiece(null);
                    }
                    else
                    {
                        int       newVal = fillPiece();
                        NodePiece piece;
                        Point     fallPoint = new Point(x, -1 - fills[x]);

                        if (dead.Count > 0)
                        {
                            NodePiece revived = dead[0];
                            revived.ResetBonus();
                            revived.gameObject.SetActive(true);
                            piece = revived;

                            dead.RemoveAt(0);
                        }
                        else
                        {
                            GameObject obj = Instantiate(nodePiece, gameBoard);
                            NodePiece  n   = obj.GetComponent <NodePiece>();
                            piece = n;
                        }
                        piece.Initialize(newVal, p, pieces[newVal - 1]);
                        piece.rect.anchoredPosition = getPositionFromPoint(fallPoint);

                        Node hole = GetNodeAtPoint(p);
                        hole.SetPiece(piece);
                        ResetPiece(piece);
                        fills[x]++;
                    }
                    break;
                }
            }
        }
    }