80 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirBomber.Drawnings;
namespace AirBomber.CollectionGenericObjects;
public class AirPlaneSharingService : AbstractCompany
{
private List<Tuple<int, int>> locCoord = new List<Tuple<int, int>>();
private int numRows, numCols;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="collection"></param>
public AirPlaneSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningAirPlane> collection) : base(picWidth, picHeight, collection)
{
}
protected override void DrawBackground(Graphics g)
{
Color backgroundColor = Color.Gray;
using (Brush brush = new SolidBrush(backgroundColor))
{
g.FillRectangle(brush, new Rectangle(0, 0, _pictureWidth, _pictureHeight));
}
Pen pen = new Pen(Color.Brown, 3);
int offsetX = 10, offsetY = -12;
int x = _pictureWidth - _placeSizeWidth, y = offsetY;
numRows = 0;
int adjustedHeight = _pictureHeight - (_placeSizeHeight + 5 + offsetY);
while (y + _placeSizeHeight <= adjustedHeight)
{
int numCols = 0;
int initialX = x;
while (x >= 0)
{
numCols++;
g.DrawLine(pen, x, y, x + _placeSizeWidth / 2, y);
g.DrawLine(pen, x, y, x, y + _placeSizeHeight + 4);
locCoord.Add(new Tuple<int, int>(x, y));
x -= _placeSizeWidth + 2;
}
numRows++;
x = initialX;
y += _placeSizeHeight + 5 + offsetY;
}
numCols = numCols;
}
protected override void SetObjectsPosition()
{
if (locCoord == null || _collection == null)
{
return;
}
int row = numRows - 1, col = numCols;
for (int i = 0; i < _collection?.Count; i++, col--)
{
try
{
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection?.Get(i)?.SetPosition(locCoord[row * numCols - col].Item1 + 5, locCoord[row * numCols - col].Item2 + 9);
}
catch (Exception) { }
if (col == 1)
{
col = numCols + 1;
row--;
}
}
}
}