From 9d409dbed8b19833d7edc3a572d3150f2937f3cf Mon Sep 17 00:00:00 2001 From: GokaPek <109132407+GokaPek@users.noreply.github.com> Date: Tue, 10 Oct 2023 20:30:49 +0400 Subject: [PATCH 1/7] =?UTF-8?q?=D0=92=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CarsGenericCollection.cs | 138 ++++++++++++++++++ .../DrawningSPAU.cs | 5 + .../Form.Designer.cs | 92 +++++++----- .../SelfPropelledArtilleryUnit/Form.cs | 108 +++++++++----- .../FormSPAUCollection.Designer.cs | 45 ++++++ .../FormSPAUCollection.cs | 20 +++ .../FormSPAUCollection.resx | 120 +++++++++++++++ .../SelfPropelledArtilleryUnit/SetGeneric.cs | 81 ++++++++++ 8 files changed, 536 insertions(+), 73 deletions(-) create mode 100644 SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CarsGenericCollection.cs create mode 100644 SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs create mode 100644 SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs create mode 100644 SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.resx create mode 100644 SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CarsGenericCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CarsGenericCollection.cs new file mode 100644 index 0000000..8069ed4 --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CarsGenericCollection.cs @@ -0,0 +1,138 @@ +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 +{ + /// + /// Параметризованный класс для набора объектов DrawningCar + /// + /// + /// + internal class SPAUGenericCollection + where T : DrawningSPAU + where U : IMoveableObject + { + /// + /// Ширина окна прорисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна прорисовки + /// + private readonly int _pictureHeight; + /// + /// Размер занимаемого объектом места (ширина) + /// + private readonly int _placeSizeWidth = 210; + /// + /// Размер занимаемого объектом места (высота) + /// + private readonly int _placeSizeHeight = 90; + /// + /// Набор объектов + /// + private readonly SetGeneric _collection; + /// + /// Конструктор + /// + /// + /// + public SPAUGenericCollection(int picWidth, int picHeight) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = new SetGeneric(width * height); + } + /// + /// Перегрузка оператора сложения + /// + /// + /// + /// + public static bool operator +(SPAUGenericCollection collect, T? obj) + { + if (obj == null) + { + return false; + } + return collect?._collection.Insert(obj) ?? false; + } + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static T? operator -(SPAUGenericCollection collect, int pos) + { + T? obj = collect._collection.Get(pos); + if (obj != null) + { + collect._collection.Remove(pos); + } + return obj; + } + /// + /// Получение объекта IMoveableObject + /// + /// + /// + public U? GetU(int pos) + { + return (U?)_collection.Get(pos)?.GetMoveableObject; + } + /// + /// Вывод всего набора объектов + /// + /// + public Bitmap ShowCars() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawObjects(gr); + return bmp; + } + /// + /// Метод отрисовки фона + /// + /// + private void DrawBackground(Graphics g) + { + Pen pen = new(Color.Black, 3); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight + + 1; ++j) + {//линия рамзетки места + g.DrawLine(pen, i * _placeSizeWidth, j * + _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * + _placeSizeHeight); + } + g.DrawLine(pen, i * _placeSizeWidth, 0, i * + _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); + } + } + /// + /// Метод прорисовки объектов + /// + /// + private void DrawObjects(Graphics g) + { + for (int i = 0; i < _collection.Count; i++) + { + // TODO получение объекта + // TODO установка позиции + // TODO прорисовка объекта + } + } + } +} + diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSPAU.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSPAU.cs index 9b0ef7d..606486e 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSPAU.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSPAU.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using SelfPropelledArtilleryUnit.Entities; +using SelfPropelledArtilleryUnit.MovementStrategy; namespace SelfPropelledArtilleryUnit.DrawningObjects { @@ -217,5 +218,9 @@ namespace SelfPropelledArtilleryUnit.DrawningObjects _ => false, }; } + /// + /// Получение объекта IMoveableObject из объекта DrawningCar + /// + public IMoveableObject GetMoveableObject => new DrawningObjectSPAU(this); } } diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form.Designer.cs index 25d4253..047d2c8 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form.Designer.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form.Designer.cs @@ -29,14 +29,15 @@ private void InitializeComponent() { pictureBoxSPAU = new PictureBox(); - buttonCreate = new Button(); buttonUp = new Button(); buttonDown = new Button(); buttonLeft = new Button(); buttonRight = new Button(); - buttonCreateParent = new Button(); - buttonStep = new Button(); comboBoxStrategy = new ComboBox(); + ButtonCreateSPAU = new Button(); + ButtonCreateSPAUchild = new Button(); + ButtonSelectSPAU = new Button(); + ButtonStartegyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxSPAU).BeginInit(); SuspendLayout(); // @@ -49,17 +50,6 @@ pictureBoxSPAU.TabIndex = 0; pictureBoxSPAU.TabStop = false; // - // buttonCreate - // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(134, 412); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(301, 29); - buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать САУ с залповой установкой"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += buttonCreate_Click; - // // buttonUp // buttonUp.BackgroundImage = Properties.Resources.upper_arrow; @@ -104,26 +94,6 @@ buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += buttonMove_Click; // - // buttonCreateParent - // - buttonCreateParent.Location = new Point(12, 409); - buttonCreateParent.Name = "buttonCreateParent"; - buttonCreateParent.Size = new Size(116, 30); - buttonCreateParent.TabIndex = 6; - buttonCreateParent.Text = "Создать САУ"; - buttonCreateParent.UseVisualStyleBackColor = true; - buttonCreateParent.Click += buttonCreateParent_Click; - // - // buttonStep - // - buttonStep.Location = new Point(794, 65); - buttonStep.Name = "buttonStep"; - buttonStep.Size = new Size(76, 30); - buttonStep.TabIndex = 7; - buttonStep.Text = "Шаг"; - buttonStep.UseVisualStyleBackColor = true; - buttonStep.Click += buttonStep_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -134,19 +104,60 @@ comboBoxStrategy.Size = new Size(103, 28); comboBoxStrategy.TabIndex = 8; // + // ButtonCreateSPAU + // + ButtonCreateSPAU.Location = new Point(12, 403); + ButtonCreateSPAU.Name = "ButtonCreateSPAU"; + ButtonCreateSPAU.Size = new Size(153, 36); + ButtonCreateSPAU.TabIndex = 11; + ButtonCreateSPAU.Text = "Создать обычный"; + ButtonCreateSPAU.UseVisualStyleBackColor = true; + ButtonCreateSPAU.Click += ButtonCreateSPAU_Click; + // + // ButtonCreateSPAUchild + // + ButtonCreateSPAUchild.Location = new Point(189, 403); + ButtonCreateSPAUchild.Name = "ButtonCreateSPAUchild"; + ButtonCreateSPAUchild.Size = new Size(153, 35); + ButtonCreateSPAUchild.TabIndex = 12; + ButtonCreateSPAUchild.Text = "Создать с ЗУ"; + ButtonCreateSPAUchild.UseVisualStyleBackColor = true; + ButtonCreateSPAUchild.Click += ButtonCreateSPAUchild_Click; + // + // ButtonSelectSPAU + // + ButtonSelectSPAU.Location = new Point(759, 90); + ButtonSelectSPAU.Name = "ButtonSelectSPAU"; + ButtonSelectSPAU.Size = new Size(111, 37); + ButtonSelectSPAU.TabIndex = 13; + ButtonSelectSPAU.Text = "Выбрать"; + ButtonSelectSPAU.UseVisualStyleBackColor = true; + ButtonSelectSPAU.Click += ButtonSelectSPAU_Click; + // + // ButtonStartegyStep + // + ButtonStartegyStep.Location = new Point(767, 49); + ButtonStartegyStep.Name = "ButtonStartegyStep"; + ButtonStartegyStep.Size = new Size(103, 26); + ButtonStartegyStep.TabIndex = 14; + ButtonStartegyStep.Text = "Шаг"; + ButtonStartegyStep.UseVisualStyleBackColor = true; + ButtonStartegyStep.Click += ButtonStartegyStep_Click; + // // Form // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(882, 453); + Controls.Add(ButtonStartegyStep); + Controls.Add(ButtonSelectSPAU); + Controls.Add(ButtonCreateSPAUchild); + Controls.Add(ButtonCreateSPAU); Controls.Add(comboBoxStrategy); - Controls.Add(buttonStep); - Controls.Add(buttonCreateParent); Controls.Add(buttonRight); Controls.Add(buttonLeft); Controls.Add(buttonDown); Controls.Add(buttonUp); - Controls.Add(buttonCreate); Controls.Add(pictureBoxSPAU); Name = "Form"; StartPosition = FormStartPosition.CenterParent; @@ -158,13 +169,14 @@ #endregion private PictureBox pictureBoxSPAU; - private Button buttonCreate; private Button buttonUp; private Button buttonDown; private Button buttonLeft; private Button buttonRight; - private Button buttonCreateParent; - private Button buttonStep; private ComboBox comboBoxStrategy; + private Button ButtonCreateSPAU; + private Button ButtonCreateSPAUchild; + private Button ButtonSelectSPAU; + private Button ButtonStartegyStep; } } \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form.cs index 757860f..697d5cd 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form.cs @@ -1,5 +1,6 @@ using SelfPropelledArtilleryUnit.DrawningObjects; using SelfPropelledArtilleryUnit.MovementStrategy; +using System.Drawing; namespace SelfPropelledArtilleryUnit { @@ -13,14 +14,20 @@ namespace SelfPropelledArtilleryUnit /// /// /// - private AbstractStrategy? _abstractStrategy; + private AbstractStrategy? _strategy; + /// + /// + /// + public DrawningSPAU? SelectedSPAU { get; private set; } /// /// /// public Form() { InitializeComponent(); + _strategy = null; + SelectedSPAU = null; } /// /// @@ -42,32 +49,36 @@ namespace SelfPropelledArtilleryUnit /// /// /// - private void buttonCreate_Click(object sender, EventArgs e) + private void ButtonCreateSPAUchild_Click(object sender, EventArgs e) { Random random = new(); + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + + ColorDialog dialogColor = new(); + if (dialogColor.ShowDialog() == DialogResult.OK) + { + color = dialogColor.Color; + } + ColorDialog dialogDop = new(); + if (dialogDop.ShowDialog() == DialogResult.OK) + { + dopColor = dialogDop.Color; + } _drawningSPAU = new DrawningSPAUchild(random.Next(100, 300), - random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), - random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), - random.Next(0, 256)), true, + random.Next(1000, 3000), color, + dopColor, Convert.ToBoolean(random.Next(0, 2)), pictureBoxSPAU.Width, pictureBoxSPAU.Height); - _drawningSPAU.SetPosition(random.Next(10, 100), - random.Next(10, 100)); - Draw(); - } - private void buttonCreateParent_Click(object sender, EventArgs e) - { - Random random = new(); - _drawningSPAU = new DrawningSPAU(random.Next(100, 300), - random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), - random.Next(0, 256)), - pictureBoxSPAU.Width, pictureBoxSPAU.Height); - _drawningSPAU.SetPosition(random.Next(10, 100), - random.Next(10, 100)); + _drawningSPAU.SetPosition(random.Next(10, 100), random.Next(10, + 100)); Draw(); + } + /// + /// + /// + /// + /// private void buttonMove_Click(object sender, EventArgs e) { if (_drawningSPAU == null) @@ -93,7 +104,28 @@ namespace SelfPropelledArtilleryUnit Draw(); } - private void buttonStep_Click(object sender, EventArgs e) + private void ButtonCreateSPAU_Click(object sender, EventArgs e) + { + Random random = new(); + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + _drawningSPAU = new DrawningSPAU(random.Next(100, 300), + random.Next(1000, 3000), color, + pictureBoxSPAU.Width, pictureBoxSPAU.Height); + _drawningSPAU.SetPosition(random.Next(10, 100), random.Next(10, + 100)); + Draw(); + } + /// + /// + /// + /// + /// + private void ButtonStartegyStep_Click(object sender, EventArgs e) { if (_drawningSPAU == null) { @@ -101,34 +133,44 @@ namespace SelfPropelledArtilleryUnit } if (comboBoxStrategy.Enabled) { - _abstractStrategy = comboBoxStrategy.SelectedIndex - switch + _strategy = comboBoxStrategy.SelectedIndex switch { 0 => new MoveToCenter(), 1 => new MoveToBorder(), _ => null, }; - if (_abstractStrategy == null) + if (_strategy == null) { return; } - _abstractStrategy.SetData(new - DrawningObjectSPAU(_drawningSPAU), pictureBoxSPAU.Width, - pictureBoxSPAU.Height); - comboBoxStrategy.Enabled = false; + _strategy.SetData(_drawningSPAU.GetMoveableObject, + pictureBoxSPAU.Width, pictureBoxSPAU.Height); } - if (_abstractStrategy == null) + if (_strategy == null) { return; } - _abstractStrategy.MakeStep(); + comboBoxStrategy.Enabled = false; + _strategy.MakeStep(); Draw(); - if (_abstractStrategy.GetStatus() == Status.Finish) + if (_strategy.GetStatus() == Status.Finish) { comboBoxStrategy.Enabled = true; - _abstractStrategy = null; + _strategy = null; } } + /// + /// + /// + /// + /// + private void ButtonSelectSPAU_Click(object sender, EventArgs e) + { + SelectedSPAU = _drawningSPAU; + DialogResult = DialogResult.OK; + } + + } } \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs new file mode 100644 index 0000000..9744951 --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs @@ -0,0 +1,45 @@ +namespace SelfPropelledArtilleryUnit +{ + partial class FormSPAUCollection + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + SuspendLayout(); + // + // FormSPAUCollection + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(899, 456); + Name = "FormSPAUCollection"; + Text = "FormSPAUCollection"; + ResumeLayout(false); + } + + #endregion + } +} \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs new file mode 100644 index 0000000..9fd8665 --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SelfPropelledArtilleryUnit +{ + public partial class FormSPAUCollection : Form + { + public FormSPAUCollection() + { + InitializeComponent(); + } + } +} diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.resx b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs new file mode 100644 index 0000000..6a7787e --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SelfPropelledArtilleryUnit.Generics +{ + /// + /// Параметризованный набор объектов + /// + /// + internal class SetGeneric + where T : class + { + /// + /// Массив объектов, которые храним + /// + private readonly T?[] _places; + /// + /// Количество объектов в массиве + /// + public int Count => _places.Length; + /// + /// Конструктор + /// + /// + public SetGeneric(int count) + { + _places = new T?[count]; + } + /// + /// Добавление объекта в набор + /// + /// Добавляемый автомобиль + /// + public bool Insert(T car) + { + // TODO вставка в начало набора + return true; + } + /// + /// Добавление объекта в набор на конкретную позицию + /// + /// Добавляемый автомобиль + /// Позиция + /// + public bool Insert(T car, int position) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, если нет, то + // проверка, что после вставляемого элемента в массиве есть пустой элемент + // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента + // TODO вставка по позиции + _places[position] = car; + return true; + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присвоив элементу массива значение null + return true; + } + /// + /// Получение объекта из набора по позиции + /// + /// + /// + public T? Get(int position) + { + // TODO проверка позиции + return _places[position]; + } + } +} + -- 2.25.1 From b22939ef87eb059beec9eb337401eccfbaa310ca Mon Sep 17 00:00:00 2001 From: GokaPek <109132407+GokaPek@users.noreply.github.com> Date: Tue, 10 Oct 2023 20:55:27 +0400 Subject: [PATCH 2/7] =?UTF-8?q?=D0=93=D0=B5=D0=BD=D0=B5=D1=80=D0=B8=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...{Form.Designer.cs => FormSPAU.Designer.cs} | 2 +- .../{Form.cs => FormSPAU.cs} | 4 +- .../{Form.resx => FormSPAU.resx} | 0 .../FormSPAUCollection.Designer.cs | 64 +++++++++++++++++ .../FormSPAUCollection.cs | 71 ++++++++++++++++++- .../SelfPropelledArtilleryUnit/Program.cs | 3 +- ...Collection.cs => SPAUGenericCollection.cs} | 0 7 files changed, 139 insertions(+), 5 deletions(-) rename SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/{Form.Designer.cs => FormSPAU.Designer.cs} (99%) rename SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/{Form.cs => FormSPAU.cs} (98%) rename SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/{Form.resx => FormSPAU.resx} (100%) rename SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/{CarsGenericCollection.cs => SPAUGenericCollection.cs} (100%) diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAU.Designer.cs similarity index 99% rename from SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form.Designer.cs rename to SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAU.Designer.cs index 047d2c8..69dd5eb 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form.Designer.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAU.Designer.cs @@ -1,6 +1,6 @@ namespace SelfPropelledArtilleryUnit { - partial class Form + partial class FormSPAU { /// /// Required designer variable. diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAU.cs similarity index 98% rename from SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form.cs rename to SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAU.cs index 697d5cd..0ca7af8 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAU.cs @@ -4,7 +4,7 @@ using System.Drawing; namespace SelfPropelledArtilleryUnit { - public partial class Form : System.Windows.Forms.Form + public partial class FormSPAU : System.Windows.Forms.Form { /// /// - @@ -23,7 +23,7 @@ namespace SelfPropelledArtilleryUnit /// /// /// - public Form() + public FormSPAU() { InitializeComponent(); _strategy = null; diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form.resx b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAU.resx similarity index 100% rename from SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form.resx rename to SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAU.resx diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs index 9744951..493c480 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs @@ -28,18 +28,82 @@ /// private void InitializeComponent() { + pictureBoxCollection = new PictureBox(); + maskedTextBoxNumber = new MaskedTextBox(); + ButtonAddSPAU = new Button(); + ButtonRemoveSPAU = new Button(); + ButtonRefreshCollection = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); SuspendLayout(); // + // pictureBoxCollection + // + pictureBoxCollection.Location = new Point(12, 12); + pictureBoxCollection.Name = "pictureBoxCollection"; + pictureBoxCollection.Size = new Size(680, 432); + pictureBoxCollection.TabIndex = 0; + pictureBoxCollection.TabStop = false; + // + // maskedTextBoxNumber + // + maskedTextBoxNumber.Location = new Point(729, 51); + maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + maskedTextBoxNumber.Size = new Size(143, 27); + maskedTextBoxNumber.TabIndex = 1; + // + // ButtonAddSPAU + // + ButtonAddSPAU.Location = new Point(748, 102); + ButtonAddSPAU.Name = "ButtonAddSPAU"; + ButtonAddSPAU.Size = new Size(102, 33); + ButtonAddSPAU.TabIndex = 2; + ButtonAddSPAU.Text = "Добавить"; + ButtonAddSPAU.UseVisualStyleBackColor = true; + ButtonAddSPAU.Click += ButtonAddSPAU_Click; + // + // ButtonRemoveSPAU + // + ButtonRemoveSPAU.Location = new Point(750, 141); + ButtonRemoveSPAU.Name = "ButtonRemoveSPAU"; + ButtonRemoveSPAU.Size = new Size(100, 37); + ButtonRemoveSPAU.TabIndex = 3; + ButtonRemoveSPAU.Text = "Удалить"; + ButtonRemoveSPAU.UseVisualStyleBackColor = true; + ButtonRemoveSPAU.Click += ButtonRemoveSPAU_Click; + // + // ButtonRefreshCollection + // + ButtonRefreshCollection.Location = new Point(750, 195); + ButtonRefreshCollection.Name = "ButtonRefreshCollection"; + ButtonRefreshCollection.Size = new Size(100, 35); + ButtonRefreshCollection.TabIndex = 4; + ButtonRefreshCollection.Text = "Обновить"; + ButtonRefreshCollection.UseVisualStyleBackColor = true; + ButtonRefreshCollection.Click += ButtonRefreshCollection_Click; + // // 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(pictureBoxCollection); Name = "FormSPAUCollection"; Text = "FormSPAUCollection"; + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); ResumeLayout(false); + PerformLayout(); } #endregion + + private PictureBox pictureBoxCollection; + private MaskedTextBox maskedTextBoxNumber; + private Button ButtonAddSPAU; + private Button ButtonRemoveSPAU; + private Button ButtonRefreshCollection; } } \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs index 9fd8665..00e650d 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs @@ -1,4 +1,5 @@ -using System; +using SelfPropelledArtilleryUnit.Generics; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -7,14 +8,82 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using SelfPropelledArtilleryUnit.DrawningObjects; +using SelfPropelledArtilleryUnit.MovementStrategy; +using SelfPropelledArtilleryUnit.Generics; namespace SelfPropelledArtilleryUnit { + /// + /// Форма для работы с набором объектов класса DrawningSPAU + /// public partial class FormSPAUCollection : Form { + /// + /// Набор объектов + /// + private readonly SPAUGenericCollection _SPAUs; + /// + /// Конструктор + /// public FormSPAUCollection() { InitializeComponent(); + _SPAUs = new SPAUGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + } + /// + /// Добавление объекта в набор + /// + /// + /// + private void ButtonAddSPAU_Click(object sender, EventArgs e) + { + FormSPAU form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + if (_SPAUs + form.SelectedSPAU) + { + MessageBox.Show("Объект добавлен"); + //pictureBoxCollection.Image = _SPAUs.ShowSPAUs(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + /// + /// Удаление объекта из набора + /// + /// + /// + private void ButtonRemoveSPAU_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxNumber.Text); + if (_SPAUs - pos != null) + { + MessageBox.Show("Объект удален"); + //pictureBoxCollection.Image = _SPAUs.ShowSPAUs(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// + /// Обновление рисунка по набору + /// + /// + /// + private void ButtonRefreshCollection_Click(object sender, EventArgs + e) + { + //pictureBoxCollection.Image = _SPAUs.ShowSPAUs(); } } } diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Program.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Program.cs index 960f82b..92aa644 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Program.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Program.cs @@ -9,7 +9,8 @@ namespace SelfPropelledArtilleryUnit static void Main() { ApplicationConfiguration.Initialize(); - Application.Run(new Form()); + Application.Run(new FormSPAUCollection()); + //Application.Run(new FormSPAU()); } } } \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CarsGenericCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs similarity index 100% rename from SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CarsGenericCollection.cs rename to SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs -- 2.25.1 From e875215a6f2a32b30d44b44bb5fef2bec7c53421 Mon Sep 17 00:00:00 2001 From: GokaPek <109132407+GokaPek@users.noreply.github.com> Date: Wed, 11 Oct 2023 09:12:20 +0400 Subject: [PATCH 3/7] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormSPAUCollection.cs | 6 +- .../SPAUGenericCollection.cs | 9 +-- .../SelfPropelledArtilleryUnit/SetGeneric.cs | 56 ++++++++++++++----- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs index 00e650d..e9d6ba7 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs @@ -44,7 +44,7 @@ namespace SelfPropelledArtilleryUnit if (_SPAUs + form.SelectedSPAU) { MessageBox.Show("Объект добавлен"); - //pictureBoxCollection.Image = _SPAUs.ShowSPAUs(); + pictureBoxCollection.Image = _SPAUs.ShowSPAUs(); } else { @@ -68,7 +68,7 @@ namespace SelfPropelledArtilleryUnit if (_SPAUs - pos != null) { MessageBox.Show("Объект удален"); - //pictureBoxCollection.Image = _SPAUs.ShowSPAUs(); + pictureBoxCollection.Image = _SPAUs.ShowSPAUs(); } else { @@ -83,7 +83,7 @@ namespace SelfPropelledArtilleryUnit private void ButtonRefreshCollection_Click(object sender, EventArgs e) { - //pictureBoxCollection.Image = _SPAUs.ShowSPAUs(); + pictureBoxCollection.Image = _SPAUs.ShowSPAUs(); } } } diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs index 8069ed4..8d52ad1 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs @@ -56,13 +56,14 @@ namespace SelfPropelledArtilleryUnit.Generics /// /// /// - public static bool operator +(SPAUGenericCollection collect, T? obj) + public static SPAUGenericCollection operator +(SPAUGenericCollection collect, T? obj) { if (obj == null) { - return false; + return collect; } - return collect?._collection.Insert(obj) ?? false; + collect._collection.Insert(obj); + return collect; } /// /// Перегрузка оператора вычитания @@ -92,7 +93,7 @@ namespace SelfPropelledArtilleryUnit.Generics /// Вывод всего набора объектов /// /// - public Bitmap ShowCars() + public Bitmap ShowSPAUs() { Bitmap bmp = new(_pictureWidth, _pictureHeight); Graphics gr = Graphics.FromImage(bmp); diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs index 6a7787e..3355026 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Configuration; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -32,12 +33,22 @@ namespace SelfPropelledArtilleryUnit.Generics /// /// Добавление объекта в набор /// - /// Добавляемый автомобиль + /// Добавляемый автомобиль /// - public bool Insert(T car) + public bool Insert(T spau) { - // TODO вставка в начало набора - return true; + try + { + for (int i = _places.Length - 1; i > 0; i--) + { + _places[i] = _places[i - 1]; + } + _places[0] = spau; + return true; + } + catch { + return false; + } } /// /// Добавление объекта в набор на конкретную позицию @@ -45,14 +56,25 @@ namespace SelfPropelledArtilleryUnit.Generics /// Добавляемый автомобиль /// Позиция /// - public bool Insert(T car, int position) + public bool Insert(T spau, int position) { - // TODO проверка позиции - // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // проверка, что после вставляемого элемента в массиве есть пустой элемент - // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента - // TODO вставка по позиции - _places[position] = car; + if (position < 0 || position >= _places.Count() || spau == null) + { + return false; + } + if (_places[position] == null) + { + return false; + + } + int positionNull = Array.FindIndex(_places, position, x => x == null); + if (positionNull == -1) + return false; + for (int i = positionNull; i > position; i--) + { + _places[i] = _places[i - 1]; + } + _places[position] = spau; return true; } /// @@ -62,9 +84,12 @@ namespace SelfPropelledArtilleryUnit.Generics /// public bool Remove(int position) { - // TODO проверка позиции - // TODO удаление объекта из массива, присвоив элементу массива значение null - return true; + if (position < 0 || position >= _places.Count()) + return false; + + _places[position] = null; + + return true; } /// /// Получение объекта из набора по позиции @@ -73,7 +98,8 @@ namespace SelfPropelledArtilleryUnit.Generics /// public T? Get(int position) { - // TODO проверка позиции + if (position < 0 || position >= _places.Count()) + return null; return _places[position]; } } -- 2.25.1 From bbb8274ca8d1f80f4684f7331252cd501ec88e7f Mon Sep 17 00:00:00 2001 From: GokaPek <109132407+GokaPek@users.noreply.github.com> Date: Wed, 11 Oct 2023 11:08:05 +0400 Subject: [PATCH 4/7] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormSPAUCollection.cs | 3 +-- .../SPAUGenericCollection.cs | 21 +++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs index e9d6ba7..c22eff1 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs @@ -1,5 +1,4 @@ -using SelfPropelledArtilleryUnit.Generics; -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs index 8d52ad1..4a0e391 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs @@ -56,14 +56,14 @@ namespace SelfPropelledArtilleryUnit.Generics /// /// /// - public static SPAUGenericCollection operator +(SPAUGenericCollection collect, T? obj) + public static bool operator +(SPAUGenericCollection collect, T? obj) { if (obj == null) { - return collect; + return false; } - collect._collection.Insert(obj); - return collect; + collect?._collection.Insert(obj); + return true; } /// /// Перегрузка оператора вычитания @@ -127,8 +127,21 @@ namespace SelfPropelledArtilleryUnit.Generics /// private void DrawObjects(Graphics g) { + int j = 0; + int stringCount = 0; + DrawningSPAU current; for (int i = 0; i < _collection.Count; i++) { + current = _collection.Get(i); + current?.SetPosition(stringCount * 200, 250 - j * 50); + stringCount++; + if (stringCount >= 3) + { + j++; + stringCount = 0; + } + + current?.DrawTransport(g); // TODO получение объекта // TODO установка позиции // TODO прорисовка объекта -- 2.25.1 From adc8149b7ed7fb00c5a4837abe793d6a5bcf6adb Mon Sep 17 00:00:00 2001 From: GokaPek <109132407+GokaPek@users.noreply.github.com> Date: Sat, 21 Oct 2023 17:04:23 +0400 Subject: [PATCH 5/7] =?UTF-8?q?=D0=9E=D1=81=D1=82=D0=B0=D0=BB=D0=BE=D1=81?= =?UTF-8?q?=D1=8C=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BE=D0=BF=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B8=D1=82=D1=8C=20+=20=D0=B8=20-=20(=D1=82=D0=B7?= =?UTF-8?q?=20=D0=BD=D0=B5=20=D1=87=D1=91=D1=82=D0=BA=D0=BE=D0=B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SelfPropelledArtilleryUnit/FormSPAU.cs | 2 +- .../SelfPropelledArtilleryUnit/FormSPAUCollection.cs | 3 +-- .../SPAUGenericCollection.cs | 12 ++++-------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAU.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAU.cs index 0ca7af8..e011b97 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAU.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAU.cs @@ -67,7 +67,7 @@ namespace SelfPropelledArtilleryUnit } _drawningSPAU = new DrawningSPAUchild(random.Next(100, 300), random.Next(1000, 3000), color, - dopColor, Convert.ToBoolean(random.Next(0, 2)), + dopColor, true, pictureBoxSPAU.Width, pictureBoxSPAU.Height); _drawningSPAU.SetPosition(random.Next(10, 100), random.Next(10, 100)); diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs index c22eff1..a444169 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs @@ -79,8 +79,7 @@ namespace SelfPropelledArtilleryUnit /// /// /// - private void ButtonRefreshCollection_Click(object sender, EventArgs - e) + private void ButtonRefreshCollection_Click(object sender, EventArgs e) { pictureBoxCollection.Image = _SPAUs.ShowSPAUs(); } diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs index 4a0e391..eae28eb 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs @@ -110,9 +110,9 @@ namespace SelfPropelledArtilleryUnit.Generics Pen pen = new(Color.Black, 3); for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) { - for (int j = 0; j < _pictureHeight / _placeSizeHeight + - 1; ++j) - {//линия рамзетки места + for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) + { + //линия рамзетки места g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); @@ -133,18 +133,14 @@ namespace SelfPropelledArtilleryUnit.Generics for (int i = 0; i < _collection.Count; i++) { current = _collection.Get(i); - current?.SetPosition(stringCount * 200, 250 - j * 50); + current?.SetPosition(stringCount * 200, 280 - j * 100); stringCount++; if (stringCount >= 3) { j++; stringCount = 0; } - current?.DrawTransport(g); - // TODO получение объекта - // TODO установка позиции - // TODO прорисовка объекта } } } -- 2.25.1 From a98774d0c42b0b35c1f7532d5b21f4e5881b1af0 Mon Sep 17 00:00:00 2001 From: GokaPek <109132407+GokaPek@users.noreply.github.com> Date: Sun, 22 Oct 2023 18:09:18 +0400 Subject: [PATCH 6/7] =?UTF-8?q?=D0=9E=D1=81=D1=82=D0=B0=D0=BB=D0=BE=D1=81?= =?UTF-8?q?=D1=8C=20=D1=80=D0=B0=D0=B7=D0=BE=D0=B1=D1=80=D0=B0=D1=82=D1=8C?= =?UTF-8?q?=D1=81=D1=8F=20=D1=81=20+=20=D0=B8=20=D0=B2=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D0=B2=D0=BA=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SelfPropelledArtilleryUnit/FormSPAUCollection.cs | 12 ++++++++++-- .../SPAUGenericCollection.cs | 8 ++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs index a444169..3df0d7d 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs @@ -63,8 +63,16 @@ namespace SelfPropelledArtilleryUnit { return; } - int pos = Convert.ToInt32(maskedTextBoxNumber.Text); - if (_SPAUs - pos != null) + int pos; + try { + + pos = Convert.ToInt32(maskedTextBoxNumber.Text); + } + catch { + MessageBox.Show("Не удалось удалить объект"); + return; + } + if (_SPAUs - pos) { MessageBox.Show("Объект удален"); pictureBoxCollection.Image = _SPAUs.ShowSPAUs(); diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs index eae28eb..600294e 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs @@ -71,14 +71,18 @@ namespace SelfPropelledArtilleryUnit.Generics /// /// /// - public static T? operator -(SPAUGenericCollection collect, int pos) + public static bool operator -(SPAUGenericCollection collect, int pos) { T? obj = collect._collection.Get(pos); if (obj != null) { collect._collection.Remove(pos); } - return obj; + else + { + return false; + } + return true; } /// /// Получение объекта IMoveableObject -- 2.25.1 From 8f08604a56079800fba8a9a544e969b5fe256152 Mon Sep 17 00:00:00 2001 From: GokaPek <109132407+GokaPek@users.noreply.github.com> Date: Tue, 24 Oct 2023 10:50:42 +0400 Subject: [PATCH 7/7] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=203=20=D1=84=D0=B8=D0=BD?= =?UTF-8?q?=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormSPAUCollection.cs | 6 ++- .../SPAUGenericCollection.cs | 7 ++- .../SelfPropelledArtilleryUnit/SetGeneric.cs | 48 +++++++++---------- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs index 3df0d7d..fe93be1 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs @@ -10,6 +10,7 @@ using System.Windows.Forms; using SelfPropelledArtilleryUnit.DrawningObjects; using SelfPropelledArtilleryUnit.MovementStrategy; using SelfPropelledArtilleryUnit.Generics; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace SelfPropelledArtilleryUnit { @@ -18,6 +19,7 @@ namespace SelfPropelledArtilleryUnit /// public partial class FormSPAUCollection : Form { + readonly int countPlaces = 11; /// /// Набор объектов /// @@ -40,7 +42,9 @@ namespace SelfPropelledArtilleryUnit FormSPAU form = new(); if (form.ShowDialog() == DialogResult.OK) { - if (_SPAUs + form.SelectedSPAU) + int addedIndex = _SPAUs + form.SelectedSPAU; + if (addedIndex != -1 && addedIndex <= countPlaces) + { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = _SPAUs.ShowSPAUs(); diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs index 600294e..11a18a7 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs @@ -56,14 +56,13 @@ namespace SelfPropelledArtilleryUnit.Generics /// /// /// - public static bool operator +(SPAUGenericCollection collect, T? obj) + public static int operator +(SPAUGenericCollection collect, T? obj) { if (obj == null) { - return false; + return -1; } - collect?._collection.Insert(obj); - return true; + return collect._collection.Insert(obj); } /// /// Перегрузка оператора вычитания diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs index 3355026..b8ecae8 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs @@ -35,20 +35,9 @@ namespace SelfPropelledArtilleryUnit.Generics /// /// Добавляемый автомобиль /// - public bool Insert(T spau) + public int Insert(T spau) { - try - { - for (int i = _places.Length - 1; i > 0; i--) - { - _places[i] = _places[i - 1]; - } - _places[0] = spau; - return true; - } - catch { - return false; - } + return Insert(spau, 0); } /// /// Добавление объекта в набор на конкретную позицию @@ -56,26 +45,37 @@ namespace SelfPropelledArtilleryUnit.Generics /// Добавляемый автомобиль /// Позиция /// - public bool Insert(T spau, int position) + public int Insert(T spau, int position) { - if (position < 0 || position >= _places.Count() || spau == null) + if (position < 0 || spau == null) { - return false; + return -1; } - if (_places[position] == null) + if (position >= Count) { - return false; - + return -1; } + // Ищем первую пустую позицию начиная с указанной позиции int positionNull = Array.FindIndex(_places, position, x => x == null); - if (positionNull == -1) - return false; + + if (positionNull == -1 && _places[Count - 1] != null) + { + // Если пустых позиций нет и последняя позиция в массиве занята + return -1; + } + else if (positionNull == -1) + { + // Если позиция для вставки пустая, а пустых позиций больше нет + positionNull = Count - 1; + } + // Сдвигаем элементы вправо, начиная с первой пустой позиции и заканчивая указанной позицией for (int i = positionNull; i > position; i--) { _places[i] = _places[i - 1]; } + // Вставка по позиции _places[position] = spau; - return true; + return position; } /// /// Удаление объекта из набора с конкретной позиции @@ -84,7 +84,7 @@ namespace SelfPropelledArtilleryUnit.Generics /// public bool Remove(int position) { - if (position < 0 || position >= _places.Count()) + if (position < 0 || position >= Count) return false; _places[position] = null; @@ -98,7 +98,7 @@ namespace SelfPropelledArtilleryUnit.Generics /// public T? Get(int position) { - if (position < 0 || position >= _places.Count()) + if (position < 0 || position >= Count) return null; return _places[position]; } -- 2.25.1