70 lines
2.2 KiB
C#
Raw Normal View History

2024-03-17 14:18:19 +04:00
using AntiAircraftGun.CollectionGenereticObject;
using AntiAircraftGun.Drawnings;
namespace AntiAircraftGun.CollectionGenereticObjects;
/// <summary>
/// Реализация абстрактной компании - база бронемашин
/// </summary>
public class CarBase : AbstractCompany
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="collection"></param>
public CarBase(int picWidth, int picHeight, ICollectionGenericObjects<DrawningArmoredCar> collection) : base(picWidth, picHeight, collection)
{
}
2024-03-18 14:23:34 +04:00
/// <summary>
/// Отрисовка базы
/// </summary>
/// <param name="g">Графика</param>
2024-03-17 14:18:19 +04:00
protected override void DrawBackgound(Graphics g)
{
2024-03-18 14:23:34 +04:00
Pen pen = new Pen(Color.Black, 4f);
for (int i = 0; i < _pictureHeight / _placeSizeHeight / 2; i++)
2024-03-17 14:18:19 +04:00
{
2024-03-18 14:23:34 +04:00
g.DrawLine(pen, 0, i * _placeSizeHeight * 2, _pictureWidth / _placeSizeWidth * _placeSizeWidth, i * _placeSizeHeight * 2);
for (int j = 0; j < _pictureWidth / _placeSizeWidth + 1; ++j)
2024-03-17 14:18:19 +04:00
{
2024-03-18 14:23:34 +04:00
g.DrawLine(pen, j * _placeSizeWidth, i * _placeSizeHeight * 2, j * _placeSizeWidth, i * _placeSizeHeight * 2 + _placeSizeHeight);
2024-03-17 14:18:19 +04:00
}
}
}
2024-03-18 14:23:34 +04:00
/// <summary>
/// Установка объекта в базу
/// </summary>
2024-03-17 14:18:19 +04:00
protected override void SetObjectsPosition()
{
2024-05-05 12:00:21 +04:00
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int curWidth = width - 1;
int curHeight = 0;
2024-03-18 14:23:34 +04:00
for (int i = 0; i < (_collection?.Count ?? 0); i++)
2024-03-17 14:18:19 +04:00
{
2024-05-05 12:00:21 +04:00
try
2024-03-18 14:23:34 +04:00
{
2024-05-05 12:00:21 +04:00
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection?.Get(i)?.SetPosition(_placeSizeWidth * curWidth, curHeight * _placeSizeHeight + 4);
2024-03-18 14:23:34 +04:00
}
2024-05-05 12:00:21 +04:00
catch (Exception) { }
if (curWidth > 0)
curWidth--;
else
2024-03-18 14:23:34 +04:00
{
2024-05-05 12:00:21 +04:00
curWidth = width - 1;
curHeight++;
2024-03-18 14:23:34 +04:00
}
2024-05-05 12:00:21 +04:00
if (curHeight > height)
2024-03-17 14:18:19 +04:00
{
2024-05-05 12:00:21 +04:00
return;
2024-03-17 14:18:19 +04:00
}
}
}
}