using ProjectCruiser.DrawningSamples; namespace ProjectCruiser; 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 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 = 10, currentW = 10; for (int i = 0; i < MaxInRow; i++) { currentH = 10; for (int j = 0; j < MaxInColon; j++) { g.DrawLine(pen, currentW + _placeSizeWidth, currentH - 1, currentW - 1, currentH - 1); g.DrawLine(pen, currentW - 1, currentH - 1, currentW - 1, currentH + _placeSizeHeight); currentH += _placeSizeHeight + 1; } currentW += _placeSizeWidth + between; } } protected override void SetObjectsPosition() { int index_collection = 0; int newX = fromBorder, newY = fromCeiling; if (_collection != null) { for (int i = 0; i < MaxInColon; ++i) { newX = fromBorder; for (int j = 0; j < MaxInRow; ++j) { if (_collection.GetItem(index_collection) != null) { _collection.GetItem(index_collection).SetPictureSize(_pictureWidth, _pictureHeight); _collection.GetItem(index_collection).SetPosition(newX, newY); newX += _placeSizeWidth + between; index_collection++; } } newY += _placeSizeHeight + 2; } } } }