using ProjectStormTrooper.Drawnings; using ProjectStormTrooper.Exceptions; namespace ProjectStormTrooper.CollectionGenericObjects; /// /// Реализация абстрактной компании - каршеринг /// public class Hangar : AbstractCompany { /// /// Конструктор /// /// /// /// public Hangar(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) { } protected override void DrawBackgound(Graphics g) { Pen pen = new(Color.Black, 3); int posX = 0; for (int i = 0; i < _pictureWidth/_placeSizeWidth; i++) { int posY = 0; g.DrawLine(pen, posX, posY, posX, posY + _placeSizeHeight*(_pictureHeight/ _placeSizeHeight)); for(int j = 0; j <= _pictureHeight/_placeSizeHeight; j++) { g.DrawLine(pen, posX, posY, posX + _placeSizeWidth-ColsSpace, posY); posY += _placeSizeHeight; } posX += _placeSizeWidth; } } protected override void SetObjectsPosition() { int posX = _pictureWidth / _placeSizeWidth-1; int posY = 0; for (int i = 0; i < _collection?.Count; i++) { try { _collection?.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); _collection?.Get(i).SetPosition(posX * _placeSizeWidth, posY * _placeSizeHeight); } catch (ObjectNotFoundException) { break; } if(posX > 0) { posX--; } else { posX = _pictureWidth / _placeSizeWidth-1; posY++; } if(posY >= _placeSizeHeight) { return; } } } }