From 614075b569eb053323b0c37efc616581e94af607 Mon Sep 17 00:00:00 2001 From: MariaBelkina <89656988623@mail.ru> Date: Fri, 12 Apr 2024 22:19:35 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=B0=203,=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=B4=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=B4=D0=BE=D0=BF=20=D1=86?= =?UTF-8?q?=D0=B2=D0=B5=D1=82=D0=B0=20=D0=B2=20=D0=BA=D1=80=D1=83=D1=82?= =?UTF-8?q?=D0=BE=D0=B9=20=D0=B1=D1=83=D0=BB=D1=8C=D0=B4=D0=BE=D0=B7=D0=B5?= =?UTF-8?q?=D1=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 4 +- .../CarSharingService.cs | 35 -------- .../CollectionGenericObjects/Garage.cs | 84 +++++++++++++++++++ .../MassiveGenericObject.cs | 78 +++++++++++++++-- .../FormBulldozer.Designer.cs | 30 ------- .../FormBulldozerCollection.Designer.cs | 2 + .../FormBulldozerCollection.cs | 22 +++-- 7 files changed, 170 insertions(+), 85 deletions(-) delete mode 100644 ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/CarSharingService.cs create mode 100644 ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/Garage.cs diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/AbstractCompany.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/AbstractCompany.cs index 383d382..302c514 100644 --- a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/AbstractCompany.cs @@ -16,12 +16,12 @@ public abstract class AbstractCompany /// /// Размер места (ширина) /// - protected readonly int _placeSizeWidth = 210; + protected readonly int _placeSizeWidth = 190; /// /// Размер места (высота) /// - protected readonly int _placeSizeHeight = 80; + protected readonly int _placeSizeHeight = 130; /// /// Ширина окна diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/CarSharingService.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/CarSharingService.cs deleted file mode 100644 index 124236c..0000000 --- a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/CarSharingService.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using ProjectBulldozer.Drawnings; - -namespace ProjectBulldozer.CollectionGenericObjects; - -/// -/// Реализация абстрактной компании -/// -public class CarSharingService : AbstractCompany -{ - /// - /// Конструктор - /// - /// - /// - /// - public CarSharingService(int picWidth, int picHeight, ICollectoinGenericObjects collectoin) : base(picWidth, picHeight, collectoin) - { - - } - - protected override void DrawBackground(Graphics g) - { - throw new NotImplementedException(); - } - - protected override void SetObjectsPosition() - { - throw new NotImplementedException(); - } -} diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/Garage.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/Garage.cs new file mode 100644 index 0000000..8583f11 --- /dev/null +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/Garage.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectBulldozer.Drawnings; + +namespace ProjectBulldozer.CollectionGenericObjects; + +/// +/// Реализация абстрактной компании +/// +public class Garage : AbstractCompany +{ + /// + /// Конструктор + /// + /// + /// + /// + public Garage(int picWidth, int picHeight, ICollectoinGenericObjects collectoin) : base(picWidth, picHeight, collectoin) + { + + } + + /// + /// отрисовка парковки + /// + /// + protected override void DrawBackground(Graphics g) + { + int cntVertically = _pictureHeight / _placeSizeHeight; //Колличество мест по вертикали + int cntHorizontally = _pictureWidth / _placeSizeWidth; //Колличество мест по горизонтали + Pen pen = new Pen(Color.FromArgb(0, 0, 0)); + pen.Width = 3; + + for (int i = 0; i < cntHorizontally; i++) + { + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, cntVertically * _placeSizeHeight); + for (int j = 0; j < cntVertically + 1; j++) + { + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, (i + 1) * _placeSizeWidth - 50, j * _placeSizeHeight); + } + } + } + + /// + /// выбор места на парковке + /// + protected override void SetObjectsPosition() + { + //Влево, вверх + int width = _pictureWidth / _placeSizeWidth - 1; + int height = _pictureHeight / _placeSizeHeight - 1; + + int placeHorizontally = width; + int placeVertically = height; + + for (int i = 0; i < (_collection?.Count ?? 0); i++) + { + if (placeVertically < 0) + { + return; + } + if (_collection?.Get(i) != null) + { + _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); + _collection?.Get(i)?.SetPosition(_placeSizeWidth * placeHorizontally + 20, _placeSizeHeight * placeVertically + 20); + } + + if (placeHorizontally > 0) + { + placeHorizontally--; + } + else + { + placeHorizontally = width; + placeVertically--; + } + } + + //throw new NotImplementedException(); + } +} diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/MassiveGenericObject.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/MassiveGenericObject.cs index 57b2d03..22bf179 100644 --- a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/MassiveGenericObject.cs +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/MassiveGenericObject.cs @@ -41,29 +41,89 @@ public class MassiveGenericObject : ICollectoinGenericObjects public T? Get(int position) { - //TODO проверка позиции - return _collection[position]; + //Проверка позиции + if ((position >= 0) && (position < Count)) + { + return _collection[position]; + } + else + { + return null; + } } public bool Insert(T obj) { - //TODO вставка в свободное место набора + //Вставка в свободное место набора + for (int i = 0; i < Count; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return true; + } + } + return false; } public bool Insert(T obj, int position) { - //TODO Проверка позиции - //TODO проверка, что элемент массива по этой позиции пустой, если нет, то ищется свободное место после этой + //Проверка позиции + if ((position < 0) || (position >= Count)) + { + return false; + } + + //Проверка, что элемент массива по этой позиции пустой, если нет, то ищется свободное место после этой //позиции и идёт вставка туда, если нет после, ищем до - //TODO вставка - return false; + if (_collection[position] != null) + { + bool placed = false; + for (int i = position + 1; i < Count; i++) + { + if (_collection[i] == null) + { + position = i; + placed = true; + break; + } + } + + if (placed == false) + { + for (int i = position - 1; i >= 0; i--) + { + if (_collection[i] == null) + { + position = i; + placed = true; + break; + } + } + } + + if (placed == false) + { + return false; + } + } + + //Вставка + _collection[position] = obj; + return true; } public bool Remove(int position) { - //TODO проверка позиции - //TODO удаление объекта из массива, присвоив элементу массива значение null + //Проверка позиции + if ((position < 0) || (position >= Count) || (_collection[position] == null)) + { + return false; + } + + //Удаление объекта из массива, присвоив элементу массива значение null + _collection[position] = null; return true; } } diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs index 3f5f8be..3ababcc 100644 --- a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs @@ -29,12 +29,10 @@ private void InitializeComponent() { pictureBoxBulldozer = new PictureBox(); - ButtonCreateBulldozer = new Button(); buttonRight = new Button(); buttonUp = new Button(); buttonLeft = new Button(); buttonDown = new Button(); - ButtonCreateDozer = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).BeginInit(); @@ -50,18 +48,6 @@ pictureBoxBulldozer.TabIndex = 0; pictureBoxBulldozer.TabStop = false; // - // ButtonCreateBulldozer - // - ButtonCreateBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - ButtonCreateBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); - ButtonCreateBulldozer.Location = new Point(12, 371); - ButtonCreateBulldozer.Name = "ButtonCreateBulldozer"; - ButtonCreateBulldozer.Size = new Size(325, 46); - ButtonCreateBulldozer.TabIndex = 1; - ButtonCreateBulldozer.Text = "Создать крутой бульдозер"; - ButtonCreateBulldozer.UseVisualStyleBackColor = true; - ButtonCreateBulldozer.Click += ButtonCreateBulldozer_Click; - // // buttonRight // buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -110,18 +96,6 @@ buttonDown.UseVisualStyleBackColor = true; buttonDown.Click += ButtonMove_Click; // - // ButtonCreateDozer - // - ButtonCreateDozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - ButtonCreateDozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); - ButtonCreateDozer.Location = new Point(343, 371); - ButtonCreateDozer.Name = "ButtonCreateDozer"; - ButtonCreateDozer.Size = new Size(248, 46); - ButtonCreateDozer.TabIndex = 6; - ButtonCreateDozer.Text = "Создать бульдозер"; - ButtonCreateDozer.UseVisualStyleBackColor = true; - ButtonCreateDozer.Click += ButtonCreateDozer_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -151,12 +125,10 @@ ClientSize = new Size(874, 429); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(ButtonCreateDozer); Controls.Add(buttonDown); Controls.Add(buttonLeft); Controls.Add(buttonUp); Controls.Add(buttonRight); - Controls.Add(ButtonCreateBulldozer); Controls.Add(pictureBoxBulldozer); Name = "FormBulldozer"; Text = "FormBulldozer"; @@ -168,12 +140,10 @@ #endregion private PictureBox pictureBoxBulldozer; - private Button ButtonCreateBulldozer; private Button buttonRight; private Button buttonUp; private Button buttonLeft; private Button buttonDown; - private Button ButtonCreateDozer; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs index 846c232..a9ff02a 100644 --- a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs @@ -76,6 +76,7 @@ buttonRefresh.TabIndex = 3; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; // // buttonGoToCheck // @@ -136,6 +137,7 @@ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(332, 41); comboBoxSelectorCompany.TabIndex = 1; + comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; // // pictureBox // diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs index 9caa62f..b485011 100644 --- a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs @@ -36,7 +36,17 @@ public partial class FormBulldozerCollection : Form /// /// /// - private void ComboBoxSelectorCompany_SelectedIndexChanget(object sender, EventArgs e) + private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new Garage(pictureBox.Width, pictureBox.Height, new MassiveGenericObject()); + break; + } + + } +/* private void ComboBoxSelectorCompany_SelectedIndexChanget(object sender, EventArgs e) { switch (comboBoxSelectorCompany.Text) { @@ -44,7 +54,7 @@ public partial class FormBulldozerCollection : Form _company = new CarSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObject()); break; } - } + }*/ /// /// Добавление обычного бульдозера @@ -101,12 +111,6 @@ public partial class FormBulldozerCollection : Form { MessageBox.Show("Не удалось добавить объект..."); } - /* - _drawningDozer.SetPictureSize(pictureBoxBulldozer.Width, pictureBoxBulldozer.Height); - _drawningDozer.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw();*/ } /// @@ -197,7 +201,7 @@ public partial class FormBulldozerCollection : Form /// private void ButtonRefresh_Click(object sender, EventArgs e) { - if(_company == null) + if (_company == null) { return; }