2024-04-09 08:38:25 +04:00
|
|
|
|
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)
|
|
|
|
|
{
|
2024-04-09 13:54:43 +04:00
|
|
|
|
Color backgroundColor = Color.Gray;
|
2024-04-09 08:38:25 +04:00
|
|
|
|
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;
|
2024-04-09 13:54:43 +04:00
|
|
|
|
int x = _pictureWidth - _placeSizeWidth, y = offsetY;
|
2024-04-09 08:38:25 +04:00
|
|
|
|
numRows = 0;
|
2024-04-09 13:54:43 +04:00
|
|
|
|
while (y + _placeSizeHeight <= _pictureHeight)
|
2024-04-09 08:38:25 +04:00
|
|
|
|
{
|
|
|
|
|
int numCols = 0;
|
2024-04-09 13:54:43 +04:00
|
|
|
|
int initialX = x; // сохраняем начальное значение x
|
|
|
|
|
while (x >= 0)
|
2024-04-09 08:38:25 +04:00
|
|
|
|
{
|
|
|
|
|
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));
|
2024-04-09 13:54:43 +04:00
|
|
|
|
x -= _placeSizeWidth + 2;
|
2024-04-09 08:38:25 +04:00
|
|
|
|
}
|
|
|
|
|
numRows++;
|
2024-04-09 13:54:43 +04:00
|
|
|
|
x = initialX; // возвращаем x к начальному значению после завершения строки
|
|
|
|
|
y += _placeSizeHeight + 5 + offsetY;
|
2024-04-09 08:38:25 +04:00
|
|
|
|
}
|
2024-04-09 13:54:43 +04:00
|
|
|
|
numCols = numCols; // сохраняем значение numCols для использования в других методах
|
2024-04-09 08:38:25 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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--)
|
|
|
|
|
{
|
|
|
|
|
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
|
|
|
|
|
_collection?.Get(i)?.SetPosition(locCoord[row * numCols - col].Item1 + 5, locCoord[row * numCols - col].Item2 + 9);
|
|
|
|
|
if (col == 1)
|
|
|
|
|
{
|
|
|
|
|
col = numCols + 1;
|
|
|
|
|
row--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|