73 lines
2.6 KiB
C#
73 lines
2.6 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;
|
|
while (y + _placeSizeHeight <= _pictureHeight)
|
|
{
|
|
int numCols = 0;
|
|
int initialX = x; // сохраняем начальное значение 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; // возвращаем x к начальному значению после завершения строки
|
|
y += _placeSizeHeight + 5 + offsetY;
|
|
}
|
|
numCols = 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--)
|
|
{
|
|
_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--;
|
|
}
|
|
}
|
|
}
|
|
}
|