PIbd-11_Nekrasov_A.A._LabWork_07_Simple #9

Closed
alhimek17 wants to merge 2 commits from LabWokr07 into LabWork06
2 changed files with 20 additions and 30 deletions
Showing only changes of commit 913adffdfa - Show all commits

View File

@ -10,35 +10,29 @@ namespace ProjectAirPlane.CollectionGenericObjects;
public abstract class AbstractCompany
{
/// <summary>
/// Размер места (ширина)
/// </summary>
protected readonly int _placeSizeWidth = 210;
/// Размер места (ширина)
/// </summary>
protected readonly int _placeSizeWidth = 210;
/// <summary>
/// Размер места (высота)
/// </summary>
protected readonly int _placeSizeHeight = 80;
protected readonly int _placeSizeHeight = 90;
/// <summary>
/// Ширина окна
/// </summary>
protected readonly int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
protected readonly int _pictureHeight;
/// <summary>
/// Коллекция автомобилей
/// Коллекция судов
/// </summary>
protected ICollectionGenericObjects<DrawningPlane>? _collection = null;
/// <summary>
/// Вычисление максимального количества элементов, который можно разместить в окне
/// </summary>
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
/// <summary>
/// Конструктор
/// </summary>
@ -52,18 +46,16 @@ public abstract class AbstractCompany
_collection = collection;
_collection.MaxCount = GetMaxCount;
}
/// <summary>
/// Перегрузка оператора сложения для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="car">Добавляемый объект</param>
/// <param name="ship">Добавляемый объект</param>
/// <returns></returns>
public static int operator +(AbstractCompany company, DrawningPlane plane)
{
return company._collection?.Insert(plane) ?? -1;
return company._collection.Insert(plane);
}
/// <summary>
/// Перегрузка оператора удаления для класса
/// </summary>
@ -72,9 +64,8 @@ public abstract class AbstractCompany
/// <returns></returns>
public static DrawningPlane operator -(AbstractCompany company, int position)
{
return company._collection?.Remove(position) ?? null;
return company._collection?.Remove(position);
}
/// <summary>
/// Получение случайного объекта из коллекции
/// </summary>
@ -84,7 +75,6 @@ public abstract class AbstractCompany
Random rnd = new();
return _collection?.Get(rnd.Next(GetMaxCount));
}
/// <summary>
/// Вывод всей коллекции
/// </summary>
@ -94,25 +84,25 @@ public abstract class AbstractCompany
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
Graphics graphics = Graphics.FromImage(bitmap);
DrawBackgound(graphics);
SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
DrawningPlane? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
try
{
DrawningPlane? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
}
catch (Exception) { }
}
return bitmap;
}
/// <summary>
/// Вывод заднего фона
/// </summary>
/// <param name="g"></param>
protected abstract void DrawBackgound(Graphics g);
/// <summary>
/// Расстановка объектов
/// </summary>
protected abstract void SetObjectsPosition();
}
}

View File

@ -12,10 +12,9 @@ public class PlaneSharingService : AbstractCompany
public PlaneSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningPlane> collection) : base(picWidth, picHeight, collection)
{
}
protected override void DrawBackgound(Graphics g)
{
//рисуем пристань
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
Pen pen = new(Color.Black, 3);
@ -27,7 +26,6 @@ public class PlaneSharingService : AbstractCompany
}
}
}
protected override void SetObjectsPosition()
{
int width = _pictureWidth / _placeSizeWidth;
@ -38,11 +36,12 @@ public class PlaneSharingService : AbstractCompany
for (int i = 0; i < (_collection?.Count ?? 0); i++)
{
if (_collection.Get(i) != null)
try
{
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
_collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 15, curHeight * _placeSizeHeight + 3);
_collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 20, curHeight * _placeSizeHeight + 4);
}
catch (Exception) { }
if (curWidth > 0)
curWidth--;
else
@ -55,5 +54,6 @@ public class PlaneSharingService : AbstractCompany
return;
}
}
}
}