// 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);
            }
        }
Example #2
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);
            }
        }