2024-05-13 05:36:46 +04:00

68 lines
1.9 KiB
C#

using ProjectSeaplane.Drawings;
namespace ProjectSeaplane.CollectionGenericObjects;
public abstract class AbstractCompany
{
protected readonly int _placeSizeWidth = 210;
protected readonly int _placeSizeHeight = 100;
protected readonly int _pictureWidth;
protected readonly int _pictureHeight;
protected ICollectionGenericObjects<DrawingPlane>? _collection = null;
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawingPlane> collection)
{
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
_collection.MaxCount = GetMaxCount;
}
public static int? operator +(AbstractCompany company, DrawingPlane plane)
{
return company._collection?.Insert(plane, new DrawingPlaneEqutables());
}
public static DrawingPlane operator -(AbstractCompany company, int position)
{
return company._collection?.Remove(position);
}
public DrawingPlane? GetRandomObject()
{
Random rnd = new();
return _collection?.Get(rnd.Next(GetMaxCount));
}
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)
{
try
{
DrawingPlane? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
}
catch (Exception) { }
}
return bitmap;
}
protected abstract void DrawBackgound(Graphics g);
protected abstract void SetObjectsPosition();
public void Sort(IComparer<DrawingPlane?> comparer) => _collection?.CollectionSort(comparer);
}