2024-03-21 10:52:11 +04:00
|
|
|
|
using ProjectCruiser.Drawnings;
|
2024-05-13 22:40:26 +04:00
|
|
|
|
using ProjectCruiser.Exceptions;
|
2024-03-21 10:52:11 +04:00
|
|
|
|
|
|
|
|
|
namespace ProjectCruiser.CollectionGenericObjects
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Абстракция компании, хранящий коллекцию автомобилей
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class AbstractCompany
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Размер места (ширина)
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected readonly int _placeSizeWidth = 180;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Размер места (высота)
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected readonly int _placeSizeHeight = 70;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected readonly int _pictureWidth;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected readonly int _pictureHeight;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-04-04 11:05:33 +04:00
|
|
|
|
/// Коллекция крейсеров
|
2024-03-21 10:52:11 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
protected ICollectionGenericObjects<DrawningCruiser>? _collection = null;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Вычисление максимального количества элементов, который можно разместить в окне
|
|
|
|
|
/// </summary>
|
2024-05-13 22:40:26 +04:00
|
|
|
|
private int GetMaxCount => (_pictureWidth / _placeSizeWidth) * (_pictureHeight / _placeSizeHeight);
|
2024-03-21 10:52:11 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="picWidth">Ширина окна</param>
|
|
|
|
|
/// <param name="picHeight">Высота окна</param>
|
|
|
|
|
/// <param name="collection">Коллекция автомобилей</param>
|
|
|
|
|
public AbstractCompany(int picWidth, int picHeight,
|
|
|
|
|
ICollectionGenericObjects<DrawningCruiser> collection)
|
|
|
|
|
{
|
|
|
|
|
_pictureWidth = picWidth;
|
|
|
|
|
_pictureHeight = picHeight;
|
|
|
|
|
_collection = collection;
|
2024-05-13 12:59:51 +04:00
|
|
|
|
_collection.MaxCount = GetMaxCount;
|
2024-03-21 10:52:11 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Перегрузка оператора сложения для класса
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="company">Компания</param>
|
|
|
|
|
/// <param name="сruiser">Добавляемый объект</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static int operator +(AbstractCompany company, DrawningCruiser сruiser)
|
|
|
|
|
{
|
|
|
|
|
return company._collection.Insert(сruiser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Перегрузка оператора удаления для класса
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="company">Компания</param>
|
|
|
|
|
/// <param name="position">Номер удаляемого объекта</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static DrawningCruiser operator -(AbstractCompany company, int position)
|
|
|
|
|
{
|
|
|
|
|
return company._collection?.Remove(position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение случайного объекта из коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DrawningCruiser? GetRandomObject()
|
|
|
|
|
{
|
|
|
|
|
Random rnd = new();
|
|
|
|
|
return _collection?.Get(rnd.Next(GetMaxCount));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Вывод всей коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Bitmap? Show()
|
|
|
|
|
{
|
|
|
|
|
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
|
|
|
|
|
Graphics graphics = Graphics.FromImage(bitmap);
|
|
|
|
|
DrawBackgound(graphics);
|
|
|
|
|
SetObjectsPosition();
|
|
|
|
|
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
|
|
|
|
{
|
2024-05-13 22:40:26 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DrawningCruiser? obj = _collection?.Get(i);
|
|
|
|
|
obj?.DrawTransport(graphics);
|
|
|
|
|
}
|
|
|
|
|
catch (ObjectNotFoundException e)
|
|
|
|
|
{ }
|
|
|
|
|
catch (PositionOutOfCollectionException e)
|
|
|
|
|
{ }
|
2024-03-21 10:52:11 +04:00
|
|
|
|
}
|
|
|
|
|
return bitmap;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Вывод заднего фона
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="g"></param>
|
|
|
|
|
protected abstract void DrawBackgound(Graphics g);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Расстановка объектов
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected abstract void SetObjectsPosition();
|
|
|
|
|
}
|
|
|
|
|
}
|