This commit is contained in:
ShabOl 2023-11-29 10:24:28 +04:00
parent b1f9c38b44
commit f49703596b
3 changed files with 25 additions and 20 deletions

View File

@ -51,18 +51,26 @@ namespace AirBomber
if (obj is null) if (obj is null)
return; return;
if (obj + (Renderer) != -1) try
{ {
MessageBox.Show("Объект добавлен"); if (obj + (Renderer) != -1)
_logger.LogInformation("Объект добавлен"); {
MessageBox.Show("Объект добавлен");
_logger.LogInformation("Объект добавлен");
CollectionPictureBox.Image = obj.ShowEntities(); CollectionPictureBox.Image = obj.ShowEntities();
}
else
{
MessageBox.Show("Не удалось добавить объект");
_logger.LogWarning("Не удалось добавить объект");
}
} }
catch (StorageOverflowException ex)
else
{ {
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show(ex.Message);
_logger.LogWarning("Не удалось добавить объект"); _logger.LogWarning(ex.Message);
} }
} }
@ -97,6 +105,7 @@ namespace AirBomber
catch (EntityNotFoundException ex) catch (EntityNotFoundException ex)
{ {
MessageBox.Show(ex.Message); MessageBox.Show(ex.Message);
_logger.LogWarning(ex.Message);
} }
} }

View File

@ -1,4 +1,5 @@
using AirBomber.MovementStrategy; using AirBomber.Exceptions;
using AirBomber.MovementStrategy;
using AirBomber.Rendering; using AirBomber.Rendering;
namespace AirBomber.Generics namespace AirBomber.Generics
@ -36,12 +37,7 @@ namespace AirBomber.Generics
public static bool operator -(EntitiesGenericCollection<T, U> collect, int pos) public static bool operator -(EntitiesGenericCollection<T, U> collect, int pos)
{ {
T? obj = collect._collection[pos]; return collect._collection.Remove(pos);
if (obj != null)
return collect._collection.Remove(pos);
return false;
} }
public U? GetU(int pos) public U? GetU(int pos)

View File

@ -29,13 +29,13 @@ namespace AirBomber.Generics
return i; return i;
} }
throw new StorageOverflowException(); throw new StorageOverflowException(_maxCount);
} }
public int Insert(T Entity, int Position) public int Insert(T Entity, int Position)
{ {
if (Position >= _maxCount) if (Position >= _maxCount)
throw new StorageOverflowException(); throw new StorageOverflowException(_maxCount);
if (_objects[Position] is null) if (_objects[Position] is null)
{ {
@ -43,16 +43,16 @@ namespace AirBomber.Generics
return Position; return Position;
} }
throw new StorageOverflowException(); throw new StorageOverflowException(_maxCount);
} }
public bool Remove(int Position) public bool Remove(int Position)
{ {
if (Position >= _maxCount) if (Position >= _maxCount)
throw new EntityNotFoundException(); throw new EntityNotFoundException(Position);
if (_objects[Position] is null) if (_objects[Position] is null)
throw new EntityNotFoundException(); throw new EntityNotFoundException(Position);
_objects[Position] = default(T); _objects[Position] = default(T);
return true; return true;