From f49703596b7060c8e3501c49ac49b17ecb1ce10c Mon Sep 17 00:00:00 2001 From: olshab Date: Wed, 29 Nov 2023 10:24:28 +0400 Subject: [PATCH] final --- AirBomber/FormEntityCollection.cs | 25 +++++++++++++------ .../Generics/EntitiesGenericCollection.cs | 10 +++----- AirBomber/Generics/SetGeneric.cs | 10 ++++---- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/AirBomber/FormEntityCollection.cs b/AirBomber/FormEntityCollection.cs index 5135250..ec45175 100644 --- a/AirBomber/FormEntityCollection.cs +++ b/AirBomber/FormEntityCollection.cs @@ -51,18 +51,26 @@ namespace AirBomber if (obj is null) return; - if (obj + (Renderer) != -1) + try { - MessageBox.Show("Объект добавлен"); - _logger.LogInformation("Объект добавлен"); + if (obj + (Renderer) != -1) + { + MessageBox.Show("Объект добавлен"); + _logger.LogInformation("Объект добавлен"); - CollectionPictureBox.Image = obj.ShowEntities(); + CollectionPictureBox.Image = obj.ShowEntities(); + } + + else + { + MessageBox.Show("Не удалось добавить объект"); + _logger.LogWarning("Не удалось добавить объект"); + } } - - else + catch (StorageOverflowException ex) { - MessageBox.Show("Не удалось добавить объект"); - _logger.LogWarning("Не удалось добавить объект"); + MessageBox.Show(ex.Message); + _logger.LogWarning(ex.Message); } } @@ -97,6 +105,7 @@ namespace AirBomber catch (EntityNotFoundException ex) { MessageBox.Show(ex.Message); + _logger.LogWarning(ex.Message); } } diff --git a/AirBomber/Generics/EntitiesGenericCollection.cs b/AirBomber/Generics/EntitiesGenericCollection.cs index d8954ee..3e45de2 100644 --- a/AirBomber/Generics/EntitiesGenericCollection.cs +++ b/AirBomber/Generics/EntitiesGenericCollection.cs @@ -1,4 +1,5 @@ -using AirBomber.MovementStrategy; +using AirBomber.Exceptions; +using AirBomber.MovementStrategy; using AirBomber.Rendering; namespace AirBomber.Generics @@ -36,12 +37,7 @@ namespace AirBomber.Generics public static bool operator -(EntitiesGenericCollection collect, int pos) { - T? obj = collect._collection[pos]; - - if (obj != null) - return collect._collection.Remove(pos); - - return false; + return collect._collection.Remove(pos); } public U? GetU(int pos) diff --git a/AirBomber/Generics/SetGeneric.cs b/AirBomber/Generics/SetGeneric.cs index bffb484..dba30a0 100644 --- a/AirBomber/Generics/SetGeneric.cs +++ b/AirBomber/Generics/SetGeneric.cs @@ -29,13 +29,13 @@ namespace AirBomber.Generics return i; } - throw new StorageOverflowException(); + throw new StorageOverflowException(_maxCount); } public int Insert(T Entity, int Position) { if (Position >= _maxCount) - throw new StorageOverflowException(); + throw new StorageOverflowException(_maxCount); if (_objects[Position] is null) { @@ -43,16 +43,16 @@ namespace AirBomber.Generics return Position; } - throw new StorageOverflowException(); + throw new StorageOverflowException(_maxCount); } public bool Remove(int Position) { if (Position >= _maxCount) - throw new EntityNotFoundException(); + throw new EntityNotFoundException(Position); if (_objects[Position] is null) - throw new EntityNotFoundException(); + throw new EntityNotFoundException(Position); _objects[Position] = default(T); return true;