diff --git a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ShipSharingService.cs b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ShipSharingService.cs index 8f41e1e..76791bc 100644 --- a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ShipSharingService.cs +++ b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ShipSharingService.cs @@ -2,19 +2,52 @@ namespace ProjectContainerShip.CollectionGenericObjects; -public class ShipSharingService : AbstractCompany +public class ShipPortService : AbstractCompany { - public ShipSharingService(int pictureWidth, int pictureHeight, ICollectionGenericObjects collection) : base(pictureWidth, pictureHeight, collection) + public ShipPortService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) { } - protected override void DrawBackgound(Graphics g) { - throw new NotImplementedException(); + // Пристань + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + Pen pen = new(Color.Black, 3); + for (int i = 0; i < width; i++) + { + for (int j = 0; j < height + 1; ++j) + { + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 5, j * _placeSizeHeight); + } + } } protected override void SetObjectsPosition() { - throw new NotImplementedException(); + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + + int curWidth = width - 1; + int curHeight = 0; + + for (int i = 0; i < (_collection?.Count ?? 0); i++) + { + if (_collection.Get(i) != null) + { + _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); + _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 55, curHeight * _placeSizeHeight + 20); + } + if (curWidth > 0) + curWidth--; + else + { + curWidth = width - 1; + curHeight++; + } + if (curHeight > height) + { + return; + } + } } } diff --git a/ProjectContainerShip/ProjectContainerShip/FormShipCollection.cs b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.cs index 06a3498..3e51d56 100644 --- a/ProjectContainerShip/ProjectContainerShip/FormShipCollection.cs +++ b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.cs @@ -30,7 +30,7 @@ public partial class FormShipCollection : Form switch (comboBoxSelectorCompany.Text) { case "Хранилище": - _company = new ShipSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + _company = new ShipPortService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); break; } } @@ -54,10 +54,10 @@ public partial class FormShipCollection : Form drawningShip = new DrawningShip(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); break; case nameof(DrawningContainerShip): + // TODO вызов диалогового окна для выбора цвета (made) drawningShip = new DrawningContainerShip(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + GetColor(random), GetColor(random), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; default: return;