From 2206e2523398c50e8e7677d730dd7fc939b024d2 Mon Sep 17 00:00:00 2001 From: Anya Date: Mon, 20 May 2024 14:22:37 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B04?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionGenericObject/CollectionType.cs | 25 ++ .../ListGenericObjects.cs | 74 +++++ .../StorageCollection.cs | 80 ++++++ lab_0/FormSimpleBusCollection.Designer.cs | 258 +++++++++++++----- lab_0/FormSimpleBusCollection.cs | 184 ++++++++++--- lab_0/MovementStrategy/MoveToBorder.cs | 11 +- 6 files changed, 528 insertions(+), 104 deletions(-) create mode 100644 lab_0/CollectionGenericObject/CollectionType.cs create mode 100644 lab_0/CollectionGenericObject/ListGenericObjects.cs create mode 100644 lab_0/CollectionGenericObject/StorageCollection.cs diff --git a/lab_0/CollectionGenericObject/CollectionType.cs b/lab_0/CollectionGenericObject/CollectionType.cs new file mode 100644 index 0000000..a47150a --- /dev/null +++ b/lab_0/CollectionGenericObject/CollectionType.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectBus.CollectionGenericObject; + +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + + /// + /// Массив + /// + Massive = 1, + + /// + /// Список + /// + List = 2 +} diff --git a/lab_0/CollectionGenericObject/ListGenericObjects.cs b/lab_0/CollectionGenericObject/ListGenericObjects.cs new file mode 100644 index 0000000..2fbfbdb --- /dev/null +++ b/lab_0/CollectionGenericObject/ListGenericObjects.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectBus.CollectionGenericObject; + +public class ListGenericObjects : ICollectionGenericObjects + where T : class +{ + /// + /// Список объектов, которые храним + /// + private readonly List _collection; + + /// + /// Максимально допустимое число объектов в списке + /// + private int _maxCount; + + public int Count => _collection.Count; + + public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } } + + /// + /// Конструктор + /// + public ListGenericObjects() + { + _collection = new(); + } + + public T? Get(int position) + { + + if (position < 0 || position > _collection.Count - 1) + { + return null; + } + return _collection[position]; + } + + public int Insert(T obj) + { + if (_collection.Count + 1 > _maxCount) { return 0; } + _collection.Add(obj); + + return 1; + } + + public int Insert(T obj, int position) + { + if (_collection.Count + 1 < _maxCount) { return 0; } + if (position > _collection.Count || position < 0) + { + return 0; + } + _collection.Insert(position, obj); + return 1; + } + + public T Remove(int position) + { + if (position > _collection.Count || position < 0) + { + return null; + } + T temp = _collection[position]; + _collection.RemoveAt(position); + return temp; + } +} + diff --git a/lab_0/CollectionGenericObject/StorageCollection.cs b/lab_0/CollectionGenericObject/StorageCollection.cs new file mode 100644 index 0000000..bec1f83 --- /dev/null +++ b/lab_0/CollectionGenericObject/StorageCollection.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectBus.CollectionGenericObject; + +/// +/// Класс-хранилище коллекций +/// +/// + +public class StorageCollection + where T : class +{/// + /// Словарь (хранилище) с коллекциями + /// + readonly Dictionary> _storages; + + /// + /// Возвращение списка названий коллекций + /// + public List Keys => _storages.Keys.ToList(); + + /// + /// Конструктор + /// + public StorageCollection() + { + _storages = new Dictionary>(); + } + + /// + /// Добавление коллекции в хранилище + /// + /// Название коллекции + /// тип коллекции + public void AddCollection(string name, CollectionType collectionType) + { + if (name == null || _storages.ContainsKey(name)) { return; } + switch (collectionType) + + { + case CollectionType.None: + return; + case CollectionType.Massive: + _storages.Add(name, new MassiveGenericObjects { }); + return; + case CollectionType.List: + _storages.Add(name, new ListGenericObjects { }); + return; + } + + } + + /// + /// Удаление коллекции + /// + /// Название коллекции + public void DelCollection(string name) + { + if (name == null || !_storages.ContainsKey(name)) { return; } + _storages.Remove(name); + } + + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectionGenericObjects? this[string name] + { + get + { + if (name == null || !_storages.ContainsKey(name)) { return null; } + return _storages[name]; + } + } +} diff --git a/lab_0/FormSimpleBusCollection.Designer.cs b/lab_0/FormSimpleBusCollection.Designer.cs index 90730ea..bb33b9e 100644 --- a/lab_0/FormSimpleBusCollection.Designer.cs +++ b/lab_0/FormSimpleBusCollection.Designer.cs @@ -29,83 +29,62 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); - buttonRefresh = new Button(); - buttonGoToCheck = new Button(); - buttonDelBus = new Button(); - maskedTextBox = new MaskedTextBox(); + panelCompanyTools = new Panel(); buttonAddBus = new Button(); buttonAddSimpleBus = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonRefresh = new Button(); + buttonDelBus = new Button(); + buttonGoToCheck = new Button(); + panelStorage = new Panel(); + buttonCollectionDel = new Button(); + buttonCreateCompany = new Button(); + listBoxCollection = new ListBox(); + buttonCollectionAdd = new Button(); comboBoxSelectorCompany = new ComboBox(); + radioButtonList = new RadioButton(); + radioButtonMassive = new RadioButton(); + textBoxCollectionName = new TextBox(); + labelCollectionName = new Label(); pictureBox = new PictureBox(); groupBoxTools.SuspendLayout(); + panelCompanyTools.SuspendLayout(); + panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); SuspendLayout(); // // groupBoxTools // - groupBoxTools.Controls.Add(buttonRefresh); - groupBoxTools.Controls.Add(buttonGoToCheck); - groupBoxTools.Controls.Add(buttonDelBus); - groupBoxTools.Controls.Add(maskedTextBox); - groupBoxTools.Controls.Add(buttonAddBus); - groupBoxTools.Controls.Add(buttonAddSimpleBus); - groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Controls.Add(panelCompanyTools); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(1063, 0); + groupBoxTools.Location = new Point(1018, 0); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(333, 962); + groupBoxTools.Size = new Size(356, 1058); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // - // buttonRefresh + // panelCompanyTools // - buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(6, 731); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(315, 84); - buttonRefresh.TabIndex = 7; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRefresh_Click_1; - // - // buttonGoToCheck - // - buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(6, 565); - buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(315, 84); - buttonGoToCheck.TabIndex = 6; - buttonGoToCheck.Text = "Передать на тесты"; - buttonGoToCheck.UseVisualStyleBackColor = true; - buttonGoToCheck.Click += ButtonGoToCheck_Click_1; - // - // buttonDelBus - // - buttonDelBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonDelBus.Location = new Point(6, 416); - buttonDelBus.Name = "buttonDelBus"; - buttonDelBus.Size = new Size(315, 84); - buttonDelBus.TabIndex = 5; - buttonDelBus.Text = "Удалить автобус"; - buttonDelBus.UseVisualStyleBackColor = true; - - // - // maskedTextBox - // - maskedTextBox.Location = new Point(6, 355); - maskedTextBox.Mask = "00"; - maskedTextBox.Name = "maskedTextBox"; - maskedTextBox.Size = new Size(315, 39); - maskedTextBox.TabIndex = 4; - maskedTextBox.ValidatingType = typeof(int); + panelCompanyTools.Controls.Add(buttonAddBus); + panelCompanyTools.Controls.Add(buttonAddSimpleBus); + panelCompanyTools.Controls.Add(maskedTextBox); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonDelBus); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Dock = DockStyle.Bottom; + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 543); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(350, 512); + panelCompanyTools.TabIndex = 8; // // buttonAddBus // - buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddBus.Location = new Point(6, 225); + buttonAddBus.Location = new Point(6, 77); buttonAddBus.Name = "buttonAddBus"; - buttonAddBus.Size = new Size(315, 84); + buttonAddBus.Size = new Size(321, 76); buttonAddBus.TabIndex = 2; buttonAddBus.Text = "Добавление автобуса с доп. отсеком"; buttonAddBus.UseVisualStyleBackColor = true; @@ -113,51 +92,190 @@ // // buttonAddSimpleBus // - buttonAddSimpleBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddSimpleBus.Location = new Point(6, 118); + buttonAddSimpleBus.Location = new Point(9, 3); buttonAddSimpleBus.Name = "buttonAddSimpleBus"; - buttonAddSimpleBus.Size = new Size(315, 84); + buttonAddSimpleBus.Size = new Size(318, 59); buttonAddSimpleBus.TabIndex = 1; buttonAddSimpleBus.Text = "Добавление автобуса"; buttonAddSimpleBus.UseVisualStyleBackColor = true; buttonAddSimpleBus.Click += ButtonAddSimpleBus_Click; // + // maskedTextBox + // + maskedTextBox.Location = new Point(15, 173); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(306, 39); + maskedTextBox.TabIndex = 0; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(6, 366); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(328, 49); + buttonRefresh.TabIndex = 7; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonDelBus + // + buttonDelBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonDelBus.Location = new Point(6, 231); + buttonDelBus.Name = "buttonDelBus"; + buttonDelBus.Size = new Size(321, 46); + buttonDelBus.TabIndex = 5; + buttonDelBus.Text = "Удалить автобус"; + buttonDelBus.UseVisualStyleBackColor = true; + buttonDelBus.Click += buttonDelBus_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(6, 293); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(328, 58); + buttonGoToCheck.TabIndex = 6; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // panelStorage + // + panelStorage.Controls.Add(buttonCollectionDel); + panelStorage.Controls.Add(buttonCreateCompany); + panelStorage.Controls.Add(listBoxCollection); + panelStorage.Controls.Add(buttonCollectionAdd); + panelStorage.Controls.Add(comboBoxSelectorCompany); + panelStorage.Controls.Add(radioButtonList); + panelStorage.Controls.Add(radioButtonMassive); + panelStorage.Controls.Add(textBoxCollectionName); + panelStorage.Controls.Add(labelCollectionName); + panelStorage.Dock = DockStyle.Top; + panelStorage.Location = new Point(3, 35); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(350, 518); + panelStorage.TabIndex = 8; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(3, 348); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(324, 46); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += ButtonCollectionDel_Click; + // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(6, 456); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(324, 46); + buttonCreateCompany.TabIndex = 9; + buttonCreateCompany.Text = "Создать компанию"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += ButtonCreateCompany_Click; + // + // listBoxCollection + // + listBoxCollection.ItemHeight = 32; + listBoxCollection.Location = new Point(0, 231); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(324, 100); + listBoxCollection.TabIndex = 7; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(0, 166); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(324, 46); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += ButtonCollectionAdd_Click; + // // comboBoxSelectorCompany // comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "хранилище" }); - comboBoxSelectorCompany.Location = new Point(6, 47); + comboBoxSelectorCompany.Location = new Point(0, 400); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; - comboBoxSelectorCompany.Size = new Size(315, 40); + comboBoxSelectorCompany.Size = new Size(344, 40); comboBoxSelectorCompany.TabIndex = 0; comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(181, 114); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(125, 36); + radioButtonList.TabIndex = 3; + radioButtonList.TabStop = true; + radioButtonList.Text = "Список"; + radioButtonList.UseVisualStyleBackColor = true; + // + // radioButtonMassive + // + radioButtonMassive.AutoSize = true; + radioButtonMassive.Location = new Point(13, 114); + radioButtonMassive.Name = "radioButtonMassive"; + radioButtonMassive.Size = new Size(128, 36); + radioButtonMassive.TabIndex = 2; + radioButtonMassive.TabStop = true; + radioButtonMassive.Text = "Массив"; + radioButtonMassive.UseVisualStyleBackColor = true; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(3, 60); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(318, 39); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(34, 25); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(251, 32); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции:"; + // // pictureBox // pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(1063, 962); - pictureBox.TabIndex = 3; + pictureBox.Size = new Size(1018, 1058); + pictureBox.TabIndex = 0; pictureBox.TabStop = false; // // FormSimpleBusCollection // AutoScaleDimensions = new SizeF(13F, 32F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1396, 962); + ClientSize = new Size(1374, 1058); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Name = "FormSimpleBusCollection"; Text = "Коллекция автобусов"; groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ResumeLayout(false); } + + #endregion @@ -170,5 +288,15 @@ private PictureBox pictureBox; private Button buttonRefresh; private Button buttonGoToCheck; + private Panel panelStorage; + private Label labelCollectionName; + private TextBox textBoxCollectionName; + private RadioButton radioButtonList; + private RadioButton radioButtonMassive; + private Button buttonCollectionDel; + private ListBox listBoxCollection; + private Button buttonCollectionAdd; + private Button buttonCreateCompany; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/lab_0/FormSimpleBusCollection.cs b/lab_0/FormSimpleBusCollection.cs index 31552a4..58e7f6a 100644 --- a/lab_0/FormSimpleBusCollection.cs +++ b/lab_0/FormSimpleBusCollection.cs @@ -6,12 +6,30 @@ namespace ProjectBus; public partial class FormSimpleBusCollection : Form { + /// + /// Хранилише коллекций + /// + private readonly StorageCollection _storageCollection; + + /// + /// Компания + /// private AbstractCompany? _company = null; + + /// + /// Конструктор + /// public FormSimpleBusCollection() { InitializeComponent(); + _storageCollection = new(); } + /// + /// Выбор компании + /// + /// + /// private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { switch (comboBoxSelectorCompany.Text) @@ -22,6 +40,11 @@ public partial class FormSimpleBusCollection : Form } } + /// + /// Добавление обычного автомобиля + /// + /// + /// private void ButtonAddSimpleBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSimpleBus)); /// @@ -35,35 +58,6 @@ public partial class FormSimpleBusCollection : Form /// Создание объекта класса-перемещения /// /// Тип создаваемого объекта - - /// - /// Получение цвета - /// - /// Генератор случайных чисел - /// - - - /// - /// Удаление объекта - /// - /// - /// - - - /// - /// Передача объекта в другую форму - /// - /// - /// - - - /// - /// Перерисовка коллекции - /// - /// - /// - - private void CreateObject(string type) { if (_company == null) @@ -98,6 +92,12 @@ public partial class FormSimpleBusCollection : Form _ = MessageBox.Show(drawningSimpleBus.ToString()); } } + + /// + /// Получение цвета + /// + /// Генератор случайных чисел + /// private static Color GetColor(Random random) { Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); @@ -110,8 +110,12 @@ public partial class FormSimpleBusCollection : Form return color; } - - private void ButtonDelBus_Click_1(object sender, EventArgs e) + /// + /// Удаление объекта + /// + /// + /// + private void buttonDelBus_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) { @@ -136,7 +140,12 @@ public partial class FormSimpleBusCollection : Form } - private void ButtonRefresh_Click_1(object sender, EventArgs e) + /// + /// Перерисовка коллекции + /// + /// + /// + private void ButtonRefresh_Click(object sender, EventArgs e) { if (_company == null) { @@ -147,7 +156,12 @@ public partial class FormSimpleBusCollection : Form } - private void ButtonGoToCheck_Click_1(object sender, EventArgs e) + /// + /// Передача объекта в другую форму + /// + /// + /// + private void ButtonGoToCheck_Click(object sender, EventArgs e) { if (_company == null) { @@ -178,5 +192,109 @@ public partial class FormSimpleBusCollection : Form form.ShowDialog(); } + + /// + /// Добавление коллекции + /// + /// + /// + private void ButtonCollectionAdd_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked)) + { + MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + CollectionType collectionType = CollectionType.None; + if (radioButtonMassive.Checked) + { + collectionType = CollectionType.Massive; + } + else if (radioButtonList.Checked) + { + collectionType = CollectionType.List; + } + + _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType); + RerfreshListBoxItems(); + + } + + /// + /// Удаление коллекции + /// + /// + /// + private void ButtonCollectionDel_Click(object sender, EventArgs e) + { + if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) + { + MessageBox.Show("Коллекция не выбрана"); + return; + } + if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); + RerfreshListBoxItems(); + + } + + /// + /// Обновление списка в listBoxCollection + /// + private void RerfreshListBoxItems() + { + listBoxCollection.Items.Clear(); + for (int i = 0; i < _storageCollection.Keys?.Count; ++i) + { + string? colName = _storageCollection.Keys?[i]; + if (!string.IsNullOrEmpty(colName)) + { + listBoxCollection.Items.Add(colName); + } + } + + } + + /// + /// Создание компании + /// + /// + /// + private void ButtonCreateCompany_Click(object sender, EventArgs e) + { + if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) + { + MessageBox.Show("Коллекция не выбрана"); + return; + } + + ICollectionGenericObjects? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty]; + if (collection == null) + { + MessageBox.Show("Коллекция не проинициализирована"); + return; + } + + switch (comboBoxSelectorCompany.Text) + { + case "хранилище": + _company = new BusStation(pictureBox.Width, pictureBox.Height, collection); + break; + } + + panelCompanyTools.Enabled = true; + RerfreshListBoxItems(); + } + + + } + + + + diff --git a/lab_0/MovementStrategy/MoveToBorder.cs b/lab_0/MovementStrategy/MoveToBorder.cs index c273b21..6323474 100644 --- a/lab_0/MovementStrategy/MoveToBorder.cs +++ b/lab_0/MovementStrategy/MoveToBorder.cs @@ -7,8 +7,6 @@ using System.Threading.Tasks; namespace ProjectBus.MovementStrategy; public class MoveToBorder : AbstractStrategy { - - protected override bool IsTargetDestinaion() { ObjectParameters? objParams = GetObjectParameters; @@ -16,11 +14,12 @@ public class MoveToBorder : AbstractStrategy { return false; } - return objParams.RightBorder - GetStep() <= FieldWidth - && objParams.RightBorder + GetStep() >= FieldWidth && - objParams.DownBorder - GetStep() <= FieldHeight - && objParams.DownBorder + GetStep() >= FieldHeight; + return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth + && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth && + objParams.ObjectMiddleVertical - GetStep() <= FieldHeight + && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight; } + protected override void MoveToTarget() { ObjectParameters? objParams = GetObjectParameters;