diff --git a/ProjectBattleship/ProjectBattleship/CollectionGenericObjects/Docks.cs b/ProjectBattleship/ProjectBattleship/CollectionGenericObjects/Docks.cs index b007c8f..a486f47 100644 --- a/ProjectBattleship/ProjectBattleship/CollectionGenericObjects/Docks.cs +++ b/ProjectBattleship/ProjectBattleship/CollectionGenericObjects/Docks.cs @@ -1,4 +1,5 @@ using ProjectBattleship.DrawingObject; +using ProjectBattleship.Exceptions; namespace ProjectBattleship.CollectionGenericObjects; /// @@ -12,8 +13,8 @@ public class Docks : AbstractCompany /// /// /// - public Docks(int picWidth, int picHeight, - ICollectionGenericObjects collection) : + public Docks(int picWidth, int picHeight, + ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) { } @@ -26,48 +27,47 @@ public class Docks : AbstractCompany { for (int j = 0; j < height; ++j) { - g.FillRectangle(brush, i * _placeSizeWidth, + g.FillRectangle(brush, i * _placeSizeWidth, j * _placeSizeHeight, 200, 5); - g.FillRectangle(brush, i * _placeSizeWidth, + g.FillRectangle(brush, i * _placeSizeWidth, j * _placeSizeHeight, 5, 80); } } for (int j = 0; j < height - 4; ++j) { - g.FillRectangle(brush, j * _placeSizeWidth, + g.FillRectangle(brush, j * _placeSizeWidth, height * _placeSizeHeight, 200, 5); } } protected override void SetObjectsPosition() { - if (_collection == null) return; int width = _pictureWidth / _placeSizeWidth; int height = _pictureHeight / _placeSizeHeight; int curWidth = width - 1; int curHeight = 0; - for (int i = 0; i < _collection.Count; i++) + for (int i = 0; i < (_collection?.Count ?? 0); i++) { - DrawingWarship? _warship = _collection.Get(i); - if (_warship != null) + try { - if (_warship.SetPictureSize(_pictureWidth, _pictureHeight)) - { - _warship.SetPosition(_placeSizeWidth * curWidth + 20, - curHeight * _placeSizeHeight + 15); - } + _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); + _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 10, curHeight * _placeSizeHeight + 10); } - curWidth--; - if (curWidth < 0) + catch (ObjectNotFoundException) { } + catch (PositionOutOfCollectionException e) { } + if (curWidth > 0) + curWidth--; + else { - curHeight++; curWidth = width - 1; + curHeight++; } + if (curHeight >= height) { return; } } } -} +} \ No newline at end of file diff --git a/ProjectBattleship/ProjectBattleship/FormWarshipCollection.cs b/ProjectBattleship/ProjectBattleship/FormWarshipCollection.cs index e0efd5d..e38f8aa 100644 --- a/ProjectBattleship/ProjectBattleship/FormWarshipCollection.cs +++ b/ProjectBattleship/ProjectBattleship/FormWarshipCollection.cs @@ -142,29 +142,29 @@ public partial class FormWarshipCollection : Form /// /// /// - private void ButtonRemoveWarship_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) - || _company == null) - { - return; - } - if (MessageBox.Show("Удалить объект?", "Удаление", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) - { - return; - } - int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_company - pos != null) - { - MessageBox.Show("Объект удален"); - pictureBox.Image = _company.Show(); - } - else - { - MessageBox.Show("Не удалось удалить объект"); - } - } + //private void ButtonRemoveWarship_Click(object sender, EventArgs e) + //{ + // if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) + // || _company == null) + // { + // return; + // } + // if (MessageBox.Show("Удалить объект?", "Удаление", + // MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + // { + // return; + // } + // int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + // if (_company - pos != null) + // { + // MessageBox.Show("Объект удален"); + // pictureBox.Image = _company.Show(); + // } + // else + // { + // MessageBox.Show("Не удалось удалить объект"); + // } + //} /// /// Передача объекта в другую форму /// diff --git a/ProjectBattleship/ProjectBattleship/ProjectBattleship.csproj b/ProjectBattleship/ProjectBattleship/ProjectBattleship.csproj index a26e80c..08c7869 100644 --- a/ProjectBattleship/ProjectBattleship/ProjectBattleship.csproj +++ b/ProjectBattleship/ProjectBattleship/ProjectBattleship.csproj @@ -9,8 +9,7 @@ - - +