From 58cd3ac83eb0e9110a9931f30462308d65a76953 Mon Sep 17 00:00:00 2001 From: ivans Date: Tue, 26 Mar 2024 23:48:45 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= =?UTF-8?q?=20lab03?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 115 +++++++++++ .../ICollectionGenericObjects.cs | 48 +++++ .../MassiveGenericObjects.cs | 120 +++++++++++ .../CollectionGenericObjects/PlanePark.cs | 49 +++++ .../FormPlaneCollection.Designer.cs | 172 ++++++++++++++++ .../ProjectSeaplane/FormPlaneCollection.cs | 191 ++++++++++++++++++ .../ProjectSeaplane/FormPlaneCollection.resx | 120 +++++++++++ .../ProjectSeaplane/FormSeaplane.Designer.cs | 28 --- .../ProjectSeaplane/FormSeaplane.cs | 62 ++---- ProjectSeaplane/ProjectSeaplane/Program.cs | 2 +- 10 files changed, 829 insertions(+), 78 deletions(-) create mode 100644 ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/AbstractCompany.cs create mode 100644 ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ICollectionGenericObjects.cs create mode 100644 ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/MassiveGenericObjects.cs create mode 100644 ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/PlanePark.cs create mode 100644 ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs create mode 100644 ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs create mode 100644 ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.resx diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/AbstractCompany.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..5e45aef --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,115 @@ +using ProjectSeaplane.Drawnings; +namespace ProjectSeaplane.CollectionGenericObjects; + +/// +/// Абстракция компании, хранящий коллекцию автомобилей +/// +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 210; + + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 80; + + /// + /// Ширина окна + /// + protected readonly int _pictureWidth; + + /// + /// Высота окна + /// + protected readonly int _pictureHeight; + + /// + /// Коллекция cамолетов + /// + protected ICollectionGenericObjects? _collection = null; + + /// + /// Вычисление максимального количества элементов, который можно разместить в окне + /// + private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight); + + /// + /// Конструктор + /// + /// Ширина окна + /// Высота окна + /// Коллекция самолетов + public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection) + { + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = collection; + _collection.SetMaxCount = GetMaxCount; + } + + /// + /// Перегрузка оператора сложения для класса + /// + /// Компания + /// Добавляемый объект + /// + public static int operator +(AbstractCompany company, DrawingBasicSeaplane seaplane) + { + return company._collection.Insert(seaplane); + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawingBasicSeaplane operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position); + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawingBasicSeaplane? GetRandomObject() + { + Random rnd = new(); + return _collection?.Get(rnd.Next(GetMaxCount)); + } + + /// + /// Вывод всей коллекции + /// + /// + public Bitmap? Show() + { + Bitmap bitmap = new(_pictureWidth, _pictureHeight); + Graphics graphics = Graphics.FromImage(bitmap); + DrawBackgound(graphics); + + SetObjectsPosition(); + for (int i = 0; i < (_collection?.Count ?? 0); ++i) + { + DrawingBasicSeaplane? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + + return bitmap; + } + + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..d27a8ef --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,48 @@ +namespace ProjectSeaplane.CollectionGenericObjects; + +/// +/// Интерфейс описания действий для набора хранимых объектов +/// +/// Параметр: ограничение - ссылочный тип +public interface ICollectionGenericObjects + where T : class +{ + /// + /// Количество объектов в коллекции + /// + int Count { get; } + + /// + /// Установка максимального количества элементов + /// + int SetMaxCount { set; } + + /// + /// Добавление объекта в коллекцию + /// + /// Добавляемый объект + /// true - вставка прошла удачно, false - вставка не удалась + int Insert(T obj); + + /// + /// Добавление объекта в коллекцию на конкретную позицию + /// + /// Добавляемый объект + /// Позиция + /// true - вставка прошла удачно, false - вставка не удалась + int Insert(T obj, int position); + + /// + /// Удаление объекта из коллекции с конкретной позиции + /// + /// Позиция + /// true - удаление прошло удачно, false - удаление не удалось + T Remove(int position); + + /// + /// Получение объекта по позиции + /// + /// Позиция + /// Объект + T? Get(int position); +} \ No newline at end of file diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..209e421 --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,120 @@ +namespace ProjectSeaplane.CollectionGenericObjects; + +/// +/// Параметризованный набор объектов +/// +/// Параметр: ограничение - ссылочный тип +public class MassiveGenericObjects : ICollectionGenericObjects + where T : class +{ + /// + /// массив объектов, которые храним + /// + private T?[] _collection; + public int Count => _collection.Length; + + public int SetMaxCount + { + set + { + if (value > 0) + { + if (_collection.Length > 0) + { + Array.Resize(ref _collection, value); + } + else + { + _collection = new T?[value]; + } + } + } + } + + /// + /// Конструктор + /// + public MassiveGenericObjects() + { + _collection = Array.Empty(); + } + + public T? Get(int position) + { + // TODO проверка позиции + if (position >= _collection.Length || position < 0) + { + return null; + } + return _collection[position]; + } + + public int Insert(T obj) + { + // TODO вставка в свободное место набора + int index = 0; + while (index < _collection.Length) + { + if (_collection[index] == null) + { + _collection[index] = obj; + return index; + } + + index++; + } + return -1; + } + + public int Insert(T obj, int position) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, если нет, то + // ищется свободное место после этой позиции и идет вставка туда + // если нет после, ищем до + // TODO вставка + if (position >= _collection.Length || position < 0) + { + return -1; + } + + if (_collection[position] == null) + { + _collection[position] = obj; + return position; + } + int index; + + for (index = position + 1; index < _collection.Length; ++index) + { + if (_collection[index] == null) + { + _collection[position] = obj; + return position; + } + } + + for (index = position - 1; index >= 0; --index) + { + if (_collection[index] == null) + { + _collection[position] = obj; + return position; + } + } + return -1; + } + + public T Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присвоив элементу массива значение null + if (position >= _collection.Length || position < 0) + { + return null; + } + T obj = _collection[position]; + _collection[position] = null; + return obj; + } +} \ No newline at end of file diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/PlanePark.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/PlanePark.cs new file mode 100644 index 0000000..e11a5ef --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/PlanePark.cs @@ -0,0 +1,49 @@ +using ProjectSeaplane.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectSeaplane.CollectionGenericObjects; + +public class PlanePark : AbstractCompany +{ + /// + /// Конструктор + /// + /// + /// + /// + public PlanePark(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + protected override void DrawBackgound(Graphics g) + { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + Pen pen = new(Color.Black, 3); + for (int i = 0; i < width; i++) + { + for (int j = 0; j < height + 1; ++j) + { + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 15, j * _placeSizeHeight); + } + } + } + + protected override void SetObjectsPosition() + { + int count = 0; + for (int y = 5; y + 50 < _pictureHeight; y += 90) + { + for (int x = 5; x + 200 < _pictureWidth; x += _placeSizeHeight + 90) + { + _collection?.Get(count)?.SetPictureSize(_pictureWidth, _pictureHeight); + _collection?.Get(count)?.SetPosition(x, y); + count++; + } + } + } +} diff --git a/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs new file mode 100644 index 0000000..6c71bd9 --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs @@ -0,0 +1,172 @@ +namespace ProjectSeaplane +{ + partial class FormPlaneCollection + { + /// + /// 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() + { + groupBoxTools = new GroupBox(); + buttonRefresh = new Button(); + buttonGoToCheck = new Button(); + buttonDelSeaplane = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonAddSeaplane = new Button(); + buttonAddBasicSeaplane = new Button(); + comboBoxSelectorCompany = new ComboBox(); + pictureBox = new PictureBox(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(buttonRefresh); + groupBoxTools.Controls.Add(buttonGoToCheck); + groupBoxTools.Controls.Add(buttonDelSeaplane); + groupBoxTools.Controls.Add(maskedTextBox); + groupBoxTools.Controls.Add(buttonAddSeaplane); + groupBoxTools.Controls.Add(buttonAddBasicSeaplane); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(872, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(180, 579); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.FlatStyle = FlatStyle.Flat; + buttonRefresh.Location = new Point(6, 474); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(168, 43); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.FlatStyle = FlatStyle.Flat; + buttonGoToCheck.Location = new Point(6, 353); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(168, 43); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + // + // buttonDelSeaplane + // + buttonDelSeaplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonDelSeaplane.FlatStyle = FlatStyle.Flat; + buttonDelSeaplane.Location = new Point(6, 249); + buttonDelSeaplane.Name = "buttonDelSeaplane"; + buttonDelSeaplane.Size = new Size(168, 43); + buttonDelSeaplane.TabIndex = 4; + buttonDelSeaplane.Text = "Удалить самолет"; + buttonDelSeaplane.UseVisualStyleBackColor = true; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(6, 220); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(168, 23); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonAddSeaplane + // + buttonAddSeaplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddSeaplane.FlatStyle = FlatStyle.Flat; + buttonAddSeaplane.Location = new Point(6, 135); + buttonAddSeaplane.Name = "buttonAddSeaplane"; + buttonAddSeaplane.Size = new Size(168, 43); + buttonAddSeaplane.TabIndex = 2; + buttonAddSeaplane.Text = "Добавление гидросамолета"; + buttonAddSeaplane.UseVisualStyleBackColor = true; + // + // buttonAddBasicSeaplane + // + buttonAddBasicSeaplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddBasicSeaplane.FlatStyle = FlatStyle.Flat; + buttonAddBasicSeaplane.Location = new Point(6, 86); + buttonAddBasicSeaplane.Name = "buttonAddBasicSeaplane"; + buttonAddBasicSeaplane.Size = new Size(168, 43); + buttonAddBasicSeaplane.TabIndex = 1; + buttonAddBasicSeaplane.Text = "Добавление самолета"; + buttonAddBasicSeaplane.UseVisualStyleBackColor = true; + // + // comboBoxSelectorCompany + // + comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectorCompany.FormattingEnabled = true; + comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); + comboBoxSelectorCompany.Location = new Point(6, 22); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(168, 23); + comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += СomboBoxSelectorCompany_SelectedIndexChanged; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(872, 579); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormPlaneCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1052, 579); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormPlaneCollection"; + Text = "Коллекция самолетов"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private Button buttonAddBasicSeaplane; + private ComboBox comboBoxSelectorCompany; + private Button buttonAddSeaplane; + private Button buttonGoToCheck; + private Button buttonDelSeaplane; + private MaskedTextBox maskedTextBox; + private PictureBox pictureBox; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs new file mode 100644 index 0000000..db0b9a7 --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs @@ -0,0 +1,191 @@ +using ProjectSeaplane.CollectionGenericObjects; +using ProjectSeaplane.Drawnings; +namespace ProjectSeaplane; + +/// +/// Форма работы с компанией и ее коллекцией +/// +public partial class FormPlaneCollection : Form +{ + /// + /// Компания + /// + AbstractCompany? _company = null; + + /// + /// Конструктор + /// + public FormPlaneCollection() + { + InitializeComponent(); + } + + /// + /// Выбор компании + /// + /// + /// + private void СomboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new PlanePark(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + + } + + /// + /// Добавление обычного самолета + /// + /// + /// + private void ButtonAddBasicSeaplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingBasicSeaplane)); + + /// + /// Добавление гидросамолета + /// + /// + /// + private void ButtonAddSeaplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingSeaplane)); + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + + Random random = new(); + DrawingBasicSeaplane drawingBasicSeaplane; + switch (type) + { + case nameof(DrawingBasicSeaplane): + drawingBasicSeaplane = new DrawingBasicSeaplane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawingSeaplane): + // TODO вызов диалогового окна для выбора цвета + drawingBasicSeaplane = new DrawingSeaplane(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)), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + break; + default: + return; + } + + if (_company + drawingBasicSeaplane != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + + /// + /// Получение цвета + /// + /// Генератор случайных чисел + /// + private static Color GetColor(Random random) + { + 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; + } + + return color; + } + + /// + /// Удаление объекта + /// + /// + /// + private void ButtonnDelSeaplane_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) + { + return; + } + + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + + int pos = Convert.ToInt32(maskedTextBox.Text); + if (_company - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + /// + /// Передача объекта в другую форму + /// + /// + /// + private void ButtonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + DrawingBasicSeaplane? seaplane = null; + int counter = 100; + while (seaplane == null) + { + seaplane = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (seaplane == null) + { + return; + } + + FormSeaplane form = new() + { + SetSeaplane = seaplane + }; + form.ShowDialog(); + } + + /// + /// Перерисовка коллекции + /// + /// + /// + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + } + + +} diff --git a/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.resx b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.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/ProjectSeaplane/ProjectSeaplane/FormSeaplane.Designer.cs b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.Designer.cs index c496ad8..b17b242 100644 --- a/ProjectSeaplane/ProjectSeaplane/FormSeaplane.Designer.cs +++ b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.Designer.cs @@ -29,12 +29,10 @@ private void InitializeComponent() { pictureBoxSeaplane = new PictureBox(); - ButtonCreateSeaplane = new Button(); buttonLeft = new Button(); buttonDown = new Button(); buttonUp = new Button(); buttonRight = new Button(); - ButtonCreateBasicSeaplane = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxSeaplane).BeginInit(); @@ -49,17 +47,6 @@ pictureBoxSeaplane.TabIndex = 0; pictureBoxSeaplane.TabStop = false; // - // ButtonCreateSeaplane - // - ButtonCreateSeaplane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - ButtonCreateSeaplane.Location = new Point(12, 349); - ButtonCreateSeaplane.Name = "ButtonCreateSeaplane"; - ButtonCreateSeaplane.Size = new Size(256, 23); - ButtonCreateSeaplane.TabIndex = 1; - ButtonCreateSeaplane.Text = "Создать гидросамолет с обвесами"; - ButtonCreateSeaplane.UseVisualStyleBackColor = true; - ButtonCreateSeaplane.Click += ButtonCreateSeaplane_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -112,17 +99,6 @@ buttonRight.UseVisualStyleBackColor = false; buttonRight.Click += ButtonMove_Click; // - // ButtonCreateBasicSeaplane - // - ButtonCreateBasicSeaplane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - ButtonCreateBasicSeaplane.Location = new Point(288, 349); - ButtonCreateBasicSeaplane.Name = "ButtonCreateBasicSeaplane"; - ButtonCreateBasicSeaplane.Size = new Size(234, 23); - ButtonCreateBasicSeaplane.TabIndex = 8; - ButtonCreateBasicSeaplane.Text = "Создать гидросамолет без обвесов"; - ButtonCreateBasicSeaplane.UseVisualStyleBackColor = true; - ButtonCreateBasicSeaplane.Click += ButtonCreateBasicSeaplane_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -150,12 +126,10 @@ ClientSize = new Size(757, 379); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(ButtonCreateBasicSeaplane); Controls.Add(buttonRight); Controls.Add(buttonUp); Controls.Add(buttonDown); Controls.Add(buttonLeft); - Controls.Add(ButtonCreateSeaplane); Controls.Add(pictureBoxSeaplane); Name = "FormSeaplane"; Text = "Гидросамолет"; @@ -166,12 +140,10 @@ #endregion private PictureBox pictureBoxSeaplane; - private Button ButtonCreateSeaplane; private Button buttonLeft; private Button buttonDown; private Button buttonUp; private Button buttonRight; - private Button ButtonCreateBasicSeaplane; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs index 485c1b8..af233c0 100644 --- a/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs +++ b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs @@ -27,6 +27,17 @@ namespace ProjectSeaplane /// /// Метод прорисовки самолета /// + public DrawingBasicSeaplane SetSeaplane + { + set + { + _drawingSeaplane = value; + _drawingSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } private void Draw() { if (_drawingSeaplane == null) @@ -39,54 +50,7 @@ namespace ProjectSeaplane _drawingSeaplane.DrawTransport(gr); pictureBoxSeaplane.Image = bmp; } - /// - /// Обработка нажатия кнопки "Создать" - /// - /// - /// - - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawingBasicSeaplane): - _drawingSeaplane = new DrawingBasicSeaplane(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); - break; - case nameof(DrawingSeaplane): - _drawingSeaplane = new DrawingSeaplane(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)), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - break; - default: - return; - } - _drawingSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); - _drawingSeaplane.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - /// - /// Обработка нажатия кнопки "Создать гидросамолет с обвесами" - /// - /// - /// - private void ButtonCreateSeaplane_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawingSeaplane)); - } - /// - /// Обработка нажатия кнопки "Создать гидросамолет без обвесов" - /// - /// - /// - private void ButtonCreateBasicSeaplane_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawingBasicSeaplane)); - } + /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// @@ -163,7 +127,7 @@ namespace ProjectSeaplane comboBoxStrategy.Enabled = true; _strategy = null; } - + } } } diff --git a/ProjectSeaplane/ProjectSeaplane/Program.cs b/ProjectSeaplane/ProjectSeaplane/Program.cs index 4e58da8..0b08fb7 100644 --- a/ProjectSeaplane/ProjectSeaplane/Program.cs +++ b/ProjectSeaplane/ProjectSeaplane/Program.cs @@ -11,7 +11,7 @@ namespace ProjectSeaplane // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormSeaplane()); + Application.Run(new FormPlaneCollection()); } } } \ No newline at end of file -- 2.25.1 From 49024c4c176daa2bb2849cb7f49af146bbc255ab Mon Sep 17 00:00:00 2001 From: 357Sharonov Date: Wed, 27 Mar 2024 13:59:35 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D0=BB=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B103?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 4 +- .../CollectionGenericObjects/PlanePark.cs | 30 ++++++++++----- .../FormPlaneCollection.Designer.cs | 38 +++++++++++-------- .../ProjectSeaplane/FormPlaneCollection.cs | 10 +++-- 4 files changed, 50 insertions(+), 32 deletions(-) diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/AbstractCompany.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/AbstractCompany.cs index 5e45aef..0249924 100644 --- a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/AbstractCompany.cs @@ -9,12 +9,12 @@ public abstract class AbstractCompany /// /// Размер места (ширина) /// - protected readonly int _placeSizeWidth = 210; + protected readonly int _placeSizeWidth = 180; /// /// Размер места (высота) /// - protected readonly int _placeSizeHeight = 80; + protected readonly int _placeSizeHeight = 100; /// /// Ширина окна diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/PlanePark.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/PlanePark.cs index e11a5ef..28dcb2d 100644 --- a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/PlanePark.cs +++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/PlanePark.cs @@ -21,28 +21,38 @@ public class PlanePark : AbstractCompany protected override void DrawBackgound(Graphics g) { - int width = _pictureWidth / _placeSizeWidth; - int height = _pictureHeight / _placeSizeHeight; - Pen pen = new(Color.Black, 3); - for (int i = 0; i < width; i++) + int width = _pictureWidth - 1; + int height = _pictureHeight / 2; + Pen pen = new(Color.RosyBrown, 3); + + g.DrawLine(pen, width, height, 5, height); + g.DrawLine(pen, width, height - 100, 5, height - 100); + Pen pen2 = new(Color.Black, 3); + for (int i = 0; i < _pictureWidth; i+=50) { - for (int j = 0; j < height + 1; ++j) - { - g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 15, j * _placeSizeHeight); - } + g.DrawLine(pen2, width-i, height - 50, width - (i+30), height -50); } + } protected override void SetObjectsPosition() { + int count = 0; - for (int y = 5; y + 50 < _pictureHeight; y += 90) + int megacount = 0; + for (int y = _pictureHeight - 100; y - 50 > 0; y -= 100) { - for (int x = 5; x + 200 < _pictureWidth; x += _placeSizeHeight + 90) + megacount++; + if (y < _pictureHeight / 2 && y > (_pictureHeight / 2) - 100) + { + y -= 200; + } + for (int x = _pictureWidth - 200; x - 120 > 0; x -= _placeSizeHeight + 75) { _collection?.Get(count)?.SetPictureSize(_pictureWidth, _pictureHeight); _collection?.Get(count)?.SetPosition(x, y); count++; + } } } diff --git a/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs index 6c71bd9..523d962 100644 --- a/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs +++ b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs @@ -35,7 +35,7 @@ maskedTextBox = new MaskedTextBox(); buttonAddSeaplane = new Button(); buttonAddBasicSeaplane = new Button(); - comboBoxSelectorCompany = new ComboBox(); + СomboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); groupBoxTools.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); @@ -49,11 +49,11 @@ groupBoxTools.Controls.Add(maskedTextBox); groupBoxTools.Controls.Add(buttonAddSeaplane); groupBoxTools.Controls.Add(buttonAddBasicSeaplane); - groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Controls.Add(СomboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(872, 0); + groupBoxTools.Location = new Point(854, 0); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(180, 579); + groupBoxTools.Size = new Size(180, 398); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; @@ -68,6 +68,7 @@ buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; // // buttonGoToCheck // @@ -79,6 +80,7 @@ buttonGoToCheck.TabIndex = 5; buttonGoToCheck.Text = "Передать на тесты"; buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; // // buttonDelSeaplane // @@ -90,6 +92,7 @@ buttonDelSeaplane.TabIndex = 4; buttonDelSeaplane.Text = "Удалить самолет"; buttonDelSeaplane.UseVisualStyleBackColor = true; + buttonDelSeaplane.Click += ButtonnDelSeaplane_Click; // // maskedTextBox // @@ -110,6 +113,7 @@ buttonAddSeaplane.TabIndex = 2; buttonAddSeaplane.Text = "Добавление гидросамолета"; buttonAddSeaplane.UseVisualStyleBackColor = true; + buttonAddSeaplane.Click += ButtonAddSeaplane_Click; // // buttonAddBasicSeaplane // @@ -121,24 +125,25 @@ buttonAddBasicSeaplane.TabIndex = 1; buttonAddBasicSeaplane.Text = "Добавление самолета"; buttonAddBasicSeaplane.UseVisualStyleBackColor = true; + buttonAddBasicSeaplane.Click += ButtonAddBasicSeaplane_Click; // - // comboBoxSelectorCompany + // СomboBoxSelectorCompany // - comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - comboBoxSelectorCompany.FormattingEnabled = true; - comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(6, 22); - comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; - comboBoxSelectorCompany.Size = new Size(168, 23); - comboBoxSelectorCompany.TabIndex = 0; - comboBoxSelectorCompany.SelectedIndexChanged += СomboBoxSelectorCompany_SelectedIndexChanged; + СomboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + СomboBoxSelectorCompany.FormattingEnabled = true; + СomboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); + СomboBoxSelectorCompany.Location = new Point(6, 22); + СomboBoxSelectorCompany.Name = "СomboBoxSelectorCompany"; + СomboBoxSelectorCompany.Size = new Size(168, 23); + СomboBoxSelectorCompany.TabIndex = 0; + СomboBoxSelectorCompany.SelectedIndexChanged += СomboBoxSelectorCompany_SelectedIndexChanged; // // pictureBox // pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(872, 579); + pictureBox.Size = new Size(854, 398); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // @@ -146,11 +151,12 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1052, 579); + ClientSize = new Size(1034, 398); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Name = "FormPlaneCollection"; Text = "Коллекция самолетов"; + Load += FormPlaneCollection_Load; groupBoxTools.ResumeLayout(false); groupBoxTools.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); @@ -161,7 +167,7 @@ private GroupBox groupBoxTools; private Button buttonAddBasicSeaplane; - private ComboBox comboBoxSelectorCompany; + private ComboBox СomboBoxSelectorCompany; private Button buttonAddSeaplane; private Button buttonGoToCheck; private Button buttonDelSeaplane; diff --git a/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs index db0b9a7..8077c5b 100644 --- a/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs +++ b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs @@ -27,13 +27,13 @@ public partial class FormPlaneCollection : Form /// private void СomboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) + switch (СomboBoxSelectorCompany.Text) { case "Хранилище": _company = new PlanePark(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); break; } - + } /// @@ -71,8 +71,7 @@ public partial class FormPlaneCollection : Form case nameof(DrawingSeaplane): // TODO вызов диалогового окна для выбора цвета drawingBasicSeaplane = new DrawingSeaplane(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)), + GetColor(random), GetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; default: @@ -187,5 +186,8 @@ public partial class FormPlaneCollection : Form pictureBox.Image = _company.Show(); } + private void FormPlaneCollection_Load(object sender, EventArgs e) + { + } } -- 2.25.1