From d17975562c5fbf8201c44da0fb13a21f13c4e859 Mon Sep 17 00:00:00 2001 From: YourDax Date: Fri, 13 Oct 2023 02:51:58 +0400 Subject: [PATCH 1/6] Done --- .../BaseDrawingAntiAirCraftGun.cs | 6 + .../FormAntiAirCraftGun.Designer.cs | 18 +- .../AntiAirCraftGun/FormAntiAirCraftGun.cs | 35 +++- .../AntiAirCraftGun/FormAntiAirCraftGun.resx | 3 + .../FormAntiAirCraftGunCollection.Designer.cs | 123 +++++++++++++ .../FormAntiAirCraftGunCollection.cs | 69 ++++++++ .../FormAntiAirCraftGunCollection.resx | 60 +++++++ .../AntiAirCraftGun/Generics/SetGeneric.cs | 109 ++++++++++++ .../Generics/ZenitsGenericCollection.cs | 165 ++++++++++++++++++ AntiAirCraftGun/AntiAirCraftGun/Program.cs | 2 +- 10 files changed, 579 insertions(+), 11 deletions(-) create mode 100644 AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.Designer.cs create mode 100644 AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.cs create mode 100644 AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.resx create mode 100644 AntiAirCraftGun/AntiAirCraftGun/Generics/SetGeneric.cs create mode 100644 AntiAirCraftGun/AntiAirCraftGun/Generics/ZenitsGenericCollection.cs diff --git a/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs index 7b57a03..450f4f5 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using AntiAircraftGun.Enitites; +using AntiAircraftGun.MovementStrategy; namespace AntiAircraftGun.DrawingObjects { @@ -140,5 +141,10 @@ namespace AntiAircraftGun.DrawingObjects g.FillEllipse(Brushes.Black, trackRect); } } + /// + /// Получение объекта IMoveableObject из объекта DrawningCar + /// + public IMoveableObject GetMoveableObject => new DrawingObjectAntiAirCraftGun(this); + } } diff --git a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.Designer.cs b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.Designer.cs index 642efb3..eac3272 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.Designer.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.Designer.cs @@ -37,6 +37,8 @@ this.comboBoxStrategy = new System.Windows.Forms.ComboBox(); this.CreateAntiAirCraftGun = new System.Windows.Forms.Button(); this.Step = new System.Windows.Forms.Button(); + this.ButtonSelectZenit = new System.Windows.Forms.Button(); + this.colorDialog1 = new System.Windows.Forms.ColorDialog(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).BeginInit(); this.SuspendLayout(); // @@ -120,7 +122,6 @@ this.comboBoxStrategy.Name = "comboBoxStrategy"; this.comboBoxStrategy.Size = new System.Drawing.Size(170, 23); this.comboBoxStrategy.TabIndex = 6; - this.comboBoxStrategy.SelectedIndexChanged += new System.EventHandler(this.comboBoxStrategy_SelectedIndexChanged); // // CreateAntiAirCraftGun // @@ -142,11 +143,22 @@ this.Step.UseVisualStyleBackColor = true; this.Step.Click += new System.EventHandler(this.ButtonStep_Click); // + // ButtonSelectZenit + // + this.ButtonSelectZenit.Location = new System.Drawing.Point(412, 577); + this.ButtonSelectZenit.Name = "ButtonSelectZenit"; + this.ButtonSelectZenit.Size = new System.Drawing.Size(157, 23); + this.ButtonSelectZenit.TabIndex = 9; + this.ButtonSelectZenit.Text = "Выбрать объект"; + this.ButtonSelectZenit.UseVisualStyleBackColor = true; + this.ButtonSelectZenit.Click += new System.EventHandler(this.ButtonSelectZenit_Click); + // // FormAntiAirCraftGun // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1491, 628); + this.Controls.Add(this.ButtonSelectZenit); this.Controls.Add(this.Step); this.Controls.Add(this.CreateAntiAirCraftGun); this.Controls.Add(this.comboBoxStrategy); @@ -157,7 +169,7 @@ this.Controls.Add(this.CreateAdavancedAntiAirCraftGun); this.Controls.Add(this.pictureBoxAntiAircraftGun); this.Name = "FormAntiAirCraftGun"; - this.Text = "Form1"; + this.Text = "FormAntiAirCraftGun"; ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -175,5 +187,7 @@ private ComboBox comboBoxStrategy; private Button CreateAntiAirCraftGun; private Button Step; + private Button ButtonSelectZenit; + private ColorDialog colorDialog1; } } \ No newline at end of file diff --git a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs index 620a4a4..84c9976 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs @@ -1,5 +1,6 @@ using AntiAircraftGun.DrawingObjects; using AntiAircraftGun.MovementStrategy; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window; namespace AntiAircraftGun { @@ -8,9 +9,13 @@ namespace AntiAircraftGun private BaseDrawingAntiAirCraftGun _drawing; private AbstractStrategy? _abstractStrategy; + + public BaseDrawingAntiAirCraftGun? SelectedZenit { get; private set; } public FormAntiAirCraftGun() { InitializeComponent(); + _abstractStrategy = null; + SelectedZenit = null; } private void ButtonMove_Click(object sender, EventArgs e) @@ -52,12 +57,18 @@ namespace AntiAircraftGun private void CreateAdvancedAintiAirCraftGun_Click(object sender, EventArgs e) { Random random = new Random(); + Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); // + Color additionalColor = 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)); // . EntityAdvancedAntiAircraftGun + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + bodyColor = dialog.Color; + if (dialog.ShowDialog() == DialogResult.OK) + dopColor = dialog.Color; _drawing = new AdvancedDrawingAntAirCraftGun( 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)), // . - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), // . EntityAdvancedAntiAircraftGun + bodyColor, additionalColor, dopColor, Convert.ToBoolean(random.Next(2)), // Rocket Convert.ToBoolean(random.Next(2)), pictureBoxAntiAircraftGun.Width, @@ -71,11 +82,17 @@ namespace AntiAircraftGun private void CreateAntiAirCraftGun_Click(object sender, EventArgs e) { Random random = new Random(); + Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); // + Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); // . + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + bodyColor = dialog.Color; + } _drawing = new BaseDrawingAntiAirCraftGun( 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)), // . + bodyColor, additionalColor, pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height ); @@ -121,10 +138,12 @@ namespace AntiAircraftGun } } - - private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e) + private void ButtonSelectZenit_Click(object sender, EventArgs e) { - + SelectedZenit = _drawing; + DialogResult = DialogResult.OK; } + + } } \ No newline at end of file diff --git a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.resx b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.resx index f298a7b..a4bb2fd 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.resx +++ b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.resx @@ -57,4 +57,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.Designer.cs b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.Designer.cs new file mode 100644 index 0000000..4779870 --- /dev/null +++ b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.Designer.cs @@ -0,0 +1,123 @@ +namespace AntiAircraftGun +{ + partial class FormAntiAirCraftGunCollection + { + /// + /// 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() + { + this.pictureBoxCollection = new System.Windows.Forms.PictureBox(); + this.panelTools = new System.Windows.Forms.Panel(); + this.textBox = new System.Windows.Forms.TextBox(); + this.buttonUpdateColletion = new System.Windows.Forms.Button(); + this.buttonDeleteZenit = new System.Windows.Forms.Button(); + this.buttonAddZenit = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit(); + this.panelTools.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBoxCollection + // + this.pictureBoxCollection.Location = new System.Drawing.Point(12, 12); + this.pictureBoxCollection.Name = "pictureBoxCollection"; + this.pictureBoxCollection.Size = new System.Drawing.Size(711, 571); + this.pictureBoxCollection.TabIndex = 0; + this.pictureBoxCollection.TabStop = false; + // + // panelTools + // + this.panelTools.Controls.Add(this.textBox); + this.panelTools.Controls.Add(this.buttonUpdateColletion); + this.panelTools.Controls.Add(this.buttonDeleteZenit); + this.panelTools.Controls.Add(this.buttonAddZenit); + this.panelTools.Location = new System.Drawing.Point(729, 14); + this.panelTools.Name = "panelTools"; + this.panelTools.Size = new System.Drawing.Size(234, 568); + this.panelTools.TabIndex = 1; + this.panelTools.Tag = ""; + // + // textBox + // + this.textBox.Location = new System.Drawing.Point(23, 164); + this.textBox.Name = "textBox"; + this.textBox.Size = new System.Drawing.Size(193, 23); + this.textBox.TabIndex = 3; + // + // buttonUpdateColletion + // + this.buttonUpdateColletion.Location = new System.Drawing.Point(23, 263); + this.buttonUpdateColletion.Name = "buttonUpdateColletion"; + this.buttonUpdateColletion.Size = new System.Drawing.Size(193, 40); + this.buttonUpdateColletion.TabIndex = 2; + this.buttonUpdateColletion.Text = "Обновить коллекцию"; + this.buttonUpdateColletion.UseVisualStyleBackColor = true; + this.buttonUpdateColletion.Click += new System.EventHandler(this.ButtonUpdateCollection_Click); + // + // buttonDeleteZenit + // + this.buttonDeleteZenit.Location = new System.Drawing.Point(23, 193); + this.buttonDeleteZenit.Name = "buttonDeleteZenit"; + this.buttonDeleteZenit.Size = new System.Drawing.Size(193, 40); + this.buttonDeleteZenit.TabIndex = 1; + this.buttonDeleteZenit.Text = "Удалить объект"; + this.buttonDeleteZenit.UseVisualStyleBackColor = true; + this.buttonDeleteZenit.Click += new System.EventHandler(this.ButtonDeleteZenit_Click); + // + // buttonAddZenit + // + this.buttonAddZenit.Location = new System.Drawing.Point(23, 32); + this.buttonAddZenit.Name = "buttonAddZenit"; + this.buttonAddZenit.Size = new System.Drawing.Size(193, 40); + this.buttonAddZenit.TabIndex = 0; + this.buttonAddZenit.Text = "Добавить объект"; + this.buttonAddZenit.UseVisualStyleBackColor = true; + this.buttonAddZenit.Click += new System.EventHandler(this.ButtonAddZenit_Click); + // + // FormAntiAirCraftGunCollection + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(971, 595); + this.Controls.Add(this.panelTools); + this.Controls.Add(this.pictureBoxCollection); + this.Name = "FormAntiAirCraftGunCollection"; + this.Text = "FormAntiAirCraftGunCollection"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit(); + this.panelTools.ResumeLayout(false); + this.panelTools.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private PictureBox pictureBoxCollection; + private Panel panelTools; + private TextBox textBox; + private Button buttonUpdateColletion; + private Button buttonDeleteZenit; + private Button buttonAddZenit; + } +} \ No newline at end of file diff --git a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.cs b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.cs new file mode 100644 index 0000000..4adbc08 --- /dev/null +++ b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.cs @@ -0,0 +1,69 @@ +using AntiAircraftGun.DrawingObjects; +using AntiAircraftGun.Generics; +using AntiAircraftGun.MovementStrategy; +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 AntiAircraftGun +{ + public partial class FormAntiAirCraftGunCollection : Form + { + private readonly ZenitsGenericCollection _zenits; + public FormAntiAirCraftGunCollection() + { + InitializeComponent(); + _zenits = new ZenitsGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + + } + private void ButtonAddZenit_Click(object sender, EventArgs e) + { + FormAntiAirCraftGun form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + if (_zenits + form.SelectedZenit != null) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = _zenits.ShowZenits(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + + } + } + + private void ButtonDeleteZenit_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + + { + return; + } + int pos = Convert.ToInt32(textBox.Text); + if (_zenits - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = _zenits.ShowZenits(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + private void ButtonUpdateCollection_Click(object sender, EventArgs e) + { + pictureBoxCollection.Image = _zenits.ShowZenits(); + + } + } +} diff --git a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.resx b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/AntiAirCraftGun/AntiAirCraftGun/Generics/SetGeneric.cs b/AntiAirCraftGun/AntiAirCraftGun/Generics/SetGeneric.cs new file mode 100644 index 0000000..017d217 --- /dev/null +++ b/AntiAirCraftGun/AntiAirCraftGun/Generics/SetGeneric.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AntiAircraftGun.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) + { + // Вставка в начало набора + for (int i = 0; i < _places.Length; i++) + { + if (_places[i] == null) + { + _places[i] = car; + return true; + } + } + return false; // Если нет пустых мест + } + /// + /// Добавление объекта в набор на конкретную позицию + /// /// + /// Добавляемый автомобиль + /// Позиция + /// + public bool Insert(T car, int position) + { + // Проверка позиции + if (position < 0 || position >= _places.Length) + return false; + + // Проверка, что элемент массива по этой позиции пустой + if (_places[position] != null) + return false; + + // Проверка, что после вставляемого элемента в массиве есть пустой элемент + for (int i = position + 1; i < _places.Length; i++) + { + if (_places[i] == null) + { + // Сдвиг всех объектов справа от позиции до первого пустого элемента + for (int j = i; j > position; j--) + { + _places[j] = _places[j - 1]; + } + _places[position] = car; + return true; + } + } + + return false; // Если нет пустых мест справа + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + // Проверка позиции + if (position < 0 || position >= _places.Length) + return false; + + // Удаление объекта из массива, присвоив элементу массива значение null + _places[position] = null; + return true; + } + /// + /// Получение объекта из набора по позиции + /// + /// + /// + public T? Get(int position) + { + if (position < 0 || position >= _places.Length) + { + // Позиция находится за пределами допустимого диапазона, вернем null + return null; + } + return _places[position]; + } + } +} diff --git a/AntiAirCraftGun/AntiAirCraftGun/Generics/ZenitsGenericCollection.cs b/AntiAirCraftGun/AntiAirCraftGun/Generics/ZenitsGenericCollection.cs new file mode 100644 index 0000000..aa41922 --- /dev/null +++ b/AntiAirCraftGun/AntiAirCraftGun/Generics/ZenitsGenericCollection.cs @@ -0,0 +1,165 @@ +using AntiAircraftGun.DrawingObjects; +using AntiAircraftGun.MovementStrategy; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AntiAircraftGun.Generics +{ + internal class ZenitsGenericCollection + where T : BaseDrawingAntiAirCraftGun + 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 ZenitsGenericCollection(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 +(ZenitsGenericCollection collect, T? + obj) + { + if (obj == null) + { + return false; + } + return collect?._collection.Insert(obj) ?? false; + } + + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static T? operator -(ZenitsGenericCollection 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 ShowZenits() + { + 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) + { + int x = 0; // Начальная координата X + int y = 0; // Начальная координата Y + int maxX = _pictureWidth; // Максимальное значение X, при достижении которого будет ошибка + int maxY = _pictureHeight; // Максимальное значение Y, когда нужно изменить X + int distance_between_objects = _placeSizeHeight; + for (int i = 0; i < _collection.Count; i++) + { + // TODO: Получение объекта + T? obj = _collection.Get(i); + + if (obj != null) + { + // Проверяем, если X достигло максимума, выводим ошибку + if (x >= maxX) + { + MessageBox.Show("Не хватает места для объекта."); + break; + } + + // Устанавливаем позицию + obj.SetPosition(x, y+10); + + // TODO: Прорисовка объекта + obj.DrawTransport(g); + + // Увеличиваем координату Y для следующего объекта + y += distance_between_objects; + + // Проверяем, если Y достигло максимума, изменяем X и сбрасываем Y + if (y+distance_between_objects >= maxY) + { + y = 0; + x += obj.GetWidth+10 + distance_between_objects; + } + } + } + } + } +} diff --git a/AntiAirCraftGun/AntiAirCraftGun/Program.cs b/AntiAirCraftGun/AntiAirCraftGun/Program.cs index 2be25a2..45c0534 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/Program.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/Program.cs @@ -11,7 +11,7 @@ namespace AntiAircraftGun // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormAntiAirCraftGun()); + Application.Run(new FormAntiAirCraftGunCollection()); } } } \ No newline at end of file -- 2.25.1 From 4c46170f09575b985e6d2cb37ee4b374ed0d71bb Mon Sep 17 00:00:00 2001 From: YourDax Date: Sun, 15 Oct 2023 20:49:57 +0400 Subject: [PATCH 2/6] Fixed --- ...n.cs => AdvancedDrawingAntiAirCraftGun.cs} | 12 ++--- .../BaseDrawingAntiAirCraftGun.cs | 45 +++++++++---------- .../Enitites/EntityAdvancedAntiAircraftGun.cs | 4 +- .../AntiAirCraftGun/FormAntiAirCraftGun.cs | 2 +- .../MovementStrategy/BorderDirection.cs | 16 ------- .../DrawingObjectAntiAirCraftGun.cs | 16 +++---- 6 files changed, 39 insertions(+), 56 deletions(-) rename AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/{AdvancedDrawingAntAirCraftGun.cs => AdvancedDrawingAntiAirCraftGun.cs} (71%) delete mode 100644 AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/BorderDirection.cs diff --git a/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/AdvancedDrawingAntAirCraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/AdvancedDrawingAntiAirCraftGun.cs similarity index 71% rename from AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/AdvancedDrawingAntAirCraftGun.cs rename to AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/AdvancedDrawingAntiAirCraftGun.cs index e3eda87..8d28d7e 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/AdvancedDrawingAntAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/AdvancedDrawingAntiAirCraftGun.cs @@ -9,26 +9,26 @@ using static System.Windows.Forms.AxHost; namespace AntiAircraftGun.DrawingObjects { - public class AdvancedDrawingAntAirCraftGun : BaseDrawingAntiAirCraftGun + public class AdvancedDrawingAntiAirCraftGun : BaseDrawingAntiAirCraftGun { private Point[] points = new Point[4]; - public AdvancedDrawingAntAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor, Color dopColor, bool rocket,bool radar, int width, int height) : + public AdvancedDrawingAntiAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor, Color dopColor, bool rocket,bool radar, int width, int height) : base(speed, weight, bodyColor, additionalColor, width, height) { - EntityAntiAirСraftGun = new EntityAdvancedAntiAircraftGun(speed, weight, bodyColor, additionalColor, dopColor, rocket,radar); + AntiAirСraftGun = new EntityAdvancedAntiAirCraftGun(speed, weight, bodyColor, additionalColor, dopColor, rocket,radar); } public override void DrawTransport(Graphics g) { - if (EntityAntiAirСraftGun is not EntityAdvancedAntiAircraftGun advancedGun) + if (AntiAirСraftGun is not EntityAdvancedAntiAirCraftGun advancedGun) { return; } Pen pen = new Pen(Color.Black); - Brush bodyBrush = new SolidBrush(EntityAntiAirСraftGun.BodyColor); - Brush additionalBrush = new SolidBrush(EntityAntiAirСraftGun.AdditionalColor); + Brush bodyBrush = new SolidBrush(AntiAirСraftGun.BodyColor); + Brush additionalBrush = new SolidBrush(AntiAirСraftGun.AdditionalColor); base.DrawTransport(g); Brush dopBrush = new SolidBrush(advancedGun.DopColor); Pen dopPen = new Pen(advancedGun.DopColor); diff --git a/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs index 450f4f5..f4ba407 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs @@ -10,7 +10,7 @@ namespace AntiAircraftGun.DrawingObjects { public class BaseDrawingAntiAirCraftGun { - public EntityAntiAirCraftGun? EntityAntiAirСraftGun { get; protected set; } + public EntityAntiAirCraftGun? AntiAirСraftGun { get; protected set; } private readonly int _pictureWidth; private readonly int _pictureHeight; protected int _startPosX; @@ -22,7 +22,7 @@ namespace AntiAircraftGun.DrawingObjects { _pictureWidth = width; _pictureHeight = height; - EntityAntiAirСraftGun = new EntityAntiAirCraftGun(speed, weight, bodyColor, additionalColor); + AntiAirСraftGun = new EntityAntiAirCraftGun(speed, weight, bodyColor, additionalColor); } protected BaseDrawingAntiAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor, int width, int height, int carWidth, int carHeight) @@ -31,21 +31,20 @@ namespace AntiAircraftGun.DrawingObjects _pictureHeight = height; _zenitWidth = carWidth; _zenitHeight = carHeight; - EntityAntiAirСraftGun = new EntityAntiAirCraftGun(speed, weight, bodyColor, additionalColor); + AntiAirСraftGun = new EntityAntiAirCraftGun(speed, weight, bodyColor, additionalColor); } public void SetPosition(int x, int y) { - if (x < 0 || y < 0) + if (AntiAirСraftGun == null) return; + _startPosX = x; + _startPosY = y; + if (x < 0 || y < 0 || x + _zenitWidth >= _pictureWidth || y + _zenitHeight >= _pictureHeight) { - _startPosX = 10; - _startPosY = 10; - } - else - { - _startPosX = x; - _startPosY = y; + _startPosX = 1; + _startPosY = 1; } + } /// /// Координата X объекта @@ -71,20 +70,20 @@ namespace AntiAircraftGun.DrawingObjects /// true - можно переместится по указанному направлению public bool CanMove(DirectionType direction) { - if (EntityAntiAirСraftGun == null) + if (AntiAirСraftGun == null) { return false; } return direction switch { //влево - DirectionType.Left => _startPosX - EntityAntiAirСraftGun.Step > 0, + DirectionType.Left => _startPosX - AntiAirСraftGun.Step > 0, //вверх - DirectionType.Up => _startPosY - EntityAntiAirСraftGun.Step > 0, + DirectionType.Up => _startPosY - AntiAirСraftGun.Step > 0, // вправо - DirectionType.Right =>_startPosX + EntityAntiAirСraftGun.Step < _pictureWidth - 110, + DirectionType.Right =>_startPosX + AntiAirСraftGun.Step < _pictureWidth - 110, //вниз - DirectionType.Down => _startPosY + EntityAntiAirСraftGun.Step < _pictureHeight - 60, + DirectionType.Down => _startPosY + AntiAirСraftGun.Step < _pictureHeight - 60, _ => false, }; } @@ -94,7 +93,7 @@ namespace AntiAircraftGun.DrawingObjects /// Направление public void MoveTransport(DirectionType direction) { - if (!CanMove(direction) || EntityAntiAirСraftGun == null) + if (!CanMove(direction) || AntiAirСraftGun == null) { return; } @@ -102,19 +101,19 @@ namespace AntiAircraftGun.DrawingObjects { //влево case DirectionType.Left: - _startPosX -= (int)EntityAntiAirСraftGun.Step; + _startPosX -= (int)AntiAirСraftGun.Step; break; //вверх case DirectionType.Up: - _startPosY -= (int)EntityAntiAirСraftGun.Step; + _startPosY -= (int)AntiAirСraftGun.Step; break; // вправо case DirectionType.Right: - _startPosX += (int)EntityAntiAirСraftGun.Step; + _startPosX += (int)AntiAirСraftGun.Step; break; //вниз case DirectionType.Down: - _startPosY += (int)EntityAntiAirСraftGun.Step; + _startPosY += (int)AntiAirСraftGun.Step; break; } } @@ -124,8 +123,8 @@ namespace AntiAircraftGun.DrawingObjects Pen pen = Pens.Black; - Brush bodyBrush = new SolidBrush(EntityAntiAirСraftGun.BodyColor); - Brush additionalBrush = new SolidBrush(EntityAntiAirСraftGun.AdditionalColor); + Brush bodyBrush = new SolidBrush(AntiAirСraftGun.BodyColor); + Brush additionalBrush = new SolidBrush(AntiAirСraftGun.AdditionalColor); g.FillEllipse(additionalBrush, _startPosX, _startPosY + 40, 110, 10); g.DrawEllipse(pen, _startPosX, _startPosY + 40, 110, 10); diff --git a/AntiAirCraftGun/AntiAirCraftGun/Enitites/EntityAdvancedAntiAircraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/Enitites/EntityAdvancedAntiAircraftGun.cs index 2ad1df9..31daa0d 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/Enitites/EntityAdvancedAntiAircraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/Enitites/EntityAdvancedAntiAircraftGun.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace AntiAircraftGun.Enitites { - public class EntityAdvancedAntiAircraftGun : EntityAntiAirCraftGun + public class EntityAdvancedAntiAirCraftGun : EntityAntiAirCraftGun { public Color DopColor { get; private set; } @@ -17,7 +17,7 @@ namespace AntiAircraftGun.Enitites - public EntityAdvancedAntiAircraftGun(int speed, double weight, Color bodyColor, Color additionalColor,Color dopColor, bool rocket, bool radar) + public EntityAdvancedAntiAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor,Color dopColor, bool rocket, bool radar) : base(speed, weight, bodyColor, additionalColor) { DopColor = dopColor; diff --git a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs index 84c9976..7fe4cfe 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs @@ -65,7 +65,7 @@ namespace AntiAircraftGun bodyColor = dialog.Color; if (dialog.ShowDialog() == DialogResult.OK) dopColor = dialog.Color; - _drawing = new AdvancedDrawingAntAirCraftGun( + _drawing = new AdvancedDrawingAntiAirCraftGun( random.Next(100, 300), // random.Next(1000, 3000), // bodyColor, additionalColor, dopColor, diff --git a/AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/BorderDirection.cs b/AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/BorderDirection.cs deleted file mode 100644 index f55fd9c..0000000 --- a/AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/BorderDirection.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AntiAircraftGun.MovementStrategy -{ - public enum BorderDirection - { - Left, - Right, - Top, - Bottom - } -} diff --git a/AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/DrawingObjectAntiAirCraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/DrawingObjectAntiAirCraftGun.cs index 88886e3..6a4948c 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/DrawingObjectAntiAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/DrawingObjectAntiAirCraftGun.cs @@ -9,28 +9,28 @@ namespace AntiAircraftGun.MovementStrategy { public class DrawingObjectAntiAirCraftGun : IMoveableObject { - private readonly BaseDrawingAntiAirCraftGun? _drawningCar = null; + private readonly BaseDrawingAntiAirCraftGun? _drawningAntiAirCraftGun = null; public DrawingObjectAntiAirCraftGun(BaseDrawingAntiAirCraftGun drawningCar) { - _drawningCar = drawningCar; + _drawningAntiAirCraftGun = drawningCar; } public ObjectParameters? GetObjectPosition { get { - if (_drawningCar == null || _drawningCar.EntityAntiAirСraftGun == + if (_drawningAntiAirCraftGun == null || _drawningAntiAirCraftGun.AntiAirСraftGun == null) { return null; } - return new ObjectParameters(_drawningCar.GetPosX, - _drawningCar.GetPosY, _drawningCar.GetWidth, _drawningCar.GetHeight); + return new ObjectParameters(_drawningAntiAirCraftGun.GetPosX, + _drawningAntiAirCraftGun.GetPosY, _drawningAntiAirCraftGun.GetWidth, _drawningAntiAirCraftGun.GetHeight); } } - public int GetStep => (int)(_drawningCar?.EntityAntiAirСraftGun?.Step ?? 0); + public int GetStep => (int)(_drawningAntiAirCraftGun?.AntiAirСraftGun?.Step ?? 0); public bool CheckCanMove(DirectionType direction) => - _drawningCar?.CanMove(direction) ?? false; + _drawningAntiAirCraftGun?.CanMove(direction) ?? false; public void MoveObject(DirectionType direction) => - _drawningCar?.MoveTransport(direction); + _drawningAntiAirCraftGun?.MoveTransport(direction); } } -- 2.25.1 From e9ec3ff774ff491c4368740251f5eda1afe4ee55 Mon Sep 17 00:00:00 2001 From: YourDax Date: Sun, 15 Oct 2023 22:01:02 +0400 Subject: [PATCH 3/6] Fixed --- .../DrawingObjects/BaseDrawingAntiAirCraftGun.cs | 6 +++--- AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs index f4ba407..9dc56d4 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs @@ -81,9 +81,9 @@ namespace AntiAircraftGun.DrawingObjects //вверх DirectionType.Up => _startPosY - AntiAirСraftGun.Step > 0, // вправо - DirectionType.Right =>_startPosX + AntiAirСraftGun.Step < _pictureWidth - 110, - //вниз - DirectionType.Down => _startPosY + AntiAirСraftGun.Step < _pictureHeight - 60, + DirectionType.Right =>_startPosX + AntiAirСraftGun.Step + _zenitWidth < _pictureWidth, + //вниз + DirectionType.Down => _startPosY + AntiAirСraftGun.Step + _zenitHeight< _pictureHeight, _ => false, }; } diff --git a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs index 7fe4cfe..3ae75cd 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs @@ -145,5 +145,5 @@ namespace AntiAircraftGun } - } + } } \ No newline at end of file -- 2.25.1 From 203daf9a1605840221bc7bb9097d2d2999336c1f Mon Sep 17 00:00:00 2001 From: YourDax Date: Sun, 15 Oct 2023 23:02:57 +0400 Subject: [PATCH 4/6] Last fix --- AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs index 46ad614..4042c41 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs @@ -65,7 +65,7 @@ namespace AntiAircraftGun bodyColor = dialog.Color; if (dialog.ShowDialog() == DialogResult.OK) dopColor = dialog.Color; - _drawing = new AdvancedDrawingAntiAirCraftGun( + _drawingAntiAirCraftGun = new AdvancedDrawingAntiAirCraftGun( random.Next(100, 300), // random.Next(1000, 3000), // bodyColor, additionalColor, dopColor, @@ -89,7 +89,7 @@ namespace AntiAircraftGun { bodyColor = dialog.Color; } - _drawing = new BaseDrawingAntiAirCraftGun( + _drawingAntiAirCraftGun = new BaseDrawingAntiAirCraftGun( random.Next(100, 300), // random.Next(1000, 3000), // bodyColor, additionalColor, @@ -140,7 +140,7 @@ namespace AntiAircraftGun } private void ButtonSelectZenit_Click(object sender, EventArgs e) { - SelectedZenit = _drawing; + SelectedZenit = _drawingAntiAirCraftGun; DialogResult = DialogResult.OK; } -- 2.25.1 From 5fb2d43e03b97a6426cd64665732d239cc21790f Mon Sep 17 00:00:00 2001 From: YourDax Date: Tue, 17 Oct 2023 01:29:52 +0400 Subject: [PATCH 5/6] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AntiAirCraftGun/FormAntiAirCraftGunCollection.cs | 4 ++-- ...cCollection.cs => AntiAirCraftGunGenericCollection.cs} | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) rename AntiAirCraftGun/AntiAirCraftGun/Generics/{ZenitsGenericCollection.cs => AntiAirCraftGunGenericCollection.cs} (95%) diff --git a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.cs b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.cs index 4adbc08..0a15fc1 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.cs @@ -15,11 +15,11 @@ namespace AntiAircraftGun { public partial class FormAntiAirCraftGunCollection : Form { - private readonly ZenitsGenericCollection _zenits; + private readonly AntiAirCraftGunGenericCollection _zenits; public FormAntiAirCraftGunCollection() { InitializeComponent(); - _zenits = new ZenitsGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); } diff --git a/AntiAirCraftGun/AntiAirCraftGun/Generics/ZenitsGenericCollection.cs b/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericCollection.cs similarity index 95% rename from AntiAirCraftGun/AntiAirCraftGun/Generics/ZenitsGenericCollection.cs rename to AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericCollection.cs index aa41922..20b9208 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/Generics/ZenitsGenericCollection.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericCollection.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace AntiAircraftGun.Generics { - internal class ZenitsGenericCollection + internal class AntiAirCraftGunGenericCollection where T : BaseDrawingAntiAirCraftGun where U : IMoveableObject { @@ -37,7 +37,7 @@ namespace AntiAircraftGun.Generics /// /// /// - public ZenitsGenericCollection(int picWidth, int picHeight) + public AntiAirCraftGunGenericCollection(int picWidth, int picHeight) { int width = picWidth / _placeSizeWidth; int height = picHeight / _placeSizeHeight; @@ -51,7 +51,7 @@ namespace AntiAircraftGun.Generics /// /// /// - public static bool operator +(ZenitsGenericCollection collect, T? + public static bool operator +(AntiAirCraftGunGenericCollection collect, T? obj) { if (obj == null) @@ -67,7 +67,7 @@ namespace AntiAircraftGun.Generics /// /// /// - public static T? operator -(ZenitsGenericCollection collect, int + public static T? operator -(AntiAirCraftGunGenericCollection collect, int pos) { T? obj = collect._collection.Get(pos); -- 2.25.1 From f36062d9d89bf2d09bcfbc25433adfadea9da283 Mon Sep 17 00:00:00 2001 From: YourDax Date: Mon, 30 Oct 2023 16:23:56 +0400 Subject: [PATCH 6/6] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AntiAirCraftGunGenericCollection.cs | 38 +++++++++++-------- .../AntiAirCraftGun/Generics/SetGeneric.cs | 16 ++++---- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericCollection.cs b/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericCollection.cs index 20b9208..3ff0441 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericCollection.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericCollection.cs @@ -51,32 +51,26 @@ namespace AntiAircraftGun.Generics /// /// /// - public static bool operator +(AntiAirCraftGunGenericCollection collect, T? - obj) + public static int operator +(AntiAirCraftGunGenericCollection collect, T? obj) { if (obj == null) - { - return false; - } - return collect?._collection.Insert(obj) ?? false; + return -1; + return collect?._collection.Insert(obj) ?? -1; } - /// /// Перегрузка оператора вычитания /// /// /// /// - public static T? operator -(AntiAirCraftGunGenericCollection collect, int - pos) + public static bool operator -(AntiAirCraftGunGenericCollection collect, int pos) { - T? obj = collect._collection.Get(pos); - if (obj != null) - { - collect._collection.Remove(pos); - } - return obj; + T? obj = collect._collection.Get(pos); + if (obj != null) + return collect._collection.Remove(pos); + return false; } + /// /// Получение объекта IMoveableObject /// @@ -156,9 +150,21 @@ namespace AntiAircraftGun.Generics if (y+distance_between_objects >= maxY) { y = 0; - x += obj.GetWidth+10 + distance_between_objects; + x += _placeSizeWidth; } } + if (obj == null) + { + // Увеличиваем координату Y для следующего объекта + y += distance_between_objects; + + // Проверяем, если Y достигло максимума, изменяем X и сбрасываем Y + if (y+distance_between_objects >= maxY) + { + y = 0; + x += _placeSizeWidth; + } + }; } } } diff --git a/AntiAirCraftGun/AntiAirCraftGun/Generics/SetGeneric.cs b/AntiAirCraftGun/AntiAirCraftGun/Generics/SetGeneric.cs index 017d217..bdfeac1 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/Generics/SetGeneric.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/Generics/SetGeneric.cs @@ -30,7 +30,7 @@ namespace AntiAircraftGun.Generics /// /// Добавляемый автомобиль /// - public bool Insert(T car) + public int Insert(T car) { // Вставка в начало набора for (int i = 0; i < _places.Length; i++) @@ -38,10 +38,10 @@ namespace AntiAircraftGun.Generics if (_places[i] == null) { _places[i] = car; - return true; + return 1; } } - return false; // Если нет пустых мест + return -1; // Если нет пустых мест } /// /// Добавление объекта в набор на конкретную позицию @@ -49,15 +49,15 @@ namespace AntiAircraftGun.Generics /// Добавляемый автомобиль /// Позиция /// - public bool Insert(T car, int position) + public int Insert(T car, int position) { // Проверка позиции if (position < 0 || position >= _places.Length) - return false; + return -1; // Проверка, что элемент массива по этой позиции пустой if (_places[position] != null) - return false; + return -1; // Проверка, что после вставляемого элемента в массиве есть пустой элемент for (int i = position + 1; i < _places.Length; i++) @@ -70,11 +70,11 @@ namespace AntiAircraftGun.Generics _places[j] = _places[j - 1]; } _places[position] = car; - return true; + return 1; } } - return false; // Если нет пустых мест справа + return -1; // Если нет пустых мест справа } /// /// Удаление объекта из набора с конкретной позиции -- 2.25.1