laba8: maybe ready

This commit is contained in:
bulatova_karina 2023-12-20 10:41:38 +03:00
parent f214dc995c
commit f5fb0777e6
4 changed files with 30 additions and 32 deletions

View File

@ -162,9 +162,9 @@ namespace WarmlyShip
return;
}
var formShipConfig = new FormShipConfig();
formShipConfig.AddEvent(AddShip);
formShipConfig.Show();
var formBoatConfig = new FormShipConfig();
formBoatConfig.AddEvent(AddShip);
formBoatConfig.Show();
}
private void AddShip(DrawingWarmlyShip drawingWarmlyShip)
{
@ -178,7 +178,7 @@ namespace WarmlyShip
_logger.LogWarning("Добавление пустого объекта");
return;
}
if (obj + drawingWarmlyShip)
if (obj + drawingWarmlyShip != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowShips();
@ -189,7 +189,6 @@ namespace WarmlyShip
MessageBox.Show("Не удалось добавить объект");
_logger.LogInformation($"Не удалось добавить объект");
}
}
/// <summary>
/// Удаление объекта из набора

View File

@ -37,12 +37,9 @@ namespace WarmlyShip.Generics
/// </summary>
/// <param name="warmlyship">Добавляемый теплоход</param>
/// <returns></returns>
public bool Insert(T warmlyship, IEqualityComparer<T?>? equal = null)
public int Insert(T warmlyship, IEqualityComparer<T?>? equal = null)
{
if (_places.Count == _maxCount)
throw new StorageOverflowException(_maxCount);
Insert(warmlyship, 0, equal);
return true;
return Insert(warmlyship, 0, equal);
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
@ -50,19 +47,20 @@ namespace WarmlyShip.Generics
/// <param name="warmlyship">Добавляемый теплоход</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public bool Insert(T warmlyship, int position, IEqualityComparer<T?>? equal = null)
public int Insert(T warmlyship, int position, IEqualityComparer<T?>? equal = null)
{
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
if (position < 0 || position > Count)
throw new ShipNotFoundException(position);
if (Count >= _maxCount)
throw new StorageOverflowException(_maxCount);
if (!(position >= 0 && position <= Count))
return false;
if (equal != null)
if (equal != null && _places.Contains(warmlyship, equal))
{
if (_places.Contains(warmlyship, equal))
throw new ArgumentException(nameof(warmlyship));
//throw new StorageOverflowException("Данный объект уже есть в коллекции");
//MessageBox.Show("Данный объект уже есть в коллекции");
return -1;
}
_places.Insert(position, warmlyship);
return true;
return position;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции

View File

@ -14,12 +14,6 @@ namespace WarmlyShip.Generics
where T : DrawingWarmlyShip
where U : IMoveableObject
{
/// <summary>
/// Сортировка
/// </summary>
/// <param name="comparer"></param>
public void Sort(IComparer<T?> comparer) =>
_collection.SortSet(comparer);
/// <summary>
/// Получение объектов коллекции
/// </summary>
@ -45,6 +39,16 @@ namespace WarmlyShip.Generics
/// </summary>
private readonly SetGeneric<T> _collection;
/// <summary>
/// Получение объектов коллекции
/// </summary>
public IEnumerable<T?> GetAirplanes => _collection.GetShips();
/// <summary>
/// Сортировка
/// </summary>
/// <param name="comparer"></param>
public void Sort(IComparer<T?> comparer) =>
_collection.SortSet(comparer);
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
@ -63,14 +67,14 @@ namespace WarmlyShip.Generics
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static bool operator +(ShipsGenericCollection<T, U> collect, T?
public static int operator +(ShipsGenericCollection<T, U> collect, T?
obj)
{
if (obj == null)
{
return false;
return -1;
}
return (bool)collect?._collection.Insert(obj);
return collect._collection.Insert(obj, new DrawingShipEqutables());
}
/// <summary>
/// Перегрузка оператора вычитания
@ -82,10 +86,7 @@ namespace WarmlyShip.Generics
pos)
{
T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
}
collect._collection.Remove(pos);
return obj;
}
/// <summary>

View File

@ -171,7 +171,7 @@ namespace WarmlyShip.Generics
elem?.CreateDrawingShip(_separatorForObject, _pictureWidth, _pictureHeight);
if (ship != null)
{
if (!(collection + ship))
if (collection + ship != -1)
{
throw new Exception("Ошибка добавления в коллекцию");
}