2024-04-02 08:53:49 +04:00
|
|
|
|
using ProjectStormtrooper.Drawnings;
|
|
|
|
|
|
|
|
|
|
namespace ProjectStormtrooper.CollectionGenericObjects;
|
|
|
|
|
/// <summary>
|
2024-04-02 10:25:36 +04:00
|
|
|
|
/// Абстракция компании, хранящий коллекцию штурмовика
|
2024-04-02 08:53:49 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class AbstractCompany
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Размер места (ширина)
|
|
|
|
|
/// </summary>
|
2024-05-13 21:19:14 +04:00
|
|
|
|
protected readonly int _placeSizeWidth = 220;
|
2024-04-02 08:53:49 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Размер места (высота)
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected readonly int _placeSizeHeight = 155;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected readonly int _pictureWidth;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected readonly int _pictureHeight;
|
2024-05-13 21:19:14 +04:00
|
|
|
|
protected static int amountOfObjects = 0;
|
2024-04-02 08:53:49 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Коллекция штурмовика
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected ICollectionGenericObjects<DrawningStormtrooperBase>? _collection = null;
|
2024-05-13 21:19:14 +04:00
|
|
|
|
public static int getAmountOfObjects()
|
|
|
|
|
{
|
|
|
|
|
return amountOfObjects;
|
|
|
|
|
}
|
2024-04-02 08:53:49 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Вычисление максимального количества элементов, который можно разместить в окне
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="picWidth">Ширина окна</param>
|
|
|
|
|
/// <param name="picHeight">Высота окна</param>
|
2024-04-02 10:25:36 +04:00
|
|
|
|
/// <param name="collection">Коллекция штурмовика</param>
|
2024-04-02 08:53:49 +04:00
|
|
|
|
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningStormtrooperBase> collection)
|
|
|
|
|
{
|
|
|
|
|
_pictureWidth = picWidth;
|
|
|
|
|
_pictureHeight = picHeight;
|
|
|
|
|
_collection = collection;
|
2024-04-30 11:26:54 +04:00
|
|
|
|
_collection.MaxCount = GetMaxCount;
|
2024-04-02 08:53:49 +04:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Перегрузка оператора сложения для класса
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="company">Компания</param>
|
|
|
|
|
/// <param name="stormtrooper">Добавляемый объект</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static int operator +(AbstractCompany company, DrawningStormtrooperBase stormtrooper)
|
|
|
|
|
{
|
2024-05-16 21:57:38 +04:00
|
|
|
|
return company._collection.Insert(stormtrooper, new DrawinigStormtrooperBaseEqutables());
|
2024-04-02 08:53:49 +04:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Перегрузка оператора удаления для класса
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="company">Компания</param>
|
|
|
|
|
/// <param name="position">Номер удаляемого объекта</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static DrawningStormtrooperBase operator -(AbstractCompany company, int position)
|
|
|
|
|
{
|
|
|
|
|
return company._collection.Remove(position);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение случайного объекта из коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DrawningStormtrooperBase? 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 21:19:14 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DrawningStormtrooperBase? obj = _collection?.Get(i);
|
|
|
|
|
obj?.DrawTransport(graphics);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception) { }
|
2024-04-02 08:53:49 +04:00
|
|
|
|
}
|
|
|
|
|
return bitmap;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Вывод заднего фона
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="g"></param>
|
|
|
|
|
protected abstract void DrawBackgound(Graphics graphics);
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Расстановка объектов
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected abstract void SetObjectsPosition();
|
2024-05-16 21:57:38 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сортировка
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="comparer">Сравнитель объектов</param>
|
|
|
|
|
public void Sort(IComparer<DrawningStormtrooperBase?> comparer) => _collection?.CollectionSort(comparer);
|
2024-04-02 08:53:49 +04:00
|
|
|
|
}
|