From 39ac5fc6aadec2a7ce3e94d43553f4a1d5cce23d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Sat, 4 Nov 2023 20:53:12 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D0=BD=D0=B0=D0=B4=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D0=B9=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/BoatsGenericCollection.cs | 25 +++--- Sailboat/Sailboat/BoatsGenericStorage.cs | 84 +++++++++++++++++++++ Sailboat/Sailboat/SetGeneric.cs | 45 +++++++++-- 3 files changed, 131 insertions(+), 23 deletions(-) create mode 100644 Sailboat/Sailboat/BoatsGenericStorage.cs diff --git a/Sailboat/Sailboat/BoatsGenericCollection.cs b/Sailboat/Sailboat/BoatsGenericCollection.cs index 37a71b4..381661f 100644 --- a/Sailboat/Sailboat/BoatsGenericCollection.cs +++ b/Sailboat/Sailboat/BoatsGenericCollection.cs @@ -6,9 +6,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using Sailboat.DrawingObjects; -using Sailboat.MovementStrategy; - namespace Sailboat.Generics { /// @@ -59,8 +56,7 @@ namespace Sailboat.Generics /// /// /// - public static int operator +(BoatsGenericCollection collect, T? - obj) + public static int operator +(BoatsGenericCollection collect, T? obj) { if (obj == null) { @@ -74,16 +70,16 @@ namespace Sailboat.Generics /// /// /// - public static bool operator -(BoatsGenericCollection collect, int - pos) + public static T? operator -(BoatsGenericCollection collect, int pos) { - T? obj = collect._collection.Get(pos); + T? obj = collect._collection[pos]; if (obj != null) { collect._collection.Remove(pos); } - return false; + return obj; } + /// /// Получение объекта IMoveableObject /// @@ -91,7 +87,7 @@ namespace Sailboat.Generics /// public U? GetU(int pos) { - return (U?)_collection.Get(pos)?.GetMoveableObject; + return (U?)_collection[pos]?.GetMoveableObject; } /// /// Вывод всего набора объектов @@ -131,18 +127,17 @@ namespace Sailboat.Generics /// private void DrawObjects(Graphics g) { - for (int i = 0; i < _collection.Count; i++) + int i = 0; + foreach (var boat in _collection.GetBoats()) { - DrawingBoat boat = _collection.Get(i); - if (boat != null) { int width = _pictureWidth / _placeSizeWidth; - boat.SetPosition(i % width * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight); + boat.SetPosition(i % width * _placeSizeWidth, _pictureHeight - _pictureHeight % _placeSizeHeight - (i / width + 1) * _placeSizeHeight); boat.DrawTransport(g); } + i++; } } - } } diff --git a/Sailboat/Sailboat/BoatsGenericStorage.cs b/Sailboat/Sailboat/BoatsGenericStorage.cs new file mode 100644 index 0000000..8dd5aaa --- /dev/null +++ b/Sailboat/Sailboat/BoatsGenericStorage.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Sailboat.DrawingObjects; +using Sailboat.MovementStrategy; + +namespace Sailboat.Generics +{ + internal class BoatsGenericStorage + { + /// + /// Словарь (хранилище) + /// + readonly Dictionary> _boatStorages; + /// + /// Возвращение списка названий наборов + /// + public List Keys => _boatStorages.Keys.ToList(); + /// + /// Ширина окна отрисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна отрисовки + /// + private readonly int _pictureHeight; + /// + /// Конструктор + /// + /// + /// + public BoatsGenericStorage(int pictureWidth, int pictureHeight) + { + _boatStorages = new Dictionary>(); + _pictureWidth = pictureWidth; + _pictureHeight = pictureHeight; + } + /// + /// Добавление набора + /// + /// Название набора + public void AddSet(string name) + { + if (_boatStorages.ContainsKey(name)) + { + return; + } + _boatStorages[name] = new BoatsGenericCollection(_pictureWidth, _pictureHeight); + } + /// + /// Удаление набора + /// + /// Название набора + public void DelSet(string name) + { + if (!_boatStorages.ContainsKey(name)) + { + return; + } + _boatStorages.Remove(name); + } + /// + /// Доступ к набору + /// + /// + /// + public BoatsGenericCollection? + this[string ind] + { + get + { + if (_boatStorages.ContainsKey(ind)) + { + return _boatStorages[ind]; + } + return null; + } + } + } +} diff --git a/Sailboat/Sailboat/SetGeneric.cs b/Sailboat/Sailboat/SetGeneric.cs index 9fe38ca..2a67125 100644 --- a/Sailboat/Sailboat/SetGeneric.cs +++ b/Sailboat/Sailboat/SetGeneric.cs @@ -4,25 +4,31 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +//пофиксить чота namespace Sailboat.Generics { internal class SetGeneric where T : class { /// - /// Массив объектов, которые храним + /// Список объектов, которые храним /// - private readonly T?[] _places; + private readonly List _places; /// /// Количество объектов в массиве /// - public int Count => _places.Length; + public int Count => _places.Count; + /// + /// Максимальное количество объектов в списке + /// + private readonly int _maxCount; /// /// Конструктор /// /// public SetGeneric(int count) { - _places = new T?[count]; + _maxCount = count; + _places = new List(count); } /// /// Добавление объекта в набор @@ -90,13 +96,36 @@ namespace Sailboat.Generics /// /// /// - public T? Get(int position) + public T? this[int position] { - if (position < 0 || position >= Count) + get { - return null; + if (!(position >= 0 && position < Count)) + return null; + return _places[position]; + } + set + { + if (!(position >= 0 && position < Count && _places.Count < _maxCount)) + return; + _places.Insert(position, value); + return; + } + } + /// + /// Проход по списку + /// + /// + public IEnumerable GetBoats(int? maxBoats = null) + { + for (int i = 0; i < _places.Count; ++i) + { + yield return _places[i]; + if (maxBoats.HasValue && i == maxBoats.Value) + { + yield break; + } } - return _places[position]; } } } -- 2.25.1 From 32f16a9ebdbcc4474eecc4c3365c433fc5bcaff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Sat, 4 Nov 2023 22:34:06 +0400 Subject: [PATCH 2/5] =?UTF-8?q?=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/BoatsGenericCollection.cs | 6 +- .../Sailboat/FormBoatCollection.Designer.cs | 77 +++++++++++-- Sailboat/Sailboat/FormBoatCollection.cs | 102 ++++++++++++++++-- Sailboat/Sailboat/SetGeneric.cs | 41 ++----- 4 files changed, 177 insertions(+), 49 deletions(-) diff --git a/Sailboat/Sailboat/BoatsGenericCollection.cs b/Sailboat/Sailboat/BoatsGenericCollection.cs index 381661f..160b983 100644 --- a/Sailboat/Sailboat/BoatsGenericCollection.cs +++ b/Sailboat/Sailboat/BoatsGenericCollection.cs @@ -56,13 +56,13 @@ namespace Sailboat.Generics /// /// /// - public static int operator +(BoatsGenericCollection collect, T? obj) + public static bool operator +(BoatsGenericCollection collect, T? obj) { if (obj == null) { - return -1; + return false; } - return collect._collection.Insert(obj); + return collect?._collection.Insert(obj) ?? false; } /// /// Перегрузка оператора вычитания diff --git a/Sailboat/Sailboat/FormBoatCollection.Designer.cs b/Sailboat/Sailboat/FormBoatCollection.Designer.cs index a2f0fd8..a3be7c3 100644 --- a/Sailboat/Sailboat/FormBoatCollection.Designer.cs +++ b/Sailboat/Sailboat/FormBoatCollection.Designer.cs @@ -30,19 +30,25 @@ { this.pictureBoxCollection = new System.Windows.Forms.PictureBox(); this.panelTools = new System.Windows.Forms.Panel(); + this.panelCollection = new System.Windows.Forms.Panel(); + this.buttonDelObject = new System.Windows.Forms.Button(); + this.listBoxStorages = new System.Windows.Forms.ListBox(); + this.buttonAddObject = new System.Windows.Forms.Button(); + this.textBoxStorageName = new System.Windows.Forms.TextBox(); this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox(); this.buttonRefreshCollection = new System.Windows.Forms.Button(); this.buttonRemoveBoat = new System.Windows.Forms.Button(); this.buttonAddBoat = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit(); this.panelTools.SuspendLayout(); + this.panelCollection.SuspendLayout(); this.SuspendLayout(); // // pictureBoxCollection // this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0); this.pictureBoxCollection.Name = "pictureBoxCollection"; - this.pictureBoxCollection.Size = new System.Drawing.Size(750, 450); + this.pictureBoxCollection.Size = new System.Drawing.Size(750, 600); this.pictureBoxCollection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBoxCollection.TabIndex = 0; this.pictureBoxCollection.TabStop = false; @@ -50,25 +56,75 @@ // panelTools // this.panelTools.BackColor = System.Drawing.SystemColors.ScrollBar; + this.panelTools.Controls.Add(this.panelCollection); this.panelTools.Controls.Add(this.maskedTextBoxNumber); this.panelTools.Controls.Add(this.buttonRefreshCollection); this.panelTools.Controls.Add(this.buttonRemoveBoat); this.panelTools.Controls.Add(this.buttonAddBoat); this.panelTools.Location = new System.Drawing.Point(756, 12); this.panelTools.Name = "panelTools"; - this.panelTools.Size = new System.Drawing.Size(209, 426); + this.panelTools.Size = new System.Drawing.Size(209, 588); this.panelTools.TabIndex = 1; // + // panelCollection + // + this.panelCollection.BackColor = System.Drawing.SystemColors.AppWorkspace; + this.panelCollection.Controls.Add(this.buttonDelObject); + this.panelCollection.Controls.Add(this.listBoxStorages); + this.panelCollection.Controls.Add(this.buttonAddObject); + this.panelCollection.Controls.Add(this.textBoxStorageName); + this.panelCollection.Location = new System.Drawing.Point(16, 15); + this.panelCollection.Name = "panelCollection"; + this.panelCollection.Size = new System.Drawing.Size(181, 287); + this.panelCollection.TabIndex = 4; + // + // buttonDelObject + // + this.buttonDelObject.Location = new System.Drawing.Point(12, 230); + this.buttonDelObject.Name = "buttonDelObject"; + this.buttonDelObject.Size = new System.Drawing.Size(154, 34); + this.buttonDelObject.TabIndex = 5; + this.buttonDelObject.Text = "Удалить набор"; + this.buttonDelObject.UseVisualStyleBackColor = true; + this.buttonDelObject.Click += new System.EventHandler(this.buttonDelObject_Click); + // + // listBoxStorages + // + this.listBoxStorages.FormattingEnabled = true; + this.listBoxStorages.ItemHeight = 20; + this.listBoxStorages.Location = new System.Drawing.Point(12, 102); + this.listBoxStorages.Name = "listBoxStorages"; + this.listBoxStorages.Size = new System.Drawing.Size(154, 104); + this.listBoxStorages.TabIndex = 6; + this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged); + // + // buttonAddObject + // + this.buttonAddObject.Location = new System.Drawing.Point(12, 62); + this.buttonAddObject.Name = "buttonAddObject"; + this.buttonAddObject.Size = new System.Drawing.Size(154, 34); + this.buttonAddObject.TabIndex = 5; + this.buttonAddObject.Text = "Добавить набор"; + this.buttonAddObject.UseVisualStyleBackColor = true; + this.buttonAddObject.Click += new System.EventHandler(this.buttonAddObject_Click); + // + // textBoxStorageName + // + this.textBoxStorageName.Location = new System.Drawing.Point(29, 29); + this.textBoxStorageName.Name = "textBoxStorageName"; + this.textBoxStorageName.Size = new System.Drawing.Size(125, 27); + this.textBoxStorageName.TabIndex = 0; + // // maskedTextBoxNumber // - this.maskedTextBoxNumber.Location = new System.Drawing.Point(40, 87); + this.maskedTextBoxNumber.Location = new System.Drawing.Point(45, 416); this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; this.maskedTextBoxNumber.Size = new System.Drawing.Size(125, 27); this.maskedTextBoxNumber.TabIndex = 3; // // buttonRefreshCollection // - this.buttonRefreshCollection.Location = new System.Drawing.Point(16, 210); + this.buttonRefreshCollection.Location = new System.Drawing.Point(16, 531); this.buttonRefreshCollection.Name = "buttonRefreshCollection"; this.buttonRefreshCollection.Size = new System.Drawing.Size(180, 34); this.buttonRefreshCollection.TabIndex = 2; @@ -78,7 +134,7 @@ // // buttonRemoveBoat // - this.buttonRemoveBoat.Location = new System.Drawing.Point(16, 159); + this.buttonRemoveBoat.Location = new System.Drawing.Point(17, 469); this.buttonRemoveBoat.Name = "buttonRemoveBoat"; this.buttonRemoveBoat.Size = new System.Drawing.Size(180, 34); this.buttonRemoveBoat.TabIndex = 1; @@ -88,7 +144,7 @@ // // buttonAddBoat // - this.buttonAddBoat.Location = new System.Drawing.Point(16, 14); + this.buttonAddBoat.Location = new System.Drawing.Point(16, 339); this.buttonAddBoat.Name = "buttonAddBoat"; this.buttonAddBoat.Size = new System.Drawing.Size(180, 34); this.buttonAddBoat.TabIndex = 0; @@ -100,7 +156,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(969, 450); + this.ClientSize = new System.Drawing.Size(969, 604); this.Controls.Add(this.panelTools); this.Controls.Add(this.pictureBoxCollection); this.Name = "FormBoatCollection"; @@ -108,6 +164,8 @@ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit(); this.panelTools.ResumeLayout(false); this.panelTools.PerformLayout(); + this.panelCollection.ResumeLayout(false); + this.panelCollection.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -121,5 +179,10 @@ private Button buttonRemoveBoat; private Button buttonAddBoat; private MaskedTextBox maskedTextBoxNumber; + private Panel panelCollection; + private Button buttonDelObject; + private ListBox listBoxStorages; + private Button buttonAddObject; + private TextBox textBoxStorageName; } } \ No newline at end of file diff --git a/Sailboat/Sailboat/FormBoatCollection.cs b/Sailboat/Sailboat/FormBoatCollection.cs index 30dd6af..23c29c1 100644 --- a/Sailboat/Sailboat/FormBoatCollection.cs +++ b/Sailboat/Sailboat/FormBoatCollection.cs @@ -17,22 +17,54 @@ namespace Sailboat { public partial class FormBoatCollection : Form { - private readonly BoatsGenericCollection _boats; + private readonly BoatsGenericStorage _storage; public FormBoatCollection() { InitializeComponent(); - _boats = new BoatsGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + _storage = new BoatsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height); + + } + + private void ReloadObjects() + { + int index = listBoxStorages.SelectedIndex; + listBoxStorages.Items.Clear(); + for (int i = 0; i < _storage.Keys.Count; i++) + { + listBoxStorages.Items.Add(_storage.Keys[i]); + } + if (listBoxStorages.Items.Count > 0 && (index == -1 || index + >= listBoxStorages.Items.Count)) + { + listBoxStorages.SelectedIndex = 0; + } + else if (listBoxStorages.Items.Count > 0 && index > -1 && + index < listBoxStorages.Items.Count) + { + listBoxStorages.SelectedIndex = index; + } } private void buttonAddBoat_Click(object sender, EventArgs e) { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? + string.Empty]; + if (obj == null) + { + return; + } FormSailboat form = new(); if (form.ShowDialog() == DialogResult.OK) { - if (_boats + form.SelectedBoat != -1) + //вот здесь лажа какая то + if (obj + form.SelectedBoat) { MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = _boats.ShowBoats(); + pictureBoxCollection.Image = obj.ShowBoats(); } else { @@ -43,15 +75,26 @@ namespace Sailboat private void buttonRemoveBoat_Click(object sender, EventArgs e) { - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? + string.Empty]; + if (obj == null) + { + return; + } + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int pos = Convert.ToInt32(maskedTextBoxNumber.Text); - if (_boats - pos != null) + if (obj - pos != null) { MessageBox.Show("Объект удален"); - pictureBoxCollection.Image = _boats.ShowBoats(); + pictureBoxCollection.Image = obj.ShowBoats(); } else { @@ -62,7 +105,50 @@ namespace Sailboat private void buttonRefreshCollection_Click(object sender, EventArgs e) { - pictureBoxCollection.Image = _boats.ShowBoats(); + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? + string.Empty]; + if (obj == null) + { + return; + } + pictureBoxCollection.Image = obj.ShowBoats(); + + } + + private void buttonAddObject_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxStorageName.Text)) + { + MessageBox.Show("Не все данные заполнены", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _storage.AddSet(textBoxStorageName.Text); + ReloadObjects(); + } + + private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e) + { + pictureBoxCollection.Image = + _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowBoats(); + } + + private void buttonDelObject_Click(object sender, EventArgs e) + { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + if (MessageBox.Show($"Удалить объект { listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + _storage.DelSet(listBoxStorages.SelectedItem.ToString() + ?? string.Empty); + ReloadObjects(); + } } } } diff --git a/Sailboat/Sailboat/SetGeneric.cs b/Sailboat/Sailboat/SetGeneric.cs index 2a67125..2c62ce4 100644 --- a/Sailboat/Sailboat/SetGeneric.cs +++ b/Sailboat/Sailboat/SetGeneric.cs @@ -35,9 +35,12 @@ namespace Sailboat.Generics /// /// Добавляемая лодка /// - public int Insert(T boat) + public bool Insert(T boat) { - return Insert(boat, 0); + if (_places.Count == _maxCount) + return false; + Insert(boat, 0); + return true; } /// /// Добавление объекта в набор на конкретную позицию @@ -45,36 +48,12 @@ namespace Sailboat.Generics /// Добавляемая лодка /// Позиция /// - public int Insert(T boat, int position) + public bool Insert(T boat, int position) { - int nullIndex = -1, i; - - if (position < 0 || position >= Count) - { - return -1; - } - - for (i = position; i < Count; i++) - { - if (_places[i] == null) - { - nullIndex = i; - break; - } - } - - if (nullIndex < 0) - { - return -1; - } - - for (i = nullIndex; i > position; i--) - { - _places[i] = _places[i - 1]; - } - - _places[position] = boat; - return position; + if (!(position >= 0 && position <= Count && _places.Count < _maxCount)) + return false; + _places.Insert(position, boat); + return true; } /// /// Удаление объекта из набора с конкретной позиции -- 2.25.1 From dc179c572aafdcd98d7da8be7ff3c7fc05a155a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Sun, 5 Nov 2023 21:13:18 +0400 Subject: [PATCH 3/5] =?UTF-8?q?=D0=B5=D1=89=D0=B5=20=D1=87=D1=83=D1=82?= =?UTF-8?q?=D1=8C=20=D1=87=D1=83=D1=82=D1=8C=20=D0=B8=20=D0=BB=D0=B0=D0=B1?= =?UTF-8?q?=D0=B0=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/FormBoatCollection.cs | 1 - Sailboat/Sailboat/SetGeneric.cs | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Sailboat/Sailboat/FormBoatCollection.cs b/Sailboat/Sailboat/FormBoatCollection.cs index 23c29c1..8894ff4 100644 --- a/Sailboat/Sailboat/FormBoatCollection.cs +++ b/Sailboat/Sailboat/FormBoatCollection.cs @@ -60,7 +60,6 @@ namespace Sailboat FormSailboat form = new(); if (form.ShowDialog() == DialogResult.OK) { - //вот здесь лажа какая то if (obj + form.SelectedBoat) { MessageBox.Show("Объект добавлен"); diff --git a/Sailboat/Sailboat/SetGeneric.cs b/Sailboat/Sailboat/SetGeneric.cs index 2c62ce4..95a2392 100644 --- a/Sailboat/Sailboat/SetGeneric.cs +++ b/Sailboat/Sailboat/SetGeneric.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -//пофиксить чота namespace Sailboat.Generics { internal class SetGeneric where T : class @@ -66,8 +65,7 @@ namespace Sailboat.Generics { return false; } - - _places[position] = null; + _places.RemoveAt(position); return true; } /// -- 2.25.1 From 9aae54011062d6249f7aca1e3444204845078afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Wed, 8 Nov 2023 08:54:38 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=D0=B5=D1=89=D0=B5=20=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BE=D1=87=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/FormBoatCollection.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sailboat/Sailboat/FormBoatCollection.cs b/Sailboat/Sailboat/FormBoatCollection.cs index 8894ff4..5510193 100644 --- a/Sailboat/Sailboat/FormBoatCollection.cs +++ b/Sailboat/Sailboat/FormBoatCollection.cs @@ -29,10 +29,12 @@ namespace Sailboat { int index = listBoxStorages.SelectedIndex; listBoxStorages.Items.Clear(); + for (int i = 0; i < _storage.Keys.Count; i++) { listBoxStorages.Items.Add(_storage.Keys[i]); } + if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count)) { -- 2.25.1 From d2357e4ce5d65fd11d9ea5d4d7243cc4d636b5c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Sun, 19 Nov 2023 14:33:28 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D0=B8=D1=82=D0=BE=D0=B3=D0=BE=D0=B2=D1=8B?= =?UTF-8?q?=D0=B5=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BE=D1=87=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/BoatsGenericCollection.cs | 8 ++++---- Sailboat/Sailboat/FormSailboat.cs | 5 ++--- Sailboat/Sailboat/SetGeneric.cs | 21 +++++++++++++-------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Sailboat/Sailboat/BoatsGenericCollection.cs b/Sailboat/Sailboat/BoatsGenericCollection.cs index 160b983..f127575 100644 --- a/Sailboat/Sailboat/BoatsGenericCollection.cs +++ b/Sailboat/Sailboat/BoatsGenericCollection.cs @@ -62,7 +62,7 @@ namespace Sailboat.Generics { return false; } - return collect?._collection.Insert(obj) ?? false; + return (bool)collect?._collection.Insert(obj); } /// /// Перегрузка оператора вычитания @@ -70,14 +70,14 @@ namespace Sailboat.Generics /// /// /// - public static T? operator -(BoatsGenericCollection collect, int pos) + public static bool operator -(BoatsGenericCollection collect, int pos) { T? obj = collect._collection[pos]; if (obj != null) { collect._collection.Remove(pos); } - return obj; + return false; } /// @@ -133,7 +133,7 @@ namespace Sailboat.Generics if (boat != null) { int width = _pictureWidth / _placeSizeWidth; - boat.SetPosition(i % width * _placeSizeWidth, _pictureHeight - _pictureHeight % _placeSizeHeight - (i / width + 1) * _placeSizeHeight); + boat.SetPosition(i % width * _placeSizeWidth, i / width * _placeSizeHeight); boat.DrawTransport(g); } i++; diff --git a/Sailboat/Sailboat/FormSailboat.cs b/Sailboat/Sailboat/FormSailboat.cs index edbfb8a..bd6e458 100644 --- a/Sailboat/Sailboat/FormSailboat.cs +++ b/Sailboat/Sailboat/FormSailboat.cs @@ -52,10 +52,9 @@ namespace Sailboat Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); - ColorDialog dialogAddColor = new(); - if (dialogAddColor.ShowDialog() == DialogResult.OK) + if (dialog.ShowDialog() == DialogResult.OK) { - dopColor = dialogAddColor.Color; + dopColor = dialog.Color; } _drawingBoat = new DrawingSailboat(random.Next(100, 300), diff --git a/Sailboat/Sailboat/SetGeneric.cs b/Sailboat/Sailboat/SetGeneric.cs index 95a2392..c5bd178 100644 --- a/Sailboat/Sailboat/SetGeneric.cs +++ b/Sailboat/Sailboat/SetGeneric.cs @@ -36,8 +36,10 @@ namespace Sailboat.Generics /// public bool Insert(T boat) { - if (_places.Count == _maxCount) - return false; + if (_places.Count == _maxCount) + { + return false; + } Insert(boat, 0); return true; } @@ -49,8 +51,9 @@ namespace Sailboat.Generics /// public bool Insert(T boat, int position) { - if (!(position >= 0 && position <= Count && _places.Count < _maxCount)) - return false; + if (!(position >= 0 && position <= Count && _places.Count < _maxCount)) { + return false; + } _places.Insert(position, boat); return true; } @@ -77,14 +80,16 @@ namespace Sailboat.Generics { get { - if (!(position >= 0 && position < Count)) - return null; + if (position < 0 || position >= Count) { + return null; + } return _places[position]; } set { - if (!(position >= 0 && position < Count && _places.Count < _maxCount)) - return; + if (!(position >= 0 && position < Count && _places.Count < _maxCount)) { + return; + } _places.Insert(position, value); return; } -- 2.25.1