2024-06-13 00:05:05 +04:00
|
|
|
|
using ProjectCruiser.DrawningSamples;
|
2024-06-15 09:05:36 +04:00
|
|
|
|
namespace ProjectCruiser.CollectionGenericObj;
|
2024-06-13 00:05:05 +04:00
|
|
|
|
|
|
|
|
|
/// Абстракция компании, хранящий коллекцию автомобилей
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class AbstractCompany
|
|
|
|
|
{
|
|
|
|
|
// Размеры места
|
|
|
|
|
protected readonly int _placeSizeWidth = 312; // ширина
|
|
|
|
|
|
|
|
|
|
protected readonly int _placeSizeHeight = 56; // высота
|
|
|
|
|
|
|
|
|
|
// Ширина окна
|
|
|
|
|
protected readonly int _pictureWidth;
|
|
|
|
|
// Высота окна
|
|
|
|
|
protected readonly int _pictureHeight;
|
|
|
|
|
|
|
|
|
|
// Коллекция автомобилей
|
|
|
|
|
protected ICollectionGenObj<DrawningBase>? _collection = null;
|
2024-06-16 19:46:37 +04:00
|
|
|
|
private int GetMaxCount => (_pictureWidth / (_placeSizeWidth + 20))
|
|
|
|
|
* ( _pictureHeight / (_placeSizeHeight + 4));
|
2024-06-13 00:05:05 +04:00
|
|
|
|
|
|
|
|
|
public AbstractCompany(int picWidth, int picHeight,
|
|
|
|
|
ICollectionGenObj<DrawningBase>? collection)
|
|
|
|
|
{
|
|
|
|
|
_pictureWidth = picWidth;
|
|
|
|
|
_pictureHeight = picHeight;
|
|
|
|
|
_collection = collection;
|
2024-06-15 13:28:42 +04:00
|
|
|
|
_collection.MaxCount = GetMaxCount;
|
2024-06-13 00:05:05 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Перегрузка оператора сложения для класса
|
2024-06-15 09:05:36 +04:00
|
|
|
|
public static int operator +(AbstractCompany company,
|
2024-06-16 23:08:52 +04:00
|
|
|
|
DrawningBase transport) => company._collection.Insert(transport, new DrawiningShipEqutables());
|
2024-06-13 00:05:05 +04:00
|
|
|
|
|
|
|
|
|
// Перегрузка оператора удаления для класса
|
2024-06-15 09:05:36 +04:00
|
|
|
|
public static DrawningBase operator -(AbstractCompany company,
|
2024-06-16 23:08:52 +04:00
|
|
|
|
int pos) => company._collection?.Remove(pos);
|
2024-06-13 00:05:05 +04:00
|
|
|
|
|
2024-06-16 21:39:45 +04:00
|
|
|
|
// Сортировка ----------------------------------------------------------- [!]
|
|
|
|
|
public void Sort(IComparer<DrawningBase?> comparer) =>
|
|
|
|
|
_collection?.CollectionSort(comparer);
|
|
|
|
|
|
|
|
|
|
|
2024-06-13 00:05:05 +04:00
|
|
|
|
// Получение случайного объекта из коллекции
|
|
|
|
|
public DrawningBase? GetRandomObject()
|
|
|
|
|
{
|
|
|
|
|
Random rnd = new();
|
|
|
|
|
return _collection?.GetItem(rnd.Next(GetMaxCount));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Вывод всей коллекции
|
|
|
|
|
public Bitmap? Show()
|
|
|
|
|
{
|
|
|
|
|
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
|
|
|
|
|
Graphics graphics = Graphics.FromImage(bitmap);
|
|
|
|
|
DrawBackground(graphics);
|
2024-06-16 19:46:37 +04:00
|
|
|
|
|
|
|
|
|
SetObjectsPosition(_collection.Count - 1);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
2024-06-13 00:05:05 +04:00
|
|
|
|
{
|
2024-06-17 09:44:23 +04:00
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
DrawningBase? obj = _collection?.GetItem(i);
|
|
|
|
|
obj?.DrawTransport(graphics);
|
|
|
|
|
|
|
|
|
|
// } catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// Console.WriteLine(ex.Message);
|
|
|
|
|
// }
|
2024-06-13 00:05:05 +04:00
|
|
|
|
}
|
2024-06-16 19:46:37 +04:00
|
|
|
|
|
2024-06-13 00:05:05 +04:00
|
|
|
|
return bitmap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Вывод заднего фона
|
|
|
|
|
protected abstract void DrawBackground(Graphics g);
|
|
|
|
|
|
|
|
|
|
// Расстановка объектов
|
2024-06-16 19:46:37 +04:00
|
|
|
|
protected abstract void SetObjectsPosition(int border);
|
2024-06-13 00:05:05 +04:00
|
|
|
|
}
|
|
|
|
|
|