From d17975562c5fbf8201c44da0fb13a21f13c4e859 Mon Sep 17 00:00:00 2001 From: YourDax Date: Fri, 13 Oct 2023 02:51:58 +0400 Subject: [PATCH] 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