diff --git a/ProjectStormtrooper/CollectionGenericObjects/AbstractCompany.cs b/ProjectStormtrooper/CollectionGenericObjects/AbstractCompany.cs index 5898eec..71e19ad 100644 --- a/ProjectStormtrooper/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectStormtrooper/CollectionGenericObjects/AbstractCompany.cs @@ -9,7 +9,7 @@ public abstract class AbstractCompany /// /// Размер места (ширина) /// - protected readonly int _placeSizeWidth = 210; + protected readonly int _placeSizeWidth = 220; /// /// Размер места (высота) /// @@ -22,10 +22,15 @@ public abstract class AbstractCompany /// Высота окна /// protected readonly int _pictureHeight; + protected static int amountOfObjects = 0; /// /// Коллекция штурмовика /// protected ICollectionGenericObjects? _collection = null; + public static int getAmountOfObjects() + { + return amountOfObjects; + } /// /// Вычисление максимального количества элементов, который можно разместить в окне /// @@ -85,8 +90,12 @@ public abstract class AbstractCompany SetObjectsPosition(); for (int i = 0; i < (_collection?.Count ?? 0); ++i) { - DrawningStormtrooperBase? obj = _collection?.Get(i); - obj?.DrawTransport(graphics); + try + { + DrawningStormtrooperBase? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + catch (Exception) { } } return bitmap; } diff --git a/ProjectStormtrooper/CollectionGenericObjects/ListGenericObjects.cs b/ProjectStormtrooper/CollectionGenericObjects/ListGenericObjects.cs index 16cfc50..73ce612 100644 --- a/ProjectStormtrooper/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectStormtrooper/CollectionGenericObjects/ListGenericObjects.cs @@ -79,9 +79,9 @@ public class ListGenericObjects : ICollectionGenericObjects // TODO проверка позиции // TODO удаление объекта из списка if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position); - T obj = _collection[position]; + T temp = _collection[position]; _collection.RemoveAt(position); - return obj; + return temp; } public IEnumerable GetItems() diff --git a/ProjectStormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectStormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs index 656733e..3738366 100644 --- a/ProjectStormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectStormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs @@ -54,7 +54,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects { // проверка позиции if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position); - //if (_collection[position] == null) throw new ObjectNotFoundException(position); + if (_collection[position] == null) throw new ObjectNotFoundException(position); return _collection[position]; } diff --git a/ProjectStormtrooper/CollectionGenericObjects/StormtrooperSharingService.cs b/ProjectStormtrooper/CollectionGenericObjects/StormtrooperSharingService.cs index c556794..04c94f0 100644 --- a/ProjectStormtrooper/CollectionGenericObjects/StormtrooperSharingService.cs +++ b/ProjectStormtrooper/CollectionGenericObjects/StormtrooperSharingService.cs @@ -46,15 +46,15 @@ public class StormtrooperSharingService : AbstractCompany { try { - if (_collection.Get(i) != null) - { + _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 15, curHeight * _placeSizeHeight + 3); - } + } catch (Exception) { } if (curWidth > 0) curWidth--; + else { curWidth = width - 1; diff --git a/ProjectStormtrooper/Drawnings/DrawingStormtrooper.cs b/ProjectStormtrooper/Drawnings/DrawingStormtrooper.cs index eae3cd5..e1d4d01 100644 --- a/ProjectStormtrooper/Drawnings/DrawingStormtrooper.cs +++ b/ProjectStormtrooper/Drawnings/DrawingStormtrooper.cs @@ -20,7 +20,7 @@ public class DrawingStormtrooper: DrawningStormtrooperBase /// /// - public DrawingStormtrooper(int speed,double weight, Color bodyColor,Color additionalColor, bool rockets, bool bombs):base(140,140) + public DrawingStormtrooper(int speed,double weight, Color bodyColor,Color additionalColor, bool rockets, bool bombs):base(140,135) { EntityStormtrooperBase = new EntityStormtrooper(speed, weight, bodyColor, additionalColor, rockets, bombs); @@ -62,7 +62,7 @@ public class DrawingStormtrooper: DrawningStormtrooperBase g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 40, 10, 10); g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 90, 10, 10); } - + } diff --git a/ProjectStormtrooper/Drawnings/DrawingStormtrooperBase.cs b/ProjectStormtrooper/Drawnings/DrawingStormtrooperBase.cs index e386756..5ac903e 100644 --- a/ProjectStormtrooper/Drawnings/DrawingStormtrooperBase.cs +++ b/ProjectStormtrooper/Drawnings/DrawingStormtrooperBase.cs @@ -36,7 +36,7 @@ public class DrawningStormtrooperBase /// Высота прорисовки /// - private readonly int _drawningStormtooperHeight = 140; + private readonly int _drawningStormtooperHeight = 135; /// /// Координата Х объекта @@ -215,7 +215,7 @@ public class DrawningStormtrooperBase Pen pen = new(Color.Black); Brush bodyColorBrush = new SolidBrush(EntityStormtrooperBase.BodyColor); - + //нос штурмовика Brush brBlack = new SolidBrush(Color.Black); diff --git a/ProjectStormtrooper/FormStormtrooperCollection.Designer.cs b/ProjectStormtrooper/FormStormtrooperCollection.Designer.cs index 1992de9..006cca3 100644 --- a/ProjectStormtrooper/FormStormtrooperCollection.Designer.cs +++ b/ProjectStormtrooper/FormStormtrooperCollection.Designer.cs @@ -68,7 +68,7 @@ groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Location = new Point(911, 24); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(173, 604); + groupBoxTools.Size = new Size(173, 646); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; @@ -248,7 +248,7 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 24); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(911, 604); + pictureBox.Size = new Size(911, 646); pictureBox.TabIndex = 3; pictureBox.TabStop = false; // @@ -296,7 +296,7 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1084, 628); + ClientSize = new Size(1084, 670); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Controls.Add(menuStrip); diff --git a/ProjectStormtrooper/FormStormtrooperCollection.cs b/ProjectStormtrooper/FormStormtrooperCollection.cs index 0566c63..77b5c1c 100644 --- a/ProjectStormtrooper/FormStormtrooperCollection.cs +++ b/ProjectStormtrooper/FormStormtrooperCollection.cs @@ -100,7 +100,7 @@ public partial class FormStormtrooperCollection : Form /// private void ButtonRemoveStormtrooper_Click(object sender, EventArgs e) { - + if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) { return; @@ -110,6 +110,7 @@ public partial class FormStormtrooperCollection : Form return; } int pos = Convert.ToInt32(maskedTextBox.Text); + int tempSize = StormtrooperSharingService.getAmountOfObjects(); try { if (_company - pos != null) @@ -119,7 +120,7 @@ public partial class FormStormtrooperCollection : Form _logger.LogInformation("Удален объект по позиции" + pos); } } - catch(Exception ex) + catch (Exception ex) { MessageBox.Show("Не удалось удалить объект"); _logger.LogError("Ошибка: {Message}", ex.Message); @@ -140,22 +141,23 @@ public partial class FormStormtrooperCollection : Form int counter = 100; try { + while (stormtrooper == null) { stormtrooper = _company.GetRandomObject(); counter--; - if (counter < -0) + if (counter <= 0) { break; } } - FormStormtrooper form = new() + FormStormtrooper form = new(); { - SetStormtrooper = stormtrooper + SetStormtrooper(stormtrooper); }; form.ShowDialog(); } - catch(Exception ex) + catch (Exception ex) { MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } @@ -200,7 +202,7 @@ public partial class FormStormtrooperCollection : Form RerfreshListBoxItems(); _logger.LogInformation("Коллекция добавлена" + textBoxCollectionName.Text); } - catch(Exception ex) + catch (Exception ex) { _logger.LogError("Ошибка: {Message}", ex.Message); } @@ -231,11 +233,11 @@ public partial class FormStormtrooperCollection : Form RerfreshListBoxItems(); _logger.LogInformation("Коллекция:" + listBoxCollection.SelectedItem.ToString() + "удалена"); } - catch(Exception ex) + catch (Exception ex) { _logger.LogError("Ошибка: {Message}", ex.Message); } - + } /// /// Добавление списка в listBoxCollection @@ -302,7 +304,7 @@ public partial class FormStormtrooperCollection : Form MessageBoxButtons.OK, MessageBoxIcon.Error); _logger.LogError("Ошибка: {Message}", ex.Message); } - + } } /// @@ -323,20 +325,20 @@ public partial class FormStormtrooperCollection : Form RerfreshListBoxItems(); _logger.LogInformation("Загрузка из файла: {filename}", openFileDialog.FileName); } - catch(Exception ex) + catch (Exception ex) { MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); _logger.LogError("Ошибка: {Message}", ex.Message); } - + } } - - - + + + } diff --git a/ProjectStormtrooper/FormStormtrooperCollection.resx b/ProjectStormtrooper/FormStormtrooperCollection.resx index 8b1dfa1..ca20953 100644 --- a/ProjectStormtrooper/FormStormtrooperCollection.resx +++ b/ProjectStormtrooper/FormStormtrooperCollection.resx @@ -126,4 +126,7 @@ 261, 17 + + 25 + \ No newline at end of file