Exemplo n.º 1
0
 //---------------------------------------------------------------
 //ON OBJECT DESTROY
 //---------------------------------------------------------------
 private void OnDestroy(IDamagable sender)
 {
     try
     {
         IDraw system = FindSolarOrBlackHoleSystemWithObject(sender.ToIDraw());
         if (system == null)
         {
             throw new SystemNotFoundException();
         }
         else if (system is SolarSystem)
         {
             system.ToSolarSystem().Objects.Remove(
                 system.ToSolarSystem().Objects.Find(x => Object.ReferenceEquals(sender, x)));
             if (sender is Asteroid)
             {
                 Asteroid temp = CreateAsteroid();
                 temp.OnDestroy += new OnDestroyHandler(OnDestroy);
                 system.ToSolarSystem().Objects.Add(temp);
             }
         }
         else if (system is BlackHoleSystem)
         {
             system.ToBlackHoleSystem().Objects.Remove(
                 system.ToBlackHoleSystem().Objects.Find(x => Object.ReferenceEquals(sender, x)));
             if (sender is Asteroid)
             {
                 Asteroid temp = CreateAsteroid();
                 temp.OnDestroy += new OnDestroyHandler(OnDestroy);
                 system.ToBlackHoleSystem().Objects.Add(temp);
             }
         }
         else
         {
             throw new UnknownException();
         }
     }
     //TODO: Запилить тут обработку исключений нормальную.
     catch
     {
         return;
     }
 }