示例#1
0
        public static Component GetChild(Component pLink)
        {
            Debug.Assert(pLink != null);

            // Assume it is a Leaf, therefore no children.
            Component pChild = null;

            if (pLink.holder == Component.Container.COMPOSITE)
            {
                //could have children, go look.
                pChild = pLink.GetFirstChild();
            }

            return(pChild);
        }
示例#2
0
        static public Component GetChild(Component pNode)
        {
            Debug.Assert(pNode != null);

            Component pChild;

            if (pNode.holder == Component.Container.COMPOSITE)
            {
                pChild = pNode.GetFirstChild();
            }
            else
            {
                pChild = null;
            }

            return(pChild);
        }
示例#3
0
        private Component ReturnChildOrSibling(Component pNode, Component pSibling)
        {
            Component pFirstChild = pNode.GetFirstChild();

            // If has children, return first child
            if (pFirstChild != null)
            {
                return(pFirstChild);
            }
            // Else if node has sibling, return sibling
            else if (pSibling != null)
            {
                return(pSibling);
            }

            // If node has neither child nor sibling
            return(null);
        }
        // TODO Clean this up
        public override void Notify()
        {
            //Debug.WriteLine("RemoveShieldBrickObserver: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB);

            // This cast will throw an exception if wrong
            this.pShieldBrick     = (ShieldBrick)this.pSubject.pObjA;
            this.pColComposite    = null;
            this.pShieldComposite = null;

            // Remove Shield from composite
            Composite       pShieldGrid = GameStateManager.GetGame().GetStateCompositeManager().Find(Composite.CompositeName.ShieldGroup);
            ForwardIterator pFwdIter    = new ForwardIterator(pShieldGrid);

            Component pNode = pFwdIter.First();

            while (!pFwdIter.IsDone())
            {
                if (pNode.containerType == Component.Container.LEAF)
                {
                    // If Component is target shield brick
                    if (pNode.GetHashCode() == this.pShieldBrick.GetHashCode())
                    {
                        // Remove shield brick from column
                        pNode.pParent.Remove(pNode);

                        // Get references to parent composites
                        Component pShieldColComposite = pNode.pParent;
                        Component pShieldComposite    = null;

                        if (pShieldColComposite != null)
                        {
                            pShieldComposite = pShieldColComposite.pParent;
                        }

                        // If column is now empty, delete column
                        if (pShieldColComposite.GetFirstChild() == null)
                        {
                            // Delete empty column from parent composite
                            if (pShieldColComposite.pParent != null)
                            {
                                pShieldColComposite.pParent.Remove(pShieldColComposite);
                            }

                            // Mark empty column for death
                            if (!((GameObject)pShieldColComposite).IsMarkedForDeath())
                            {
                                this.pColComposite = (GameObject)pShieldColComposite;
                                this.pColComposite.MarkForDeath();
                            }
                        }

                        // If Shield is now empty, delete column
                        if (pShieldComposite.GetFirstChild() == null)
                        {
                            // Delete empty shield from parent composite
                            if (pShieldComposite.pParent != null)
                            {
                                pShieldComposite.pParent.Remove(pShieldComposite);
                            }

                            // Mark empty shield for death
                            if (!((GameObject)pShieldComposite).IsMarkedForDeath())
                            {
                                this.pShieldComposite = (GameObject)pShieldComposite;
                                this.pShieldComposite.MarkForDeath();
                            }
                        }

                        break;
                    }
                }

                pNode = pFwdIter.Next();
            }

            if (!pShieldBrick.IsMarkedForDeath())
            {
                pShieldBrick.MarkForDeath();

                // Delay - remove object later
                RemoveShieldBrickObserver pObserver = new RemoveShieldBrickObserver(this);
                GameStateManager.GetGame().GetStateDelayedObjectManager().Attach(pObserver);
            }
        }
示例#5
0
        public override void Notify()
        {
            // Delete missile
            //Debug.WriteLine("RemoveAlienObserver: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB);

            // This cast will throw an exception if wrong
            this.pAlien     = (Alien)this.pSubject.pObjA;
            this.pComposite = null;

            // Remove Alien from composite
            Composite       pAlienGrid = GameStateManager.GetGame().GetStateCompositeManager().Find(Composite.CompositeName.AlienGrid);
            ForwardIterator pFwdIter   = new ForwardIterator(pAlienGrid);

            Component pNode = pFwdIter.First();

            while (!pFwdIter.IsDone())
            {
                if (pNode.containerType == Component.Container.LEAF)
                {
                    // If Component is target alien
                    if (pNode.GetHashCode() == this.pAlien.GetHashCode())
                    {
                        // Remove Alien from column
                        pNode.pParent.Remove(pNode);

                        Component parentComposite = pNode.pParent;
                        // If column is now empty, delete column
                        if (parentComposite.GetFirstChild() == null)
                        {
                            // Delete empty column from parent composite
                            if (parentComposite.pParent != null)
                            {
                                parentComposite.pParent.Remove(parentComposite);
                            }

                            if (!((GameObject)parentComposite).IsMarkedForDeath())
                            {
                                // Delay - remove object later
                                this.pComposite = (GameObject)parentComposite;
                                this.pComposite.MarkForDeath();
                            }
                        }

                        break;
                    }
                }

                pNode = pFwdIter.Next();
            }

            if (!pAlien.IsMarkedForDeath())
            {
                pAlien.MarkForDeath();

                // Delay - remove object later
                RemoveAlienObserver pObserver = new RemoveAlienObserver(this);
                GameStateManager.GetGame().GetStateDelayedObjectManager().Attach(pObserver);
            }

            // Faster grid speed (shorter delta)
            float newSpeed = GameStateManager.GetGame().GetStateAlienGridSpeed() - 0.013f;

            if (newSpeed > 0.0f)
            {
                // Increase Alien Grid Speed
                GameStateManager.GetGame().SetStateAlienGridSpeed(newSpeed);
            }
        }
示例#6
0
        static public Component GetChild(Component pNode)
        {
            Debug.Assert(pNode != null);

            return(pNode.GetFirstChild());
        }