From 313b9ea2cf9c9796f361a9443a893e61d03f7f60 Mon Sep 17 00:00:00 2001 From: grishazagidulin Date: Mon, 1 Apr 2024 12:15:09 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC=D1=8B=20=D1=81=20?= =?UTF-8?q?=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D0=BE=D0=BC,?= =?UTF-8?q?=20=D1=83=D0=BA=D0=B0=D0=B7=D1=8B=D0=B2=D0=B0=D1=8E=D1=89=D0=B8?= =?UTF-8?q?=D0=BC=20=D0=BD=D0=B0=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ICollectionGenericObjects.cs | 6 +----- .../CollectionGenericObjects/MassiveGenericObjects.cs | 8 ++------ .../Battleship/CollectionGenericObjects/ShipDocks.cs | 2 -- Battleship/Battleship/FormShipCollection.cs | 11 ----------- 4 files changed, 3 insertions(+), 24 deletions(-) diff --git a/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs index eee43c9..5cf9a6b 100644 --- a/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -16,12 +16,10 @@ public interface ICollectionGenericObjects /// Количество объектов в коллекции /// int Count { get; } - /// /// Установка максимального количества элементов /// int SetMaxCount { set; } - /// /// Добавление объекта в коллекцию /// @@ -35,14 +33,12 @@ public interface ICollectionGenericObjects /// Позиция /// true - удачно, false - вставка не удалась bool Insert(T obj, int position); - /// /// Удаление объекта из коллекции с конкретной позиции /// /// Позиция /// true - удачно, false - удаление не удалось - T Remove(int position); - + T? Remove(int position); /// /// Получение объекта по позиции /// diff --git a/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs index 819afe4..afc3afb 100644 --- a/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs @@ -38,7 +38,6 @@ public class MassiveGenericObjects : ICollectionGenericObjects } } } - /// /// Конструктор /// @@ -69,7 +68,6 @@ public class MassiveGenericObjects : ICollectionGenericObjects } return -1; } - public bool Insert(T obj, int position) { if (position < 0 || position >= _collection.Length) // проверка позиции @@ -97,14 +95,12 @@ public class MassiveGenericObjects : ICollectionGenericObjects } return false; } - - public T Remove(int position) + public T? Remove(int position) { if (position < 0 || position >= _collection.Length || _collection[position]==null) // проверка позиции и наличия объекта return null; - T temp = _collection[position]; + T? temp = _collection[position]; _collection[position] = null; - return temp; } } diff --git a/Battleship/Battleship/CollectionGenericObjects/ShipDocks.cs b/Battleship/Battleship/CollectionGenericObjects/ShipDocks.cs index ed35c78..3a87e6d 100644 --- a/Battleship/Battleship/CollectionGenericObjects/ShipDocks.cs +++ b/Battleship/Battleship/CollectionGenericObjects/ShipDocks.cs @@ -22,7 +22,6 @@ public class ShipDocks : AbstractCompany public ShipDocks(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) { } - protected override void DrawBackground(Graphics g) { Pen pen = new Pen(Color.Brown, 4); @@ -40,7 +39,6 @@ public class ShipDocks : AbstractCompany x = 0; } } - protected override void SetObjectsPosition() { int count = 0; diff --git a/Battleship/Battleship/FormShipCollection.cs b/Battleship/Battleship/FormShipCollection.cs index abcacce..a638a30 100644 --- a/Battleship/Battleship/FormShipCollection.cs +++ b/Battleship/Battleship/FormShipCollection.cs @@ -78,7 +78,6 @@ public partial class FormShipCollection : Form MessageBox.Show("Не удалось добавить объект"); } } - /// /// Получение цвета /// @@ -94,19 +93,16 @@ public partial class FormShipCollection : Form } return color; } - private void ButtonDelShip_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) { return; } - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } - int pos = Convert.ToInt32(maskedTextBox.Text); if (_company - pos != null) { @@ -118,14 +114,12 @@ public partial class FormShipCollection : Form MessageBox.Show("Не удалось удалить объект"); } } - private void ButtonGoToTest_Click(object sender, EventArgs e) { if (_company == null) { return; } - DrawningShip? ship = null; int counter = 100; while (ship == null) @@ -137,20 +131,16 @@ public partial class FormShipCollection : Form break; } } - if (ship == null) { return; } - FormBattleship form = new() { SetShip = ship }; form.ShowDialog(); - } - private void ButtonRefresh_Click(object sender, EventArgs e) { if (_company == null) @@ -161,6 +151,5 @@ public partial class FormShipCollection : Form pictureBox.Image = _company.Show(); } private void ButtonAddBattleship_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBattleship)); - private void buttonAddShip_Click_1(object sender, EventArgs e) => CreateObject(nameof(DrawningShip)); }