Ejemplo n.º 1
0
        public override void Notify()
        {
            Debug.WriteLine("PlayerDeathObserver: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB);

            Player pPlayer = GameStateManager.GetGame().GetPlayer(playerName);

            // Decrement life count
            pPlayer.LoseLife();

            // Update Life count display
            Font pPlayerLives = FontManager.Find(livesFont);

            Debug.Assert(pPlayerLives != null);
            pPlayerLives.UpdateMessage("LIVES " + pPlayer.GetNumLives().ToString());

            // Remove CoreCannon
            GameObject pCoreCannon = GameStateManager.GetGame().GetStateGameObjectManager().Find(GameObject.Name.CoreCannon);

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

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

            // Set State Change Flag
            GameStateManager.GetGame().SetStateChangeFlag(true);
        }
Ejemplo n.º 2
0
        public override void Notify()
        {
            //Debug.WriteLine("RemoveMissileObserver: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB);

            if (this.pSubject.pObjA.GetType() == typeof(Missile))
            {
                this.pMissile = (Missile)this.pSubject.pObjA;
            }
            else
            {
                this.pMissile = (Missile)this.pSubject.pObjB;
            }


            //Debug.WriteLine("MissileRemoveObserver: --> delete missile {0}", pMissile);

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

                // Delay - remove object later
                RemoveMissileObserver pObserver = new RemoveMissileObserver(this);
                GameStateManager.GetGame().GetStateDelayedObjectManager().Attach(pObserver);
            }
        }
Ejemplo n.º 3
0
        public override void Notify()
        {
            //Debug.WriteLine("RemoveFlyingSaucerObserver: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB);

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

            pAlien.GetCollisionObject().GetCollisionRect().Set(0, 0, 0, 0);
            pAlien.Update();

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

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

            TimerManager.Add(TimeEvent.Name.DeployFlyingSaucer, new DeployFlyingSaucerCommand(), r.Next(30, 61));
        }
Ejemplo n.º 4
0
        public override void Notify()
        {
            //Debug.WriteLine("RemoveBombObserver: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB);

            if ((this.pSubject.pObjA.GetType() == typeof(Bomb)) ||
                (this.pSubject.pObjA.GetType() == typeof(FlyingSaucerBomb)))
            {
                this.pBomb = (Bomb)this.pSubject.pObjA;
            }
            else
            {
                this.pBomb = (Bomb)this.pSubject.pObjB;
            }


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

                // Delay - remove object later
                RemoveBombObserver pObserver = new RemoveBombObserver(this);
                GameStateManager.GetGame().GetStateDelayedObjectManager().Attach(pObserver);
            }
        }
        // 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);
            }
        }
Ejemplo n.º 6
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);
            }
        }