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;
|
|
|
|
|
private int GetMaxCount => _pictureWidth * _pictureHeight /
|
|
|
|
|
(_placeSizeWidth * _placeSizeHeight);
|
|
|
|
|
|
|
|
|
|
public AbstractCompany(int picWidth, int picHeight,
|
|
|
|
|
ICollectionGenObj<DrawningBase>? collection)
|
|
|
|
|
{
|
|
|
|
|
_pictureWidth = picWidth;
|
|
|
|
|
_pictureHeight = picHeight;
|
|
|
|
|
_collection = collection;
|
|
|
|
|
_collection.SetMaxCount = GetMaxCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Перегрузка оператора сложения для класса
|
|
|
|
|
// [ ! ] insted of bool:
|
2024-06-15 09:05:36 +04:00
|
|
|
|
public static int operator +(AbstractCompany company,
|
|
|
|
|
DrawningBase trasport) => company._collection.Insert(trasport);
|
2024-06-13 00:05:05 +04:00
|
|
|
|
|
|
|
|
|
// Перегрузка оператора удаления для класса
|
2024-06-15 09:05:36 +04:00
|
|
|
|
public static DrawningBase operator -(AbstractCompany company,
|
|
|
|
|
int pos) => company._collection.Remove(pos);
|
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);
|
|
|
|
|
SetObjectsPosition();
|
|
|
|
|
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
|
|
|
|
{
|
|
|
|
|
DrawningBase? obj = _collection?.GetItem(i);
|
|
|
|
|
obj?.DrawTransport(graphics);
|
|
|
|
|
}
|
|
|
|
|
return bitmap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Вывод заднего фона
|
|
|
|
|
protected abstract void DrawBackground(Graphics g);
|
|
|
|
|
|
|
|
|
|
// Расстановка объектов
|
|
|
|
|
protected abstract void SetObjectsPosition();
|
|
|
|
|
}
|
|
|
|
|
|