From 3400af8ec50e4c806bac5f4f7ac0e0edca8c4b67 Mon Sep 17 00:00:00 2001
From: GokaPek <109132407+GokaPek@users.noreply.github.com>
Date: Tue, 24 Oct 2023 18:31:24 +0400
Subject: [PATCH 1/5] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20?=
=?UTF-8?q?=D1=8D=D1=82=D0=B0=D0=BF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../FormSPAUCollection.cs | 1 +
.../SPAUGenericCollection.cs | 6 +-
.../SelfPropelledArtilleryUnit/SetGeneric.cs | 92 +++++++++++++------
3 files changed, 67 insertions(+), 32 deletions(-)
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs
index fe93be1..fe671dc 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs
@@ -43,6 +43,7 @@ namespace SelfPropelledArtilleryUnit
if (form.ShowDialog() == DialogResult.OK)
{
int addedIndex = _SPAUs + form.SelectedSPAU;
+ //MessageBox.Show(addedIndex.ToString());
if (addedIndex != -1 && addedIndex <= countPlaces)
{
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs
index 11a18a7..e388ee0 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs
@@ -72,7 +72,7 @@ namespace SelfPropelledArtilleryUnit.Generics
///
public static bool operator -(SPAUGenericCollection collect, int pos)
{
- T? obj = collect._collection.Get(pos);
+ T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
@@ -90,7 +90,7 @@ namespace SelfPropelledArtilleryUnit.Generics
///
public U? GetU(int pos)
{
- return (U?)_collection.Get(pos)?.GetMoveableObject;
+ return (U?)_collection[pos]?.GetMoveableObject;
}
///
/// Вывод всего набора объектов
@@ -135,7 +135,7 @@ namespace SelfPropelledArtilleryUnit.Generics
DrawningSPAU current;
for (int i = 0; i < _collection.Count; i++)
{
- current = _collection.Get(i);
+ current = _collection[i];
current?.SetPosition(stringCount * 200, 280 - j * 100);
stringCount++;
if (stringCount >= 3)
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs
index b8ecae8..29ff50e 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs
@@ -17,18 +17,23 @@ namespace SelfPropelledArtilleryUnit.Generics
///
/// Массив объектов, которые храним
///
- 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);
}
///
/// Добавление объекта в набор
@@ -47,35 +52,34 @@ namespace SelfPropelledArtilleryUnit.Generics
///
public int Insert(T spau, int position)
{
- if (position < 0 || spau == null)
- {
+ if (Count == _maxCount)
return -1;
- }
- if (position >= Count)
- {
- return -1;
- }
- // Ищем первую пустую позицию начиная с указанной позиции
- int positionNull = Array.FindIndex(_places, position, x => x == null);
- if (positionNull == -1 && _places[Count - 1] != null)
- {
- // Если пустых позиций нет и последняя позиция в массиве занята
+ if (position < 0 || spau == null)
return -1;
- }
- else if (positionNull == -1)
+
+ if (position >= _maxCount)
+ return -1;
+
+ int nullIndex = _places.IndexOf(null);
+
+ if (Count == 0)
{
- // Если позиция для вставки пустая, а пустых позиций больше нет
- positionNull = Count - 1;
+ _places.Add(spau);
}
- // Сдвигаем элементы вправо, начиная с первой пустой позиции и заканчивая указанной позицией
- for (int i = positionNull; i > position; i--)
+ else if (nullIndex != -1)
{
- _places[i] = _places[i - 1];
+ for (int i = nullIndex; i > 0; i--)
+ {
+ _places[i] = _places[i - 1];
+ }
+ _places[position] = spau;
}
- // Вставка по позиции
- _places[position] = spau;
- return position;
+ else
+ {
+ _places.Insert(position, spau);
+ }
+ return Count;
}
///
/// Удаление объекта из набора с конкретной позиции
@@ -96,12 +100,42 @@ namespace SelfPropelledArtilleryUnit.Generics
///
///
///
- public T? Get(int position)
+ public T? this[int position]
{
- if (position < 0 || position >= Count)
- return null;
- return _places[position];
+ get
+ {
+ if (position < 0 || position >= _maxCount)
+ return null;
+ return _places[position];
+ }
+ set
+ {
+ if (position < 0 || position >= _maxCount)
+ return;
+ if(_places[position] == null)
+ {
+ _places[position] = value;
+ return;
+ }
+ _places.Insert(position, value);
+ }
}
+ ///
+ /// Проход по списку
+ ///
+ ///
+ public IEnumerable GetSPAUs(int? maxSPAUs = null)
+ {
+ for (int i = 0; i < _places.Count; ++i)
+ {
+ yield return _places[i];
+ if (maxSPAUs.HasValue && i == maxSPAUs.Value)
+ {
+ yield break;
+ }
+ }
+ }
+
}
}
--
2.25.1
From 6f6ac06475f8337c0551b1a854d3cd3008e7a3ca Mon Sep 17 00:00:00 2001
From: GokaPek <109132407+GokaPek@users.noreply.github.com>
Date: Wed, 25 Oct 2023 08:34:33 +0400
Subject: [PATCH 2/5] =?UTF-8?q?=D0=92=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20?=
=?UTF-8?q?=D1=8D=D1=82=D0=B0=D0=BF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../FormSPAUCollection.Designer.cs | 92 +++++++++++--
.../FormSPAUCollection.cs | 121 ++++++++++++++++--
.../SPAUGenericStorage.cs | 84 ++++++++++++
3 files changed, 275 insertions(+), 22 deletions(-)
create mode 100644 SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericStorage.cs
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs
index 493c480..689a1dd 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs
@@ -33,7 +33,15 @@
ButtonAddSPAU = new Button();
ButtonRemoveSPAU = new Button();
ButtonRefreshCollection = new Button();
+ panel1 = new Panel();
+ panel2 = new Panel();
+ listBoxStorages = new ListBox();
+ ButtonDelObject = new Button();
+ ButtonAddObject = new Button();
+ textBoxStorageName = new TextBox();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
+ panel1.SuspendLayout();
+ panel2.SuspendLayout();
SuspendLayout();
//
// pictureBoxCollection
@@ -46,14 +54,14 @@
//
// maskedTextBoxNumber
//
- maskedTextBoxNumber.Location = new Point(729, 51);
+ maskedTextBoxNumber.Location = new Point(18, 71);
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(143, 27);
maskedTextBoxNumber.TabIndex = 1;
//
// ButtonAddSPAU
//
- ButtonAddSPAU.Location = new Point(748, 102);
+ ButtonAddSPAU.Location = new Point(44, 19);
ButtonAddSPAU.Name = "ButtonAddSPAU";
ButtonAddSPAU.Size = new Size(102, 33);
ButtonAddSPAU.TabIndex = 2;
@@ -63,7 +71,7 @@
//
// ButtonRemoveSPAU
//
- ButtonRemoveSPAU.Location = new Point(750, 141);
+ ButtonRemoveSPAU.Location = new Point(44, 118);
ButtonRemoveSPAU.Name = "ButtonRemoveSPAU";
ButtonRemoveSPAU.Size = new Size(100, 37);
ButtonRemoveSPAU.TabIndex = 3;
@@ -73,7 +81,7 @@
//
// ButtonRefreshCollection
//
- ButtonRefreshCollection.Location = new Point(750, 195);
+ ButtonRefreshCollection.Location = new Point(44, 172);
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
ButtonRefreshCollection.Size = new Size(100, 35);
ButtonRefreshCollection.TabIndex = 4;
@@ -81,21 +89,81 @@
ButtonRefreshCollection.UseVisualStyleBackColor = true;
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
//
+ // panel1
+ //
+ panel1.Controls.Add(ButtonRefreshCollection);
+ panel1.Controls.Add(ButtonRemoveSPAU);
+ panel1.Controls.Add(ButtonAddSPAU);
+ panel1.Controls.Add(maskedTextBoxNumber);
+ panel1.Location = new Point(711, 217);
+ panel1.Name = "panel1";
+ panel1.Size = new Size(176, 227);
+ panel1.TabIndex = 5;
+ //
+ // panel2
+ //
+ panel2.Controls.Add(listBoxStorages);
+ panel2.Controls.Add(ButtonDelObject);
+ panel2.Controls.Add(ButtonAddObject);
+ panel2.Controls.Add(textBoxStorageName);
+ panel2.Location = new Point(711, 12);
+ panel2.Name = "panel2";
+ panel2.Size = new Size(174, 198);
+ panel2.TabIndex = 6;
+ //
+ // listBoxStorages
+ //
+ listBoxStorages.FormattingEnabled = true;
+ listBoxStorages.ItemHeight = 20;
+ listBoxStorages.Items.AddRange(new object[] { "Ans", "Second", "Dry", "Quadro" });
+ listBoxStorages.Location = new Point(18, 87);
+ listBoxStorages.Name = "listBoxStorages";
+ listBoxStorages.Size = new Size(143, 64);
+ listBoxStorages.TabIndex = 7;
+ //
+ // ButtonDelObject
+ //
+ ButtonDelObject.Location = new Point(18, 168);
+ ButtonDelObject.Name = "ButtonDelObject";
+ ButtonDelObject.Size = new Size(143, 28);
+ ButtonDelObject.TabIndex = 3;
+ ButtonDelObject.Text = "Удалить набор";
+ ButtonDelObject.UseVisualStyleBackColor = true;
+ ButtonDelObject.Click += ButtonDelObject_Click;
+ //
+ // ButtonAddObject
+ //
+ ButtonAddObject.Location = new Point(18, 53);
+ ButtonAddObject.Name = "ButtonAddObject";
+ ButtonAddObject.Size = new Size(143, 28);
+ ButtonAddObject.TabIndex = 1;
+ ButtonAddObject.Text = "Добавить набор";
+ ButtonAddObject.UseVisualStyleBackColor = true;
+ ButtonAddObject.Click += ButtonAddObject_Click;
+ //
+ // textBoxStorageName
+ //
+ textBoxStorageName.Location = new Point(18, 20);
+ textBoxStorageName.Name = "textBoxStorageName";
+ textBoxStorageName.Size = new Size(143, 27);
+ textBoxStorageName.TabIndex = 0;
+ //
// FormSPAUCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(899, 456);
- Controls.Add(ButtonRefreshCollection);
- Controls.Add(ButtonRemoveSPAU);
- Controls.Add(ButtonAddSPAU);
- Controls.Add(maskedTextBoxNumber);
+ Controls.Add(panel2);
+ Controls.Add(panel1);
Controls.Add(pictureBoxCollection);
Name = "FormSPAUCollection";
Text = "FormSPAUCollection";
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
+ panel1.ResumeLayout(false);
+ panel1.PerformLayout();
+ panel2.ResumeLayout(false);
+ panel2.PerformLayout();
ResumeLayout(false);
- PerformLayout();
}
#endregion
@@ -105,5 +173,11 @@
private Button ButtonAddSPAU;
private Button ButtonRemoveSPAU;
private Button ButtonRefreshCollection;
+ private Panel panel1;
+ private Panel panel2;
+ private Button ButtonAddObject;
+ private TextBox textBoxStorageName;
+ private Button ButtonDelObject;
+ private ListBox listBoxStorages;
}
}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs
index fe671dc..30ed011 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs
@@ -23,14 +23,77 @@ namespace SelfPropelledArtilleryUnit
///
/// Набор объектов
///
- private readonly SPAUGenericCollection _SPAUs;
+ //private readonly SPAUGenericCollection _SPAUs;
+ private readonly SPAUGenericStorage _storage;
///
/// Конструктор
///
public FormSPAUCollection()
{
InitializeComponent();
- _SPAUs = new SPAUGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height);
+ _storage = new SPAUGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
+ }
+ ///
+ /// Заполнение listBoxObjects
+ ///
+ 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 ButtonAddObject_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(listBoxStorages.Text))
+ {
+ MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _storage.AddSet(listBoxStorages.Text);
+ ReloadObjects();
+
+ }
+ ///
+ /// Выбор набора
+ ///
+ ///
+ ///
+ private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ pictureBoxCollection.Image =
+ _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowSPAUs();
+ }
+
+ 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();
+ }
}
///
/// Добавление объекта в набор
@@ -39,16 +102,24 @@ namespace SelfPropelledArtilleryUnit
///
private void ButtonAddSPAU_Click(object sender, EventArgs e)
{
+ if (listBoxStorages.SelectedIndex == -1)
+ {
+ return;
+ }
+ var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
+ if (obj == null)
+ {
+ return;
+ }
FormSPAU form = new();
if (form.ShowDialog() == DialogResult.OK)
{
- int addedIndex = _SPAUs + form.SelectedSPAU;
- //MessageBox.Show(addedIndex.ToString());
+ int addedIndex = obj + form.SelectedSPAU;
if (addedIndex != -1 && addedIndex <= countPlaces)
-
+
{
MessageBox.Show("Объект добавлен");
- pictureBoxCollection.Image = _SPAUs.ShowSPAUs();
+ pictureBoxCollection.Image = obj.ShowSPAUs();
}
else
{
@@ -56,6 +127,8 @@ namespace SelfPropelledArtilleryUnit
}
}
}
+
+
///
/// Удаление объекта из набора
///
@@ -63,24 +136,36 @@ namespace SelfPropelledArtilleryUnit
///
private void ButtonRemoveSPAU_Click(object sender, EventArgs e)
{
+ 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;
- try {
-
- pos = Convert.ToInt32(maskedTextBoxNumber.Text);
+ try
+ {
+
+ pos = Convert.ToInt32(maskedTextBoxNumber.Text);
}
- catch {
+ catch
+ {
MessageBox.Show("Не удалось удалить объект");
return;
}
- if (_SPAUs - pos)
+ if (obj - pos)
{
MessageBox.Show("Объект удален");
- pictureBoxCollection.Image = _SPAUs.ShowSPAUs();
+ pictureBoxCollection.Image = obj.ShowSPAUs();
}
else
{
@@ -94,7 +179,17 @@ namespace SelfPropelledArtilleryUnit
///
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
- pictureBoxCollection.Image = _SPAUs.ShowSPAUs();
+ if (listBoxStorages.SelectedIndex == -1)
+ {
+ return;
+ }
+ var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
+ string.Empty];
+ if (obj == null)
+ {
+ return;
+ }
+ pictureBoxCollection.Image = obj.ShowSPAUs();
}
}
}
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericStorage.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericStorage.cs
new file mode 100644
index 0000000..fb2db48
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericStorage.cs
@@ -0,0 +1,84 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SelfPropelledArtilleryUnit.DrawningObjects;
+using SelfPropelledArtilleryUnit.MovementStrategy;
+
+namespace SelfPropelledArtilleryUnit.Generics
+{
+ ///
+ /// Класс для хранения коллекции
+ ///
+ internal class SPAUGenericStorage
+ {
+ ///
+ /// Словарь (хранилище)
+ ///
+ readonly Dictionary> _SPAUStorages;
+ ///
+ /// Возвращение списка названий наборов
+ ///
+ public List Keys => _SPAUStorages.Keys.ToList();
+ ///
+ /// Ширина окна отрисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна отрисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public SPAUGenericStorage(int pictureWidth, int pictureHeight)
+ {
+ _SPAUStorages = new Dictionary>();
+ _pictureWidth = pictureWidth;
+ _pictureHeight = pictureHeight;
+ }
+ ///
+ /// Добавление набора
+ ///
+ /// Название набора
+ public void AddSet(string name)
+ {
+ try
+ {
+ _SPAUStorages.Add(name, new SPAUGenericCollection(_pictureWidth, _pictureHeight));
+ }
+ catch (Exception) { return; }
+ }
+ ///
+ /// Удаление набора
+ ///
+ /// Название набора
+ public void DelSet(string name)
+ {
+ try { _SPAUStorages.Remove(name); } catch (Exception) { return; }
+ }
+ ///
+ /// Доступ к набору
+ ///
+ ///
+ ///
+ public SPAUGenericCollection? this[string ind]
+ {
+ get
+ {
+ if (_SPAUStorages.ContainsKey(ind))
+ {
+ return _SPAUStorages[ind];
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+ }
+
+}
--
2.25.1
From f1924cb9529ac85bceebb4ba558957b2f99ec20f Mon Sep 17 00:00:00 2001
From: GokaPek <109132407+GokaPek@users.noreply.github.com>
Date: Wed, 25 Oct 2023 08:46:18 +0400
Subject: [PATCH 3/5] =?UTF-8?q?=D0=A2=D1=80=D0=B5=D1=82=D0=B8=D0=B9=20?=
=?UTF-8?q?=D1=88=D0=B0=D0=B3=20(=D0=BF=D0=BE=D1=87=D1=82=D0=B8)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../SelfPropelledArtilleryUnit/FormSPAUCollection.cs | 3 +--
.../SelfPropelledArtilleryUnit/SetGeneric.cs | 11 +----------
2 files changed, 2 insertions(+), 12 deletions(-)
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs
index 30ed011..9407145 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs
@@ -78,8 +78,7 @@ namespace SelfPropelledArtilleryUnit
///
private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
{
- pictureBoxCollection.Image =
- _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowSPAUs();
+ pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowSPAUs();
}
private void ButtonDelObject_Click(object sender, EventArgs e)
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs
index 29ff50e..ccec5e1 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs
@@ -61,20 +61,11 @@ namespace SelfPropelledArtilleryUnit.Generics
if (position >= _maxCount)
return -1;
- int nullIndex = _places.IndexOf(null);
if (Count == 0)
{
_places.Add(spau);
}
- else if (nullIndex != -1)
- {
- for (int i = nullIndex; i > 0; i--)
- {
- _places[i] = _places[i - 1];
- }
- _places[position] = spau;
- }
else
{
_places.Insert(position, spau);
@@ -91,7 +82,7 @@ namespace SelfPropelledArtilleryUnit.Generics
if (position < 0 || position >= Count)
return false;
- _places[position] = null;
+ _places.RemoveAt(position);
return true;
}
--
2.25.1
From 981cccdaa563f402f1119c9b25dccb31b9873cad Mon Sep 17 00:00:00 2001
From: GokaPek <109132407+GokaPek@users.noreply.github.com>
Date: Wed, 25 Oct 2023 09:21:32 +0400
Subject: [PATCH 4/5] =?UTF-8?q?=D0=A2=D1=80=D0=B5=D1=82=D0=B8=D0=B9=20?=
=?UTF-8?q?=D1=8D=D1=82=D0=B0=D0=BF=20=D1=81=D0=BD=D0=BE=D0=B2=D0=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../SelfPropelledArtilleryUnit/FormSPAUCollection.cs | 6 ++----
.../SelfPropelledArtilleryUnit/SPAUGenericCollection.cs | 2 +-
.../SelfPropelledArtilleryUnit/SetGeneric.cs | 7 +------
3 files changed, 4 insertions(+), 11 deletions(-)
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs
index 9407145..45f2ba6 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs
@@ -89,8 +89,7 @@ namespace SelfPropelledArtilleryUnit
}
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
- _storage.DelSet(listBoxStorages.SelectedItem.ToString()
- ?? string.Empty);
+ _storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
ReloadObjects();
}
}
@@ -139,8 +138,7 @@ namespace SelfPropelledArtilleryUnit
{
return;
}
- var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
- string.Empty];
+ var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs
index e388ee0..0a4a07f 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs
@@ -136,7 +136,7 @@ namespace SelfPropelledArtilleryUnit.Generics
for (int i = 0; i < _collection.Count; i++)
{
current = _collection[i];
- current?.SetPosition(stringCount * 200, 280 - j * 100);
+ current?.SetPosition(stringCount * _placeSizeWidth, 280 - j * _placeSizeHeight);
stringCount++;
if (stringCount >= 3)
{
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs
index ccec5e1..85aef92 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs
@@ -103,12 +103,7 @@ namespace SelfPropelledArtilleryUnit.Generics
{
if (position < 0 || position >= _maxCount)
return;
- if(_places[position] == null)
- {
- _places[position] = value;
- return;
- }
- _places.Insert(position, value);
+ _places[position] = value;
}
}
///
--
2.25.1
From 854c7ea1b61ac39f5714688ddc3cb9f740895cda Mon Sep 17 00:00:00 2001
From: GokaPek <109132407+GokaPek@users.noreply.github.com>
Date: Wed, 25 Oct 2023 10:01:29 +0400
Subject: [PATCH 5/5] =?UTF-8?q?=D0=A4=D0=B8=D0=BD=D0=B0=D0=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../FormSPAUCollection.Designer.cs | 2 +-
.../FormSPAUCollection.cs | 14 +++++++++++---
.../SelfPropelledArtilleryUnit/SetGeneric.cs | 4 +++-
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs
index 689a1dd..f2322bf 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs
@@ -115,11 +115,11 @@
//
listBoxStorages.FormattingEnabled = true;
listBoxStorages.ItemHeight = 20;
- listBoxStorages.Items.AddRange(new object[] { "Ans", "Second", "Dry", "Quadro" });
listBoxStorages.Location = new Point(18, 87);
listBoxStorages.Name = "listBoxStorages";
listBoxStorages.Size = new Size(143, 64);
listBoxStorages.TabIndex = 7;
+ listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
//
// ButtonDelObject
//
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs
index 45f2ba6..beac829 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs
@@ -62,12 +62,12 @@ namespace SelfPropelledArtilleryUnit
///
private void ButtonAddObject_Click(object sender, EventArgs e)
{
- if (string.IsNullOrEmpty(listBoxStorages.Text))
+ if (string.IsNullOrEmpty(textBoxStorageName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
- _storage.AddSet(listBoxStorages.Text);
+ _storage.AddSet(textBoxStorageName.Text);
ReloadObjects();
}
@@ -76,10 +76,16 @@ namespace SelfPropelledArtilleryUnit
///
///
///
- private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
+
+ private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowSPAUs();
}
+ ///
+ /// Удаление набора
+ ///
+ ///
+ ///
private void ButtonDelObject_Click(object sender, EventArgs e)
{
@@ -188,5 +194,7 @@ namespace SelfPropelledArtilleryUnit
}
pictureBoxCollection.Image = obj.ShowSPAUs();
}
+
+
}
}
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs
index 85aef92..f07b832 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs
@@ -1,4 +1,6 @@
-using System;
+using SelfPropelledArtilleryUnit.DrawningObjects;
+using SelfPropelledArtilleryUnit.MovementStrategy;
+using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
--
2.25.1