From 596b0127e7de8fb22bb62615fb5288f44f4f4d8b Mon Sep 17 00:00:00 2001 From: kaznacheeva Date: Wed, 25 Oct 2023 08:47:38 +0400 Subject: [PATCH 1/7] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Battleship/Battleship/SetGeneric.cs | 43 +++++++++-- .../Battleship/ShipGenericCollection.cs | 17 +++-- Battleship/Battleship/ShipsGenericStorage.cs | 74 +++++++++++++++++++ 3 files changed, 118 insertions(+), 16 deletions(-) create mode 100644 Battleship/Battleship/ShipsGenericStorage.cs diff --git a/Battleship/Battleship/SetGeneric.cs b/Battleship/Battleship/SetGeneric.cs index 8047a61..4211842 100644 --- a/Battleship/Battleship/SetGeneric.cs +++ b/Battleship/Battleship/SetGeneric.cs @@ -16,18 +16,21 @@ namespace Battleship.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); } /// /// Добавление объекта в набор @@ -88,12 +91,36 @@ namespace Battleship.Generics /// /// /// - public T? Get(int position) + public T? this[int position] { - // TODO проверка позиции - 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 < Count && _places.Count < _maxCount)) + { + return; + } + _places.Insert(position, value); + return; + } + + } + public IEnumerable GetShips(int? maxShips = null) + { + for (int i = 0; i < _places.Count; ++i) + { + yield return _places[i]; + if (maxShips.HasValue && i == maxShips.Value) + { + yield break; + } + } } } } diff --git a/Battleship/Battleship/ShipGenericCollection.cs b/Battleship/Battleship/ShipGenericCollection.cs index 9a0ab6d..9fb13ff 100644 --- a/Battleship/Battleship/ShipGenericCollection.cs +++ b/Battleship/Battleship/ShipGenericCollection.cs @@ -31,18 +31,18 @@ namespace Battleship.Generics return collect._collection.Insert(obj); return -1; } - public static bool operator -(ShipGenericCollection? collect, int pos) + public static T? operator -(ShipGenericCollection? collect, int pos) { - T? obj = collect?._collection.Get(pos); + T? obj = collect?._collection[pos]; if (obj != null && collect != null) { - return collect._collection.Remove(pos); + collect._collection.Remove(pos); } - return false; + return obj; } public U? GetU(int pos) { - return (U?)_collection.Get(pos)?.GetMoveableObject; + return (U?)_collection[pos]?.GetMoveableObject; } public Bitmap ShowShips() { @@ -70,15 +70,16 @@ namespace Battleship.Generics } private void DrawObjects(Graphics g) { - for (int i = 0; i < _collection.Count; i++) + int i = 0; + foreach(var ship in _collection.GetShips()) { - DrawningShip? ship = _collection.Get(i); if(ship != null) { int inRow = _pictureWidth / _placeSizeWidth; - ship.SetPosition(i % inRow * _placeSizeWidth, (_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight + 5); + ship.SetPosition(i % inRow * _placeSizeWidth, _pictureHeight - _pictureHeight % _placeSizeHeight - (i / inRow + 1) * _placeSizeHeight + 5); ship.DrawTransport(g); } + i++; } } } diff --git a/Battleship/Battleship/ShipsGenericStorage.cs b/Battleship/Battleship/ShipsGenericStorage.cs new file mode 100644 index 0000000..ffe3377 --- /dev/null +++ b/Battleship/Battleship/ShipsGenericStorage.cs @@ -0,0 +1,74 @@ +using Battleship.DrawningObjects; +using Battleship.MovementStrategy; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Battleship.Generics +{ + internal class ShipsGenericStorage + { + /// + /// Словарь (хранилище) + /// + readonly Dictionary> _shipStorages; + /// + /// Возвращение списка названий наборов + /// + public List Keys => _shipStorages.Keys.ToList(); + /// + /// Ширина окна отрисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна отрисовки + /// + private readonly int _pictureHeight; + /// + /// Конструктор + /// + /// + /// /// + public ShipsGenericStorage(int pictureWidth, int pictureHeight) + { + _shipStorages = new Dictionary>(); + _pictureWidth = pictureWidth; + _pictureHeight = pictureHeight; + } + /// + /// Добавление набора + /// + /// Название набора + public void AddSet(string name) + { + // TODO Прописать логику для добавления + } + /// + /// Удаление набора + /// + /// Название набора + public void DelSet(string name) + { + // TODO Прописать логику для удаления + } + /// + /// Доступ к набору + /// + /// + /// + public ShipGenericCollection? + this[string ind] + { + get + { + // TODO Продумать логику получения набора + return null; + } + } + } +} + -- 2.25.1 From 6eb869fd5c492a923a5cb8bf667aa8bae7305fc4 Mon Sep 17 00:00:00 2001 From: kaznacheeva Date: Sat, 4 Nov 2023 23:16:55 +0400 Subject: [PATCH 2/7] =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Battleship/FormShipCollection.Designer.cs | 71 ++++++++++- Battleship/Battleship/FormShipCollection.cs | 110 ++++++++++++++++-- Battleship/Battleship/SetGeneric.cs | 82 +++---------- .../Battleship/ShipGenericCollection.cs | 7 +- Battleship/Battleship/ShipsGenericStorage.cs | 48 +++----- 5 files changed, 205 insertions(+), 113 deletions(-) diff --git a/Battleship/Battleship/FormShipCollection.Designer.cs b/Battleship/Battleship/FormShipCollection.Designer.cs index 8da44c5..f51f865 100644 --- a/Battleship/Battleship/FormShipCollection.Designer.cs +++ b/Battleship/Battleship/FormShipCollection.Designer.cs @@ -29,12 +29,18 @@ private void InitializeComponent() { this.groupBoxBattleShip = new System.Windows.Forms.GroupBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.textBoxStorageName = new System.Windows.Forms.TextBox(); + this.listBoxStorages = new System.Windows.Forms.ListBox(); + this.buttonAddObject = new System.Windows.Forms.Button(); + this.buttonDelObject = new System.Windows.Forms.Button(); this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox(); this.buttonRefreshCollection = new System.Windows.Forms.Button(); this.buttonRemoveShip = new System.Windows.Forms.Button(); this.buttonAddShip = new System.Windows.Forms.Button(); this.pictureBoxCollection = new System.Windows.Forms.PictureBox(); this.groupBoxBattleShip.SuspendLayout(); + this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit(); this.SuspendLayout(); // @@ -42,6 +48,7 @@ // this.groupBoxBattleShip.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Right))); + this.groupBoxBattleShip.Controls.Add(this.groupBox1); this.groupBoxBattleShip.Controls.Add(this.maskedTextBoxNumber); this.groupBoxBattleShip.Controls.Add(this.buttonRefreshCollection); this.groupBoxBattleShip.Controls.Add(this.buttonRemoveShip); @@ -53,16 +60,65 @@ this.groupBoxBattleShip.TabStop = false; this.groupBoxBattleShip.Text = "Инструменты"; // + // groupBox1 + // + this.groupBox1.Controls.Add(this.textBoxStorageName); + this.groupBox1.Controls.Add(this.listBoxStorages); + this.groupBox1.Controls.Add(this.buttonAddObject); + this.groupBox1.Controls.Add(this.buttonDelObject); + this.groupBox1.Location = new System.Drawing.Point(6, 22); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(171, 253); + this.groupBox1.TabIndex = 1; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Набор"; + // + // textBoxStorageName + // + this.textBoxStorageName.Location = new System.Drawing.Point(17, 40); + this.textBoxStorageName.Name = "textBoxStorageName"; + this.textBoxStorageName.Size = new System.Drawing.Size(147, 23); + this.textBoxStorageName.TabIndex = 4; + // + // listBoxStorages + // + this.listBoxStorages.FormattingEnabled = true; + this.listBoxStorages.ItemHeight = 15; + this.listBoxStorages.Location = new System.Drawing.Point(17, 124); + this.listBoxStorages.Name = "listBoxStorages"; + this.listBoxStorages.Size = new System.Drawing.Size(147, 94); + this.listBoxStorages.TabIndex = 3; + // + // buttonAddObject + // + this.buttonAddObject.Location = new System.Drawing.Point(18, 81); + this.buttonAddObject.Name = "buttonAddObject"; + this.buttonAddObject.Size = new System.Drawing.Size(147, 23); + this.buttonAddObject.TabIndex = 2; + this.buttonAddObject.Text = "Добавить набор"; + this.buttonAddObject.UseVisualStyleBackColor = true; + this.buttonAddObject.Click += new System.EventHandler(this.buttonAddObject_Click); + // + // buttonDelObject + // + this.buttonDelObject.Location = new System.Drawing.Point(17, 224); + this.buttonDelObject.Name = "buttonDelObject"; + this.buttonDelObject.Size = new System.Drawing.Size(147, 23); + this.buttonDelObject.TabIndex = 1; + this.buttonDelObject.Text = "Удалить набор"; + this.buttonDelObject.UseVisualStyleBackColor = true; + this.buttonDelObject.Click += new System.EventHandler(this.buttonDelObject_Click); + // // maskedTextBoxNumber // - this.maskedTextBoxNumber.Location = new System.Drawing.Point(22, 152); + this.maskedTextBoxNumber.Location = new System.Drawing.Point(23, 330); this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; this.maskedTextBoxNumber.Size = new System.Drawing.Size(147, 23); this.maskedTextBoxNumber.TabIndex = 3; // // buttonRefreshCollection // - this.buttonRefreshCollection.Location = new System.Drawing.Point(22, 265); + this.buttonRefreshCollection.Location = new System.Drawing.Point(23, 411); this.buttonRefreshCollection.Name = "buttonRefreshCollection"; this.buttonRefreshCollection.Size = new System.Drawing.Size(147, 33); this.buttonRefreshCollection.TabIndex = 2; @@ -72,7 +128,7 @@ // // buttonRemoveShip // - this.buttonRemoveShip.Location = new System.Drawing.Point(22, 217); + this.buttonRemoveShip.Location = new System.Drawing.Point(23, 359); this.buttonRemoveShip.Name = "buttonRemoveShip"; this.buttonRemoveShip.Size = new System.Drawing.Size(147, 33); this.buttonRemoveShip.TabIndex = 1; @@ -82,7 +138,7 @@ // // buttonAddShip // - this.buttonAddShip.Location = new System.Drawing.Point(22, 22); + this.buttonAddShip.Location = new System.Drawing.Point(23, 281); this.buttonAddShip.Name = "buttonAddShip"; this.buttonAddShip.Size = new System.Drawing.Size(147, 33); this.buttonAddShip.TabIndex = 0; @@ -112,6 +168,8 @@ this.Text = "FormShipCollection"; this.groupBoxBattleShip.ResumeLayout(false); this.groupBoxBattleShip.PerformLayout(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit(); this.ResumeLayout(false); @@ -125,5 +183,10 @@ private Button buttonAddShip; private PictureBox pictureBoxCollection; private MaskedTextBox maskedTextBoxNumber; + private GroupBox groupBox1; + private TextBox textBoxStorageName; + private ListBox listBoxStorages; + private Button buttonAddObject; + private Button buttonDelObject; } } \ No newline at end of file diff --git a/Battleship/Battleship/FormShipCollection.cs b/Battleship/Battleship/FormShipCollection.cs index 27c8eb4..404ff0e 100644 --- a/Battleship/Battleship/FormShipCollection.cs +++ b/Battleship/Battleship/FormShipCollection.cs @@ -18,14 +18,76 @@ namespace Battleship /// /// Набор объектов /// - private readonly ShipGenericCollection _ships; + private readonly ShipsGenericStorage _storage; /// /// Конструктор /// public FormShipCollection() { InitializeComponent(); - _ships = new ShipGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + _storage = new ShipsGenericStorage(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 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]?.ShowShips(); + } + /// + /// Удаление набора + /// + /// + /// + 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(); + } } /// /// Добавление объекта в набор @@ -34,13 +96,23 @@ namespace Battleship /// private void buttonAddShip_Click(object sender, EventArgs e) { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? + string.Empty]; + if (obj == null) + { + return; + } FormBattleship form = new(); if (form.ShowDialog() == DialogResult.OK) { - if (_ships + form.SelectedShip != -1) + if (obj + form.SelectedShip) { MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = _ships.ShowShips(); + pictureBoxCollection.Image = obj.ShowShips(); } else { @@ -51,16 +123,24 @@ namespace Battleship private void buttonRemoveShip_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 (_ships - pos != null) + if (obj - pos != null) { MessageBox.Show("Объект удален"); - pictureBoxCollection.Image = _ships.ShowShips(); + pictureBoxCollection.Image = obj.ShowShips(); } else { @@ -70,8 +150,18 @@ namespace Battleship private void buttonRefreshCollection_Click(object sender, EventArgs e) { - pictureBoxCollection.Image = _ships.ShowShips(); + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? + string.Empty]; + if (obj == null) + { + return; + } + pictureBoxCollection.Image = obj.ShowShips(); } - } } + diff --git a/Battleship/Battleship/SetGeneric.cs b/Battleship/Battleship/SetGeneric.cs index 4211842..fae0f1d 100644 --- a/Battleship/Battleship/SetGeneric.cs +++ b/Battleship/Battleship/SetGeneric.cs @@ -6,91 +6,45 @@ using System.Threading.Tasks; namespace Battleship.Generics { - /// - /// Параметризованный набор объектов - /// - /// + internal class SetGeneric where T : class { - /// - /// Массив объектов, которые храним - /// private readonly List _places; - /// - /// Количество объектов в массиве - /// public int Count => _places.Count; - private readonly int _maxCount; - /// - /// Конструктор - /// - /// public SetGeneric(int count) { _maxCount = count; _places = new List(count); } - /// - /// Добавление объекта в набор - /// - /// Добавляемый автомобиль - /// - public int Insert(T ship) + + public bool Insert(T ship) { - // TODO вставка в начало набора - if (_places[Count - 1] != null) - return -1; - return Insert(ship,0); - } - /// - /// Добавление объекта в набор на конкретную позицию - /// /// - /// Добавляемый автомобиль - /// Позиция - /// - public int Insert(T ship, int position) - { - // TODO проверка позиции - // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // проверка, что после вставляемого элемента в массиве есть пустой элемент - // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента - // TODO вставка по позиции_places[position] = car; - if (!(position >= 0 && position < Count)) - return -1; - if (_places[position] != null) + if(_places.Count == _maxCount) { - int ind = position; - while (ind < Count && _places[ind] != null) - ind++; - if (ind == Count) - return -1; - for (int i = ind - 1; i >= position; i--) - _places[i + 1] = _places[i]; + return false; } - _places[position] = ship; - return position; + Insert(ship, 0); + return true; + } + + public bool Insert(T ship, int position) + { + if(!(position >= 0 && position <= Count && _places.Count < _maxCount)) + { + return false; + } + _places.Insert(position, ship); + return true; } - /// - /// Удаление объекта из набора с конкретной позиции - /// - /// - /// public bool Remove(int position) { - // TODO проверка позиции - // TODO удаление объекта из массива, присвоив элементу массива значение null - if (!(position >= 0 && position < Count) || _places[position] == null) + if (!(position >= 0 && position < Count)) return false; _places[position] = null; return true; } - /// - /// Получение объекта из набора по позиции - /// - /// - /// public T? this[int position] { get diff --git a/Battleship/Battleship/ShipGenericCollection.cs b/Battleship/Battleship/ShipGenericCollection.cs index 9fb13ff..ac2d497 100644 --- a/Battleship/Battleship/ShipGenericCollection.cs +++ b/Battleship/Battleship/ShipGenericCollection.cs @@ -25,12 +25,15 @@ namespace Battleship.Generics _pictureHeight = picHeight; _collection = new SetGeneric(width * height); } - public static int operator +(ShipGenericCollection? collect, T? obj) + public static bool operator +(ShipGenericCollection? collect, T? obj) { if (obj != null && collect != null) + { return collect._collection.Insert(obj); - return -1; + } + return false; } + public static T? operator -(ShipGenericCollection? collect, int pos) { T? obj = collect?._collection[pos]; diff --git a/Battleship/Battleship/ShipsGenericStorage.cs b/Battleship/Battleship/ShipsGenericStorage.cs index ffe3377..6260ff3 100644 --- a/Battleship/Battleship/ShipsGenericStorage.cs +++ b/Battleship/Battleship/ShipsGenericStorage.cs @@ -10,28 +10,15 @@ namespace Battleship.Generics { internal class ShipsGenericStorage { - /// - /// Словарь (хранилище) - /// readonly Dictionary> _shipStorages; - /// - /// Возвращение списка названий наборов - /// + public List Keys => _shipStorages.Keys.ToList(); - /// - /// Ширина окна отрисовки - /// + private readonly int _pictureWidth; - /// - /// Высота окна отрисовки - /// + private readonly int _pictureHeight; - /// - /// Конструктор - /// - /// - /// /// + public ShipsGenericStorage(int pictureWidth, int pictureHeight) { _shipStorages = new Dictionary - /// Добавление набора - /// - /// Название набора + public void AddSet(string name) { - // TODO Прописать логику для добавления + if (_shipStorages.ContainsKey(name)) + return; + _shipStorages[name] = new ShipGenericCollection(_pictureWidth,_pictureHeight); } - /// - /// Удаление набора - /// - /// Название набора + public void DelSet(string name) { - // TODO Прописать логику для удаления + if (!_shipStorages.ContainsKey(name)) + return; + _shipStorages.Remove(name); } - /// - /// Доступ к набору - /// - /// - /// + public ShipGenericCollection? this[string ind] { get { - // TODO Продумать логику получения набора + if(_shipStorages.ContainsKey(ind)) + return _shipStorages[ind]; return null; } } -- 2.25.1 From 7686622b373b29d4671ff553487fdc9833064a9b Mon Sep 17 00:00:00 2001 From: kaznacheeva Date: Sat, 4 Nov 2023 23:36:09 +0400 Subject: [PATCH 3/7] =?UTF-8?q?=D0=B4=D0=BE=D0=BB=D0=B6=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=B1=D1=8B=D1=82=D1=8C=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Battleship/Battleship/FormShipCollection.Designer.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Battleship/Battleship/FormShipCollection.Designer.cs b/Battleship/Battleship/FormShipCollection.Designer.cs index f51f865..a597aed 100644 --- a/Battleship/Battleship/FormShipCollection.Designer.cs +++ b/Battleship/Battleship/FormShipCollection.Designer.cs @@ -88,6 +88,7 @@ this.listBoxStorages.Name = "listBoxStorages"; this.listBoxStorages.Size = new System.Drawing.Size(147, 94); this.listBoxStorages.TabIndex = 3; + this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged); // // buttonAddObject // -- 2.25.1 From 7eaadef863aa647b4071d987c616f990fe0268c0 Mon Sep 17 00:00:00 2001 From: kaznacheeva Date: Sun, 5 Nov 2023 23:44:22 +0400 Subject: [PATCH 4/7] =?UTF-8?q?=D1=87=D1=83=D1=82=D1=8C=20=D1=87=D1=83?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0,=20=D0=B4=D1=83=D0=BC=D0=B0=D1=8E=20=D0=B3=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Battleship/Battleship/SetGeneric.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Battleship/Battleship/SetGeneric.cs b/Battleship/Battleship/SetGeneric.cs index fae0f1d..c0e3858 100644 --- a/Battleship/Battleship/SetGeneric.cs +++ b/Battleship/Battleship/SetGeneric.cs @@ -40,9 +40,9 @@ namespace Battleship.Generics } public bool Remove(int position) { - if (!(position >= 0 && position < Count)) + if (position < 0 || position >= Count) return false; - _places[position] = null; + _places.RemoveAt(position); return true; } public T? this[int position] -- 2.25.1 From 6dbd0832d8740a128fa44eb7883bd8e6ef496f58 Mon Sep 17 00:00:00 2001 From: kaznacheeva Date: Wed, 15 Nov 2023 12:14:21 +0400 Subject: [PATCH 5/7] =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Battleship/Battleship/SetGeneric.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Battleship/Battleship/SetGeneric.cs b/Battleship/Battleship/SetGeneric.cs index c0e3858..7542dea 100644 --- a/Battleship/Battleship/SetGeneric.cs +++ b/Battleship/Battleship/SetGeneric.cs @@ -72,7 +72,9 @@ namespace Battleship.Generics yield return _places[i]; if (maxShips.HasValue && i == maxShips.Value) { + yield break; + } } } -- 2.25.1 From fbfcf9250dfff5629112e94d0de8dce28e3ff74a Mon Sep 17 00:00:00 2001 From: kaznacheeva Date: Wed, 15 Nov 2023 12:24:26 +0400 Subject: [PATCH 6/7] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=9B=D0=B0=D0=B1=D0=B0=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Battleship/Battleship/SetGeneric.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Battleship/Battleship/SetGeneric.cs b/Battleship/Battleship/SetGeneric.cs index 7542dea..49e4943 100644 --- a/Battleship/Battleship/SetGeneric.cs +++ b/Battleship/Battleship/SetGeneric.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; namespace Battleship.Generics { - internal class SetGeneric where T : class { -- 2.25.1 From fe3868fac1026b5da1ba6caa8e6da3d28d4d98f4 Mon Sep 17 00:00:00 2001 From: kaznacheeva Date: Mon, 20 Nov 2023 20:24:50 +0400 Subject: [PATCH 7/7] fix conflict --- Battleship/Battleship/SetGeneric.cs | 47 ----------------------------- 1 file changed, 47 deletions(-) diff --git a/Battleship/Battleship/SetGeneric.cs b/Battleship/Battleship/SetGeneric.cs index 791d406..7542dea 100644 --- a/Battleship/Battleship/SetGeneric.cs +++ b/Battleship/Battleship/SetGeneric.cs @@ -6,10 +6,7 @@ using System.Threading.Tasks; namespace Battleship.Generics { -<<<<<<< HEAD -======= ->>>>>>> 504798d4c4853a3db22a25ff6cf613a36640f1c3 internal class SetGeneric where T : class { @@ -24,46 +21,8 @@ namespace Battleship.Generics public bool Insert(T ship) { -<<<<<<< HEAD if(_places.Count == _maxCount) { -======= - if (_places[Count - 1] != null) - return -1; - return Insert(ship,0); - } - /// - /// Добавление объекта в набор на конкретную позицию - /// /// - /// Добавляемый автомобиль - /// Позиция - /// - public int Insert(T ship, int position) - { - if (!(position >= 0 && position < Count)) - return -1; - if (_places[position] != null) - { - int ind = position; - while (ind < Count && _places[ind] != null) - ind++; - if (ind == Count) - return -1; - for (int i = ind - 1; i >= position; i--) - _places[i + 1] = _places[i]; - } - _places[position] = ship; - return position; - } - /// - /// Удаление объекта из набора с конкретной позиции - /// - /// - /// - public bool Remove(int position) - { - if (!(position >= 0 && position < Count) || _places[position] == null) ->>>>>>> 504798d4c4853a3db22a25ff6cf613a36640f1c3 return false; } Insert(ship, 0); @@ -72,7 +31,6 @@ namespace Battleship.Generics public bool Insert(T ship, int position) { -<<<<<<< HEAD if(!(position >= 0 && position <= Count && _places.Count < _maxCount)) { return false; @@ -119,11 +77,6 @@ namespace Battleship.Generics } } -======= - if (!(position >= 0 && position < Count)) - return null; - return _places[position]; ->>>>>>> 504798d4c4853a3db22a25ff6cf613a36640f1c3 } } } -- 2.25.1