From 98990e36de270fa21c7c50c01612543700c0fdd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BA=D1=80=D0=B8=D1=81=D1=82=D0=B8=D0=BD=D0=B0=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B2=D1=80=D0=BE=D0=B2=D0=B0?= Date: Wed, 24 Apr 2024 22:45:48 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BC=D0=BF=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 100 +++++++++ .../ICollectionGenericObjects.cs | 0 .../MassiveGenericObjects.cs | 0 .../TrackedVehicleSharingService.cs | 62 ++++++ .../lab1/Drawnings/DrawningEntityFighter.cs | 49 +---- .../lab1/Drawnings/DrawningTrackedVehicle.cs | 2 +- solution/lab1/FormFighter.Designer.cs | 28 --- solution/lab1/FormFighter.cs | 71 ++---- .../FormTrackedVehicleCollection.Designer.cs | 176 +++++++++++++++ solution/lab1/FormTrackedVehicleCollection.cs | 204 ++++++++++++++++++ .../lab1/FormTrackedVehicleCollection.resx | 120 +++++++++++ solution/lab1/Program.cs | 2 +- 12 files changed, 686 insertions(+), 128 deletions(-) create mode 100644 solution/lab1/CollectionGenericObjects/AbstractCompany.cs rename solution/lab1/CollectionGenericObjects/{CollectionGenericObjects => }/ICollectionGenericObjects.cs (100%) rename solution/lab1/CollectionGenericObjects/{CollectionGenericObjects => }/MassiveGenericObjects.cs (100%) create mode 100644 solution/lab1/CollectionGenericObjects/TrackedVehicleSharingService.cs create mode 100644 solution/lab1/FormTrackedVehicleCollection.Designer.cs create mode 100644 solution/lab1/FormTrackedVehicleCollection.cs create mode 100644 solution/lab1/FormTrackedVehicleCollection.resx diff --git a/solution/lab1/CollectionGenericObjects/AbstractCompany.cs b/solution/lab1/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..04e7849 --- /dev/null +++ b/solution/lab1/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,100 @@ +using lab1.Drawnings; + +namespace lab1.CollectionGenericObjects; + +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 210; + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 80; + /// + /// Ширина окна + /// + protected readonly int _pictureWidth; + /// + /// Высота окна + /// + protected readonly int _pictureHeight; + /// + /// Коллекция гусеничных машин + /// + 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, DrawningTrackedVehicle trackedVehicle) + { + return company._collection.Insert(trackedVehicle); + } + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawningTrackedVehicle operator -(AbstractCompany company, int position) + { + return company._collection.Remove(position); + } + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningTrackedVehicle? 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) + { + DrawningTrackedVehicle? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + return bitmap; + } + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics graphics); + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} diff --git a/solution/lab1/CollectionGenericObjects/CollectionGenericObjects/ICollectionGenericObjects.cs b/solution/lab1/CollectionGenericObjects/ICollectionGenericObjects.cs similarity index 100% rename from solution/lab1/CollectionGenericObjects/CollectionGenericObjects/ICollectionGenericObjects.cs rename to solution/lab1/CollectionGenericObjects/ICollectionGenericObjects.cs diff --git a/solution/lab1/CollectionGenericObjects/CollectionGenericObjects/MassiveGenericObjects.cs b/solution/lab1/CollectionGenericObjects/MassiveGenericObjects.cs similarity index 100% rename from solution/lab1/CollectionGenericObjects/CollectionGenericObjects/MassiveGenericObjects.cs rename to solution/lab1/CollectionGenericObjects/MassiveGenericObjects.cs diff --git a/solution/lab1/CollectionGenericObjects/TrackedVehicleSharingService.cs b/solution/lab1/CollectionGenericObjects/TrackedVehicleSharingService.cs new file mode 100644 index 0000000..a7432ea --- /dev/null +++ b/solution/lab1/CollectionGenericObjects/TrackedVehicleSharingService.cs @@ -0,0 +1,62 @@ +using lab1.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace lab1.CollectionGenericObjects; + +public class TrackedVehicleSharingService : AbstractCompany +{ + public TrackedVehicleSharingService(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, 2); + for (int i = 0; i < width; i++) + { + for (int j = 0; j < height + 1; ++j) + { + g.DrawLine(pen, i * _placeSizeWidth + 15, j * _placeSizeHeight, i * _placeSizeWidth + 15 + _placeSizeWidth - 55, j * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth + 15, j * _placeSizeHeight, i * _placeSizeWidth + 15, j * _placeSizeHeight - _placeSizeHeight); + } + } + } + /// + /// Расстановка объектов + /// + protected override void SetObjectsPosition() + { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + int curWidth = width - 1; + int curHeight = 0; + for (int i = 0; i < (_collection?.Count ?? 0); i++) + { + if (_collection.Get(i) != null) + { + _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); + _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 45, curHeight * _placeSizeHeight + 30); + } + if (curWidth > 0) + curWidth--; + else + { + curWidth = width - 1; + curHeight++; + } + if (curHeight > height) + { + return; + } + } + } +} diff --git a/solution/lab1/Drawnings/DrawningEntityFighter.cs b/solution/lab1/Drawnings/DrawningEntityFighter.cs index 06c557a..56e5816 100644 --- a/solution/lab1/Drawnings/DrawningEntityFighter.cs +++ b/solution/lab1/Drawnings/DrawningEntityFighter.cs @@ -28,57 +28,11 @@ public class DrawningEntityFighter : DrawningTrackedVehicle return; } Pen pen = new(Color.Black); - Brush additionalBrush = new SolidBrush(fighter.AdditionalColor); - Brush BodyBrush = new SolidBrush(fighter.BodyColor); Brush CraneBrush = new SolidBrush(fighter.AdditionalColor); - //корпус - g.FillRectangle(BodyBrush, _startPosX.Value + 10, _startPosY.Value + 30, 62, 12); - g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 30, 62, 12); - g.FillRectangle(BodyBrush, _startPosX.Value + 22, _startPosY.Value + 16, 4, 15); - g.DrawRectangle(pen, _startPosX.Value + 22, _startPosY.Value + 16, 4, 14); - g.FillRectangle(BodyBrush, _startPosX.Value + 37, _startPosY.Value + 1, 5, 30); - g.DrawRectangle(pen, _startPosX.Value + 37, _startPosY.Value + 1, 5, 30); + - //стекло - g.FillRectangle(additionalBrush, _startPosX.Value + 52, _startPosY.Value + 14, 21, 16); - g.DrawRectangle(pen, _startPosX.Value + 52, _startPosY.Value + 14, 20, 16); - - //гусеницы - g.DrawLine(pen, _startPosX.Value + 8, _startPosY.Value + 42, _startPosX.Value + 10, _startPosY.Value + 42); - g.DrawLine(pen, _startPosX.Value + 7, _startPosY.Value + 43, _startPosX.Value + 7, _startPosY.Value + 53); - g.DrawLine(pen, _startPosX.Value + 8, _startPosY.Value + 54, _startPosX.Value + 12, _startPosY.Value + 54); - g.DrawLine(pen, _startPosX.Value + 13, _startPosY.Value + 55, _startPosX.Value + 69, _startPosY.Value + 55); - g.DrawLine(pen, _startPosX.Value + 70, _startPosY.Value + 54, _startPosX.Value + 73, _startPosY.Value + 54); - g.DrawLine(pen, _startPosX.Value + 74, _startPosY.Value + 53, _startPosX.Value + 74, _startPosY.Value + 43); - g.DrawLine(pen, _startPosX.Value + 71, _startPosY.Value + 42, _startPosX.Value + 73, _startPosY.Value + 42); - - //колеса - g.FillEllipse(BodyBrush, _startPosX.Value + 10, _startPosY.Value + 44, 9, 9); - g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 44, 9, 9); - g.FillEllipse(BodyBrush, _startPosX.Value + 63, _startPosY.Value + 44, 9, 9); - g.DrawEllipse(pen, _startPosX.Value + 63, _startPosY.Value + 44, 9, 9); - - g.FillEllipse(BodyBrush, _startPosX.Value + 25, _startPosY.Value + 48, 6, 6); - g.DrawEllipse(pen, _startPosX.Value + 25, _startPosY.Value + 48, 6, 6); - g.FillEllipse(BodyBrush, _startPosX.Value + 38, _startPosY.Value + 48, 6, 6); - g.DrawEllipse(pen, _startPosX.Value + 38, _startPosY.Value + 48, 6, 6); - g.FillEllipse(BodyBrush, _startPosX.Value + 50, _startPosY.Value + 48, 6, 6); - g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 48, 6, 6); - - g.FillEllipse(BodyBrush, _startPosX.Value + 33, _startPosY.Value + 44, 4, 4); - g.DrawEllipse(pen, _startPosX.Value + 33, _startPosY.Value + 44, 4, 4); - g.FillEllipse(BodyBrush, _startPosX.Value + 45, _startPosY.Value + 44, 4, 4); - g.DrawEllipse(pen, _startPosX.Value + 45, _startPosY.Value + 44, 4, 4); - - - - _startPosX += 10; - _startPosY += 25; - base.DrawTransport(g); - _startPosX -= 10; - _startPosY -= 25; if (fighter.Kovsh) { @@ -98,7 +52,6 @@ public class DrawningEntityFighter : DrawningTrackedVehicle } - } } diff --git a/solution/lab1/Drawnings/DrawningTrackedVehicle.cs b/solution/lab1/Drawnings/DrawningTrackedVehicle.cs index e8f7e0e..75d7c0d 100644 --- a/solution/lab1/Drawnings/DrawningTrackedVehicle.cs +++ b/solution/lab1/Drawnings/DrawningTrackedVehicle.cs @@ -99,7 +99,7 @@ public class DrawningTrackedVehicle /// >Высота прорисовки истребителя - protected DrawningTrackedVehicle(int drawningFighterWidth, int drawningFighterHeight) : this() + protected DrawningTrackedVehicle(int drawningFighterWidth, int drawningFighterHeight) : this() { _drawningFighterWidth = drawningFighterWidth; _drawningFighterHeight = drawningFighterHeight; diff --git a/solution/lab1/FormFighter.Designer.cs b/solution/lab1/FormFighter.Designer.cs index ce7b400..e894ad6 100644 --- a/solution/lab1/FormFighter.Designer.cs +++ b/solution/lab1/FormFighter.Designer.cs @@ -29,12 +29,10 @@ private void InitializeComponent() { pictureBoxFighter = new PictureBox(); - buttonCreate = new Button(); buttonLeft = new Button(); buttonDown = new Button(); buttonUp = new Button(); buttonRight = new Button(); - buttonCreateTrackedVehicle = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxFighter).BeginInit(); @@ -50,17 +48,6 @@ pictureBoxFighter.TabStop = false; pictureBoxFighter.Click += pictureBoxFighter_Click; // - // buttonCreate - // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(12, 538); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(226, 34); - buttonCreate.TabIndex = 1; - buttonCreate.Text = "создать истребитель"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += ButtonCreate_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -113,17 +100,6 @@ buttonRight.UseVisualStyleBackColor = false; buttonRight.Click += ButtonMove_Click; // - // buttonCreateTrackedVehicle - // - buttonCreateTrackedVehicle.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateTrackedVehicle.Location = new Point(234, 538); - buttonCreateTrackedVehicle.Name = "buttonCreateTrackedVehicle"; - buttonCreateTrackedVehicle.Size = new Size(264, 34); - buttonCreateTrackedVehicle.TabIndex = 6; - buttonCreateTrackedVehicle.Text = "создать гусеничную машину"; - buttonCreateTrackedVehicle.UseVisualStyleBackColor = true; - buttonCreateTrackedVehicle.Click += ButtonCreateTrackedVehicle_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -151,12 +127,10 @@ ClientSize = new Size(1164, 584); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateTrackedVehicle); Controls.Add(buttonRight); Controls.Add(buttonUp); Controls.Add(buttonDown); Controls.Add(buttonLeft); - Controls.Add(buttonCreate); Controls.Add(pictureBoxFighter); Name = "FormFighter"; Text = "Истребитель"; @@ -168,12 +142,10 @@ #endregion private PictureBox pictureBoxFighter; - private Button buttonCreate; private Button buttonLeft; private Button buttonDown; private Button buttonUp; private Button buttonRight; - private Button buttonCreateTrackedVehicle; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/solution/lab1/FormFighter.cs b/solution/lab1/FormFighter.cs index bd91746..c048d07 100644 --- a/solution/lab1/FormFighter.cs +++ b/solution/lab1/FormFighter.cs @@ -17,11 +17,30 @@ namespace lab1; public partial class FormFighter : Form { + /// + /// Поле-объект для прорисовки объекта + /// private DrawningTrackedVehicle? _drawningTrackedVehicle; /// /// Стратегия перемещения /// private AbstractSrategy? _strategy; + + /// + /// Получение объекта + /// + public DrawningTrackedVehicle SetTrackedVehicle + { + set + { + _drawningTrackedVehicle = value; + _drawningTrackedVehicle = value; + _drawningTrackedVehicle.SetPictureSize(pictureBoxFighter.Width, pictureBoxFighter.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } public FormFighter() { InitializeComponent(); @@ -42,62 +61,14 @@ public partial class FormFighter : Form pictureBoxFighter.Image = bmp; } - /// - /// Создание объекта класса-перемещения - /// - /// - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningTrackedVehicle): - _drawningTrackedVehicle = new DrawningTrackedVehicle(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(DrawningEntityFighter): - _drawningTrackedVehicle = new DrawningEntityFighter(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; - - } - _drawningTrackedVehicle.SetPictureSize(pictureBoxFighter.Width, pictureBoxFighter.Height); - _drawningTrackedVehicle.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - - Draw(); - } - + /// - /// Обработка нажатия кнопки "Создать истребитель" + /// Перемещение объекта по форме (нажатие кнопок навигации) /// /// /// - private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningEntityFighter)); - - - /// - /// Обработка нажатия кнопки "Создать гусеничную машину" - /// - /// - /// - private void ButtonCreateTrackedVehicle_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedVehicle)); - - - - - - - - - - private void ButtonMove_Click(object sender, EventArgs e) { if (_drawningTrackedVehicle == null) diff --git a/solution/lab1/FormTrackedVehicleCollection.Designer.cs b/solution/lab1/FormTrackedVehicleCollection.Designer.cs new file mode 100644 index 0000000..a1ab031 --- /dev/null +++ b/solution/lab1/FormTrackedVehicleCollection.Designer.cs @@ -0,0 +1,176 @@ +namespace lab1 +{ + partial class FormTrackedVehicleCollection + { + /// + /// 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(); + buttonRemoveTrackedVehicle = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonAddTrackedVehicle = new Button(); + buttonAddFighter = 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(buttonRemoveTrackedVehicle); + groupBoxTools.Controls.Add(maskedTextBox); + groupBoxTools.Controls.Add(buttonAddTrackedVehicle); + groupBoxTools.Controls.Add(buttonAddFighter); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(886, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(297, 617); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(7, 516); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(284, 53); + buttonRefresh.TabIndex = 7; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click_1; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(5, 457); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(286, 53); + buttonGoToCheck.TabIndex = 6; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += button1_Click; + // + // buttonRemoveTrackedVehicle + // + buttonRemoveTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveTrackedVehicle.Location = new Point(5, 342); + buttonRemoveTrackedVehicle.Name = "buttonRemoveTrackedVehicle"; + buttonRemoveTrackedVehicle.Size = new Size(286, 82); + buttonRemoveTrackedVehicle.TabIndex = 5; + buttonRemoveTrackedVehicle.Text = "Удаление гусеничной машины"; + buttonRemoveTrackedVehicle.UseVisualStyleBackColor = true; + buttonRemoveTrackedVehicle.Click += ButtonRemoveTrackedVehicle_Click; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(7, 305); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(284, 31); + maskedTextBox.TabIndex = 4; + maskedTextBox.ValidatingType = typeof(int); + maskedTextBox.MaskInputRejected += maskedTextBox1_MaskInputRejected; + // + // buttonAddTrackedVehicle + // + buttonAddTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddTrackedVehicle.Location = new Point(12, 181); + buttonAddTrackedVehicle.Name = "buttonAddTrackedVehicle"; + buttonAddTrackedVehicle.Size = new Size(279, 82); + buttonAddTrackedVehicle.TabIndex = 3; + buttonAddTrackedVehicle.Text = "Добавление гусеничной машины"; + buttonAddTrackedVehicle.UseVisualStyleBackColor = true; + buttonAddTrackedVehicle.Click += ButtonAddTrackedVehicle_Click; + // + // buttonAddFighter + // + buttonAddFighter.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddFighter.Location = new Point(0, 98); + buttonAddFighter.Name = "buttonAddFighter"; + buttonAddFighter.Size = new Size(291, 77); + buttonAddFighter.TabIndex = 2; + buttonAddFighter.Text = "Добавление истребителя"; + buttonAddFighter.UseVisualStyleBackColor = true; + buttonAddFighter.Click += ButtonAddTrackedVehicle_Click; + // + // comboBoxSelectorCompany + // + comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectorCompany.FormattingEnabled = true; + comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); + comboBoxSelectorCompany.Location = new Point(7, 30); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(284, 33); + comboBoxSelectorCompany.TabIndex = 1; + comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(886, 617); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + pictureBox.Click += pictureBox1_Click; + // + // FormTrackedVehicleCollection + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1183, 617); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormTrackedVehicleCollection"; + Text = "Коллекция гусеничных машин"; + Load += FormTrackedVehicleCollection_Load; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectorCompany; + private Button buttonAddTrackedVehicle; + private Button buttonAddFighter; + private PictureBox pictureBox; + private Button buttonRemoveTrackedVehicle; + private MaskedTextBox maskedTextBox; + private Button buttonGoToCheck; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/solution/lab1/FormTrackedVehicleCollection.cs b/solution/lab1/FormTrackedVehicleCollection.cs new file mode 100644 index 0000000..cfa1c2a --- /dev/null +++ b/solution/lab1/FormTrackedVehicleCollection.cs @@ -0,0 +1,204 @@ +using lab1.CollectionGenericObjects; +using lab1.Drawnings; + +namespace lab1; +/// +///Форма работы с компанией и её коллекцией +/// +public partial class FormTrackedVehicleCollection : Form +{ + /// + /// Компания + /// + private AbstractCompany? _company = null; + + /// + /// Конструктор + /// + public FormTrackedVehicleCollection() + { + InitializeComponent(); + } + /// + /// Выбор компании + /// + /// + /// + + private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new TrackedVehicleSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + + /// + /// Добавление гусеничной машины + /// + /// + /// + private void ButtonAddTrackedVehicle_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedVehicle)); + /// + /// Добавление истребителя + /// + /// + /// + private void ButtonAddEntityFighter_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningEntityFighter)); + + /// + /// Создание объекта класса-перемещения + /// + /// + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + Random random = new(); + DrawningTrackedVehicle drawningTrackedVehicle; + switch (type) + { + case nameof(DrawningTrackedVehicle): + drawningTrackedVehicle = new DrawningTrackedVehicle(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningEntityFighter): + drawningTrackedVehicle = new DrawningEntityFighter(random.Next(100, 300), random.Next(1000, 3000), + GetColor(random), + GetColor(random), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + break; + default: + return; + + } + if (_company + drawningTrackedVehicle != -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 ButtonRemoveTrackedVehicle_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) + { + return; + } + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBox.Text); + if (_company - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// + /// Передача объекта в другую форму + /// + /// + /// + + private void button1_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + DrawningTrackedVehicle? fighter = null; + int counter = 100; + while (fighter == null) + { + fighter = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + if (fighter == null) + { + return; + } + FormFighter form = new() + { + SetTrackedVehicle = fighter + }; + form.ShowDialog(); + + } + + + /// + /// Перерисовка коллекции + /// + /// + /// + private void ButtonRefresh_Click_1(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + pictureBox.Image = _company.Show(); + } + private void pictureBox1_Click(object sender, EventArgs e) + { + + } + + private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e) + { + + } + + + + private void FormTrackedVehicleCollection_Load(object sender, EventArgs e) + { + + } + +} + diff --git a/solution/lab1/FormTrackedVehicleCollection.resx b/solution/lab1/FormTrackedVehicleCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/solution/lab1/FormTrackedVehicleCollection.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/solution/lab1/Program.cs b/solution/lab1/Program.cs index d57203a..53acbe8 100644 --- a/solution/lab1/Program.cs +++ b/solution/lab1/Program.cs @@ -11,7 +11,7 @@ namespace lab1 // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormFighter()); + Application.Run(new FormTrackedVehicleCollection()); } } } \ No newline at end of file