Exemple #1
0
 public override void Add(ZooUnit unit)
 {
     if (unit is Animal && (unit as Animal).IsInZoo)
     {
         throw new CannotAddUnitException("Это животное уже в другой клетке!");
     }
     if (unit is Predator)
     {
         if (this.Units.Count == 0)
         {
             (unit as Animal).IsInZoo = true;
             Units.Add(unit);
         }
         else
         {
             List <ZooUnit> zu = new List <ZooUnit>();
             foreach (var item in this.Units)
             {
                 if (item is Predator)
                 {
                     zu.Add(item);
                 }
             }
             if (zu.Count != 0 && zu[0].GetType() == unit.GetType())
             {
                 (unit as Animal).IsInZoo = true;
                 Units.Add(unit);
             }
         }
     }
     if (unit is CageForBears || unit is CageForWolves)
     {
         Units.Add(unit);
     }
 }
Exemple #2
0
 public override void Add(ZooUnit unit)
 {
     if (unit is Giraffe || unit is CageForGiraffes)
     {
         Units.Add(unit);
     }
 }
 public override void Add(ZooUnit unit)
 {
     if (unit is Wolf || unit is CageForWolves)
     {
         Units.Add(unit);
     }
 }
Exemple #4
0
 public override void Add(ZooUnit unit)
 {
     if (unit is Bear || unit is CageForBears)
     {
         Units.Add(unit);
     }
 }
 public override void Add(ZooUnit unit)
 {
     if (unit is Animal && (unit as Animal).IsInZoo) throw new CannotAddUnitException("Это животное уже в другой клетке!");
     if (unit is Predator)
     {
         if (this.Units.Count == 0)
         {
             (unit as Animal).IsInZoo = true;
             Units.Add(unit);
         }
         else
         {
             List<ZooUnit> zu = new List<ZooUnit>();
             foreach (var item in this.Units)
                 if (item is Predator)
                     zu.Add(item);
             if (zu.Count != 0 && zu[0].GetType() == unit.GetType())
             {
                 (unit as Animal).IsInZoo = true;
                 Units.Add(unit);
             }
             else if(zu.Count !=0) throw new CannotAddUnitException("Тут уже животные другого вида!");
         }
     }
     else if (unit is Animal) throw new CannotAddUnitException("Нельзя добавить травоядное!");
     if (unit is CageForBears || unit is CageForWolves)
         Units.Add(unit);
     else if (!(unit is Animal)) throw new CannotAddUnitException("Нельзя добавить клетку для травоядных!");
     
 }
Exemple #6
0
 public override void Remove(ZooUnit unit)
 {
     if (Units.Contains(unit))
     {
         Units.Remove(unit);
     }
     else
     {
         throw new CannotRemoveUnitException("Невозможно удалить животное/клетку!");
     }
 }
Exemple #7
0
 public override void Remove(ZooUnit unit)
 {
     if (Units.Contains(unit))
     {
         if (unit is Animal)
         {
             (unit as Animal).IsInZoo = false;
             Units.Remove(unit);
         }
     }
     else
     {
         throw new CannotRemoveUnitException("Невозможно удалить животное/клетку!");
     }
 }
Exemple #8
0
 public override void Add(ZooUnit unit)
 {
     if (unit is Bear || unit is CageForBears)
     {
         if (unit is Bear)
         {
             (unit as Animal).IsInZoo = true;
         }
         Units.Add(unit);
     }
     else
     {
         throw new CannotAddUnitException("Невозможно добавить травоядное/клетку для травоядного!");
     }
 }
 public override void Add(ZooUnit unit)
 {
     if (unit is Giraffe || unit is CageForGiraffes)
     {
         if (unit is Giraffe)
         {
             (unit as Animal).IsInZoo = true;
         }
         Units.Add(unit);
     }
     else
     {
         throw new CannotAddUnitException("Невозможно добавить хищника/клетку для хищника!");
     }
 }
Exemple #10
0
 public override void Add(ZooUnit unit)
 {
     if (unit is Animal && (unit as Animal).IsInZoo)
     {
         throw new CannotAddUnitException("Это животное уже в другой клетке!");
     }
     if (unit is Herbivorous)
     {
         if (this.Units.Count == 0)
         {
             Units.Add(unit);
             (unit as Animal).IsInZoo = true;
         }
         else
         {
             List <ZooUnit> zu = new List <ZooUnit>();
             foreach (var item in this.Units)
             {
                 if (item is Herbivorous)
                 {
                     zu.Add(item);
                 }
             }
             if (zu.Count != 0 && zu[0].GetType() == unit.GetType())
             {
                 Units.Add(unit);
                 (unit as Animal).IsInZoo = true;
             }
         }
     }
     else if (unit is Animal)
     {
         throw new CannotAddUnitException("Нельзя добавить хищника!");
     }
     if (unit is CageForGiraffes)
     {
         Units.Add(unit);
     }
     else if (!(unit is Animal))
     {
         throw new CannotAddUnitException("Нельзя добавить клетку для хищников!");
     }
 }
Exemple #11
0
 public abstract void Remove(ZooUnit unit);
Exemple #12
0
 public abstract void Add(ZooUnit unit);
Exemple #13
0
 public override void Add(ZooUnit unit)
 {
     Units.Add(unit);
 }
Exemple #14
0
 public override void Remove(ZooUnit unit)
 {
     throw new InvalidOperationException();
 }