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,6 +51,8 @@ namespace AirBomber
if (obj is null) if (obj is null)
return; return;
try
{
if (obj + (Renderer) != -1) if (obj + (Renderer) != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
@ -65,6 +67,12 @@ namespace AirBomber
_logger.LogWarning("Не удалось добавить объект"); _logger.LogWarning("Не удалось добавить объект");
} }
} }
catch (StorageOverflowException ex)
{
MessageBox.Show(ex.Message);
_logger.LogWarning(ex.Message);
}
}
public void ButtonRemoveEntity_Click(object sender, EventArgs e) public void ButtonRemoveEntity_Click(object sender, EventArgs e)
{ {
@ -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];
if (obj != null)
return collect._collection.Remove(pos); 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;