PIbd-14_Pruidze_I.K_Simple_.../ProjectCruiser/CollectionGenericObj/ShipSharingService.cs
2024-06-17 09:44:23 +04:00

81 lines
2.4 KiB
C#

using ProjectCruiser.DrawningSamples;
namespace ProjectCruiser.CollectionGenericObj;
public class ShipSharingService : AbstractCompany
{
protected int MaxInRow { get; private set; }
protected int MaxInColon { get; private set; }
private int fromBorder = 20, fromCeiling = 20, between = 30;
public ShipSharingService(int picWidth, int picHeight,
ICollectionGenObj<DrawningBase> collection)
: base(picWidth, picHeight, collection)
{
MaxInRow = (picWidth - fromBorder - fromCeiling)
/ (_placeSizeWidth + between);
MaxInColon = (picHeight - fromBorder - fromCeiling)
/ _placeSizeHeight;
}
protected override void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 2);
int currentH = fromCeiling, currentW = fromBorder;
for (int i = 0; i < MaxInRow; i++)
{
currentH = fromCeiling;
for (int j = 0; j < MaxInColon; j++)
{
g.DrawLine(pen, currentW + _placeSizeWidth,
currentH, currentW, currentH);
g.DrawLine(pen, currentW, currentH,
currentW, currentH + _placeSizeHeight);
currentH += _placeSizeHeight + 1;
}
currentW += _placeSizeWidth + between;
}
}
protected override void SetObjectsPosition(int border)
{
int index_collection = 0;
int newY = fromCeiling + 4;
if (_collection != null)
{
for (int i = 0; i < MaxInColon; i++)
{
int newX = fromBorder + 2;
for (int j = 0; j < MaxInRow; j++)
{
try
{
_collection.GetItem(index_collection).SetPictureSize(
_pictureWidth, _pictureHeight);
_collection.GetItem(index_collection).SetPosition(newX, newY);
} catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
newX += _placeSizeWidth + between + 2;
if (index_collection < border)
{
index_collection++;
}
else return;
}
newY += _placeSizeHeight + 1;
}
}
}
}