using System; using System.Diagnostics; namespace SpaceInvaders { public class RemoveBombObserver : CollisionObserver { //------------------------------------------------------------------- // FIELDS //------------------------------------------------------------------- private GameObject pBomb; Random rand = new Random(); //------------------------------------------------------------------- // CONSTRUCTION //------------------------------------------------------------------- public RemoveBombObserver() : base() { this.pBomb = null; } public RemoveBombObserver(RemoveBombObserver b) : base() { Debug.Assert(b.pBomb != null); this.pBomb = b.pBomb; } //------------------------------------------------------------------- // PUBLIC METHODS //------------------------------------------------------------------- public override void Notify() { //Debug.WriteLine("Remove Bomb: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB); this.pBomb = (Bomb)this.pSubject.pObjB; //Debug.WriteLine("Delete Bomb: {0}", pBomb); if(pBomb.isDead == false) { pBomb.isDead = true; RemoveBombObserver pObserver = new RemoveBombObserver(this); DelayObjectMan.AttachDelay(pObserver); } } public override void Execute() { //game obj deletes it this.pBomb.Remove(); TimerEventMan.AddEvent(TimerEvent.EventName.AnimateBombDrop, new AnimateBombDrop(), GenRandTime(0.1f, 1.0f)); } float GenRandTime(float min, float max) { double d = rand.NextDouble(); double dout = d * (max - min) + min; return (float)dout; } } // end class } // end namespace