From 73b879b9c66807c42f40c0a38eb559f449d890e4 Mon Sep 17 00:00:00 2001 From: ivans Date: Tue, 9 Apr 2024 13:54:43 +0400 Subject: [PATCH] =?UTF-8?q?Lab03=20=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber.csproj | 2 +- .../AbstractCompany.cs | 16 +- .../AirPlaneSharingService.cs | 16 +- .../ICollectionGenericObjects.cs | 2 +- AirBomber/FormAirBomber.Designer.cs | 202 +++++------ AirBomber/FormAirBomber.cs | 62 +--- AirBomber/FormAirBomber.resx | 62 +++- AirBomber/FormAirPlaneCollection.Designer.cs | 320 ++++++++--------- AirBomber/FormAirPlaneCollection.cs | 324 +++++++++--------- AirBomber/Program.cs | 2 +- 10 files changed, 513 insertions(+), 495 deletions(-) diff --git a/AirBomber/AirBomber.csproj b/AirBomber/AirBomber.csproj index 6e9e137..71818c0 100644 --- a/AirBomber/AirBomber.csproj +++ b/AirBomber/AirBomber.csproj @@ -2,7 +2,7 @@ WinExe - net6.0-windows + net7.0-windows7.0 enable true enable diff --git a/AirBomber/CollectionGenericObjects/AbstractCompany.cs b/AirBomber/CollectionGenericObjects/AbstractCompany.cs index 49379ba..0c9b413 100644 --- a/AirBomber/CollectionGenericObjects/AbstractCompany.cs +++ b/AirBomber/CollectionGenericObjects/AbstractCompany.cs @@ -8,7 +8,7 @@ using AirBomber.Drawnings; namespace AirBomber.CollectionGenericObjects; /// -/// Абстракция компании, хранящий коллекцию самолеток +/// Абстракция компании, хранящий коллекцию самолетов /// public abstract class AbstractCompany { @@ -20,7 +20,7 @@ public abstract class AbstractCompany /// /// Размер места (высота) /// - protected readonly int _placeSizeHeight = 80; + protected readonly int _placeSizeHeight = 150; /// /// Ширина окна @@ -33,7 +33,7 @@ public abstract class AbstractCompany protected readonly int _pictureHeight; /// - /// Коллекция самолетов + /// Коллекция лодок /// protected ICollectionGenericObjects? _collection = null; @@ -47,7 +47,7 @@ public abstract class AbstractCompany /// /// Ширина окна /// Высота окна - /// Коллекция самолетов + /// Коллекция лодок public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection) { _pictureWidth = picWidth; @@ -60,11 +60,11 @@ public abstract class AbstractCompany /// Перегрузка оператора сложения для класса /// /// Компания - /// Добавляемый объект + /// Добавляемый объект /// - public static int operator +(AbstractCompany company, DrawningAirPlane airplane) + public static int operator +(AbstractCompany company, DrawningAirPlane boat) { - return company._collection?.Insert(airplane) ?? -1; + return company._collection?.Insert(boat) ?? -1; } /// @@ -118,4 +118,4 @@ public abstract class AbstractCompany /// Расстановка объектов /// protected abstract void SetObjectsPosition(); -} \ No newline at end of file +} diff --git a/AirBomber/CollectionGenericObjects/AirPlaneSharingService.cs b/AirBomber/CollectionGenericObjects/AirPlaneSharingService.cs index 85bcb6d..9a50907 100644 --- a/AirBomber/CollectionGenericObjects/AirPlaneSharingService.cs +++ b/AirBomber/CollectionGenericObjects/AirPlaneSharingService.cs @@ -23,30 +23,32 @@ public class AirPlaneSharingService : AbstractCompany protected override void DrawBackground(Graphics g) { - Color backgroundColor = Color.SkyBlue; + Color backgroundColor = Color.Gray; using (Brush brush = new SolidBrush(backgroundColor)) { g.FillRectangle(brush, new Rectangle(0, 0, _pictureWidth, _pictureHeight)); } Pen pen = new Pen(Color.Brown, 3); int offsetX = 10, offsetY = -12; - int x = 1 + offsetX, y = _pictureHeight - _placeSizeHeight + offsetY; + int x = _pictureWidth - _placeSizeWidth, y = offsetY; numRows = 0; - while (y >= 0) + while (y + _placeSizeHeight <= _pictureHeight) { int numCols = 0; - while (x + _placeSizeWidth <= _pictureWidth) + int initialX = x; // сохраняем начальное значение x + while (x >= 0) { numCols++; g.DrawLine(pen, x, y, x + _placeSizeWidth / 2, y); g.DrawLine(pen, x, y, x, y + _placeSizeHeight + 4); locCoord.Add(new Tuple(x, y)); - x += _placeSizeWidth + 2; + x -= _placeSizeWidth + 2; } numRows++; - x = 1 + offsetX; - y -= _placeSizeHeight + 5 + offsetY; + x = initialX; // возвращаем x к начальному значению после завершения строки + y += _placeSizeHeight + 5 + offsetY; } + numCols = numCols; // сохраняем значение numCols для использования в других методах } protected override void SetObjectsPosition() diff --git a/AirBomber/CollectionGenericObjects/ICollectionGenericObjects.cs b/AirBomber/CollectionGenericObjects/ICollectionGenericObjects.cs index 0bdfb8f..5bd7242 100644 --- a/AirBomber/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/AirBomber/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -45,4 +45,4 @@ public interface ICollectionGenericObjects /// Позиция /// Объект T? Get(int position); -} \ No newline at end of file +} diff --git a/AirBomber/FormAirBomber.Designer.cs b/AirBomber/FormAirBomber.Designer.cs index 40fec26..e812e07 100644 --- a/AirBomber/FormAirBomber.Designer.cs +++ b/AirBomber/FormAirBomber.Designer.cs @@ -28,151 +28,127 @@ /// private void InitializeComponent() { - this.buttonCreateAirPlane = new System.Windows.Forms.Button(); - this.ButtonRight = new System.Windows.Forms.Button(); - this.ButtonUp = new System.Windows.Forms.Button(); - this.ButtonLeft = new System.Windows.Forms.Button(); - this.ButtonDown = new System.Windows.Forms.Button(); - this.pictureBoxAirBomber = new System.Windows.Forms.PictureBox(); - this.buttonCreateAirBomber = new System.Windows.Forms.Button(); - this.comboBoxStrategy = new System.Windows.Forms.ComboBox(); - this.buttonStrategyStep = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirBomber)).BeginInit(); - this.SuspendLayout(); - // - // buttonCreateAirPlane - // - this.buttonCreateAirPlane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.buttonCreateAirPlane.Location = new System.Drawing.Point(12, 575); - this.buttonCreateAirPlane.Name = "buttonCreateAirPlane"; - this.buttonCreateAirPlane.Size = new System.Drawing.Size(233, 33); - this.buttonCreateAirPlane.TabIndex = 0; - this.buttonCreateAirPlane.Text = "Создать Военный самолет"; - this.buttonCreateAirPlane.UseVisualStyleBackColor = true; - this.buttonCreateAirPlane.Click += new System.EventHandler(this.ButtonCreateAirPlane_Click); + ButtonRight = new Button(); + ButtonUp = new Button(); + ButtonLeft = new Button(); + ButtonDown = new Button(); + pictureBoxAirBomber = new PictureBox(); + comboBoxStrategy = new ComboBox(); + buttonStrategyStep = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit(); + SuspendLayout(); // // ButtonRight // - this.ButtonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonRight.BackgroundImage = global::AirBomber.Properties.Resources.arrowRight; - this.ButtonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.ButtonRight.Location = new System.Drawing.Point(905, 560); - this.ButtonRight.Name = "ButtonRight"; - this.ButtonRight.Size = new System.Drawing.Size(50, 48); - this.ButtonRight.TabIndex = 1; - this.ButtonRight.UseVisualStyleBackColor = true; - this.ButtonRight.Click += new System.EventHandler(this.ButtonMove_Click); + ButtonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + ButtonRight.BackgroundImage = Properties.Resources.arrowRight; + ButtonRight.BackgroundImageLayout = ImageLayout.Stretch; + ButtonRight.Location = new Point(792, 420); + ButtonRight.Margin = new Padding(3, 2, 3, 2); + ButtonRight.Name = "ButtonRight"; + ButtonRight.Size = new Size(44, 36); + ButtonRight.TabIndex = 1; + ButtonRight.UseVisualStyleBackColor = true; + ButtonRight.Click += ButtonMove_Click; // // ButtonUp // - this.ButtonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonUp.BackgroundImage = global::AirBomber.Properties.Resources.arrowUp; - this.ButtonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.ButtonUp.Location = new System.Drawing.Point(849, 506); - this.ButtonUp.Name = "ButtonUp"; - this.ButtonUp.Size = new System.Drawing.Size(50, 48); - this.ButtonUp.TabIndex = 2; - this.ButtonUp.UseVisualStyleBackColor = true; - this.ButtonUp.Click += new System.EventHandler(this.ButtonMove_Click); + ButtonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + ButtonUp.BackgroundImage = Properties.Resources.arrowUp; + ButtonUp.BackgroundImageLayout = ImageLayout.Stretch; + ButtonUp.Location = new Point(743, 380); + ButtonUp.Margin = new Padding(3, 2, 3, 2); + ButtonUp.Name = "ButtonUp"; + ButtonUp.Size = new Size(44, 36); + ButtonUp.TabIndex = 2; + ButtonUp.UseVisualStyleBackColor = true; + ButtonUp.Click += ButtonMove_Click; // // ButtonLeft // - this.ButtonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonLeft.BackgroundImage = global::AirBomber.Properties.Resources.arrowLeft; - this.ButtonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.ButtonLeft.Location = new System.Drawing.Point(793, 560); - this.ButtonLeft.Name = "ButtonLeft"; - this.ButtonLeft.Size = new System.Drawing.Size(50, 48); - this.ButtonLeft.TabIndex = 3; - this.ButtonLeft.UseVisualStyleBackColor = true; - this.ButtonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + ButtonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + ButtonLeft.BackgroundImage = Properties.Resources.arrowLeft; + ButtonLeft.BackgroundImageLayout = ImageLayout.Stretch; + ButtonLeft.Location = new Point(694, 420); + ButtonLeft.Margin = new Padding(3, 2, 3, 2); + ButtonLeft.Name = "ButtonLeft"; + ButtonLeft.Size = new Size(44, 36); + ButtonLeft.TabIndex = 3; + ButtonLeft.UseVisualStyleBackColor = true; + ButtonLeft.Click += ButtonMove_Click; // // ButtonDown // - this.ButtonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonDown.BackgroundImage = global::AirBomber.Properties.Resources.arrowDown; - this.ButtonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.ButtonDown.Location = new System.Drawing.Point(849, 560); - this.ButtonDown.Name = "ButtonDown"; - this.ButtonDown.Size = new System.Drawing.Size(50, 48); - this.ButtonDown.TabIndex = 4; - this.ButtonDown.UseVisualStyleBackColor = true; - this.ButtonDown.Click += new System.EventHandler(this.ButtonMove_Click); + ButtonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + ButtonDown.BackgroundImage = Properties.Resources.arrowDown; + ButtonDown.BackgroundImageLayout = ImageLayout.Stretch; + ButtonDown.Location = new Point(743, 420); + ButtonDown.Margin = new Padding(3, 2, 3, 2); + ButtonDown.Name = "ButtonDown"; + ButtonDown.Size = new Size(44, 36); + ButtonDown.TabIndex = 4; + ButtonDown.UseVisualStyleBackColor = true; + ButtonDown.Click += ButtonMove_Click; // // pictureBoxAirBomber // - this.pictureBoxAirBomber.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBoxAirBomber.Location = new System.Drawing.Point(0, 0); - this.pictureBoxAirBomber.Name = "pictureBoxAirBomber"; - this.pictureBoxAirBomber.Size = new System.Drawing.Size(967, 621); - this.pictureBoxAirBomber.TabIndex = 5; - this.pictureBoxAirBomber.TabStop = false; - // - // buttonCreateAirBomber - // - this.buttonCreateAirBomber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.buttonCreateAirBomber.Location = new System.Drawing.Point(283, 576); - this.buttonCreateAirBomber.Name = "buttonCreateAirBomber"; - this.buttonCreateAirBomber.Size = new System.Drawing.Size(220, 33); - this.buttonCreateAirBomber.TabIndex = 6; - this.buttonCreateAirBomber.Text = "Создать Бомбардировщик"; - this.buttonCreateAirBomber.UseVisualStyleBackColor = true; - this.buttonCreateAirBomber.Click += new System.EventHandler(this.ButtonCreateAirBomber_Click); + pictureBoxAirBomber.Dock = DockStyle.Fill; + pictureBoxAirBomber.Location = new Point(0, 0); + pictureBoxAirBomber.Margin = new Padding(3, 2, 3, 2); + pictureBoxAirBomber.Name = "pictureBoxAirBomber"; + pictureBoxAirBomber.Size = new Size(846, 466); + pictureBoxAirBomber.TabIndex = 5; + pictureBoxAirBomber.TabStop = false; // // comboBoxStrategy // - this.comboBoxStrategy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxStrategy.FormattingEnabled = true; - this.comboBoxStrategy.Items.AddRange(new object[] { - "К центру ", - "К краю"}); - this.comboBoxStrategy.Location = new System.Drawing.Point(804, 12); - this.comboBoxStrategy.Name = "comboBoxStrategy"; - this.comboBoxStrategy.Size = new System.Drawing.Size(151, 28); - this.comboBoxStrategy.TabIndex = 7; + comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; + comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStrategy.FormattingEnabled = true; + comboBoxStrategy.Items.AddRange(new object[] { "К центру ", "К краю" }); + comboBoxStrategy.Location = new Point(704, 9); + comboBoxStrategy.Margin = new Padding(3, 2, 3, 2); + comboBoxStrategy.Name = "comboBoxStrategy"; + comboBoxStrategy.Size = new Size(133, 23); + comboBoxStrategy.TabIndex = 7; // // buttonStrategyStep // - this.buttonStrategyStep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonStrategyStep.Location = new System.Drawing.Point(804, 74); - this.buttonStrategyStep.Name = "buttonStrategyStep"; - this.buttonStrategyStep.Size = new System.Drawing.Size(94, 29); - this.buttonStrategyStep.TabIndex = 8; - this.buttonStrategyStep.Text = "Шаг"; - this.buttonStrategyStep.UseVisualStyleBackColor = true; - this.buttonStrategyStep.Click += new System.EventHandler(this.buttonStrategyStep_Click); + buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonStrategyStep.Location = new Point(704, 56); + buttonStrategyStep.Margin = new Padding(3, 2, 3, 2); + buttonStrategyStep.Name = "buttonStrategyStep"; + buttonStrategyStep.Size = new Size(82, 22); + buttonStrategyStep.TabIndex = 8; + buttonStrategyStep.Text = "Шаг"; + buttonStrategyStep.UseVisualStyleBackColor = true; + buttonStrategyStep.Click += buttonStrategyStep_Click; // // FormAirBomber // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(967, 621); - this.Controls.Add(this.buttonStrategyStep); - this.Controls.Add(this.comboBoxStrategy); - this.Controls.Add(this.buttonCreateAirBomber); - this.Controls.Add(this.ButtonDown); - this.Controls.Add(this.ButtonLeft); - this.Controls.Add(this.ButtonUp); - this.Controls.Add(this.ButtonRight); - this.Controls.Add(this.buttonCreateAirPlane); - this.Controls.Add(this.pictureBoxAirBomber); - this.Name = "FormAirBomber"; - this.Text = "AirBomber"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirBomber)).EndInit(); - this.ResumeLayout(false); - + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(846, 466); + Controls.Add(buttonStrategyStep); + Controls.Add(comboBoxStrategy); + Controls.Add(ButtonDown); + Controls.Add(ButtonLeft); + Controls.Add(ButtonUp); + Controls.Add(ButtonRight); + Controls.Add(pictureBoxAirBomber); + Margin = new Padding(3, 2, 3, 2); + Name = "FormAirBomber"; + Text = "AirBomber"; + ((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).EndInit(); + ResumeLayout(false); } #endregion - - private Button buttonCreateAirPlane; private Button ButtonRight; private Button ButtonUp; private Button ButtonLeft; private Button ButtonDown; private PictureBox pictureBoxAirBomber; - private Button buttonCreateAirBomber; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/AirBomber/FormAirBomber.cs b/AirBomber/FormAirBomber.cs index e1cbbaa..ce539ad 100644 --- a/AirBomber/FormAirBomber.cs +++ b/AirBomber/FormAirBomber.cs @@ -11,8 +11,22 @@ public partial class FormAirBomber : Form /// - /// private DrawningAirPlane? _drawningAirPlane; - + /// + /// + /// private AbstractStrategy? _strategy; + + public DrawningAirPlane SetAirPlane + { + set + { + _drawningAirPlane = value; + _drawningAirPlane.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } public FormAirBomber() { InitializeComponent(); @@ -38,52 +52,6 @@ public partial class FormAirBomber : Form } - /// - /// - /// - /// - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningAirPlane): - _drawningAirPlane = new DrawningAirPlane(random.Next(30, 100), random.Next(100, 500), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); - break; - case nameof(DrawningAirBomber): - _drawningAirPlane = new DrawningAirBomber(random.Next(30, 100), random.Next(100, 500), - 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; - - } - _drawningAirPlane.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); - _drawningAirPlane.SetPosition(random.Next(15, 100), random.Next(15, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - - } - - /// - /// " " - /// - /// - /// - private void ButtonCreateAirBomber_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirBomber)); - - /// - /// " " - /// - /// - /// - private void ButtonCreateAirPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirPlane)); - - private void ButtonMove_Click(object sender, EventArgs e) { if (_drawningAirPlane == null) diff --git a/AirBomber/FormAirBomber.resx b/AirBomber/FormAirBomber.resx index f298a7b..af32865 100644 --- a/AirBomber/FormAirBomber.resx +++ b/AirBomber/FormAirBomber.resx @@ -1,4 +1,64 @@ - + + + diff --git a/AirBomber/FormAirPlaneCollection.Designer.cs b/AirBomber/FormAirPlaneCollection.Designer.cs index 72c53a7..c52b0cd 100644 --- a/AirBomber/FormAirPlaneCollection.Designer.cs +++ b/AirBomber/FormAirPlaneCollection.Designer.cs @@ -1,161 +1,171 @@ -namespace AirBomber; - -partial class FormAirPlaneCollection +namespace AirBomber { - /// - /// 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) + partial class FormAirPlaneCollection { - if (disposing && (components != null)) + /// + /// 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) { - components.Dispose(); + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); } - 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(); + buttonDelAirPlane = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonAddAirBomber = new Button(); + buttonAddAirPlane = 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(buttonDelAirPlane); + groupBoxTools.Controls.Add(maskedTextBox); + groupBoxTools.Controls.Add(buttonAddAirBomber); + groupBoxTools.Controls.Add(buttonAddAirPlane); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(793, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(167, 644); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструманты"; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(12, 463); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(143, 43); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Location = new Point(12, 370); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(143, 41); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonDelAirPlane + // + buttonDelAirPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonDelAirPlane.Location = new Point(12, 275); + buttonDelAirPlane.Name = "buttonDelAirPlane"; + buttonDelAirPlane.Size = new Size(143, 39); + buttonDelAirPlane.TabIndex = 4; + buttonDelAirPlane.Text = "Удалить Самолет"; + buttonDelAirPlane.UseVisualStyleBackColor = true; + buttonDelAirPlane.Click += ButtonRemoveAirPlane_Click; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(12, 246); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(143, 23); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonAddAirBomber + // + buttonAddAirBomber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddAirBomber.Location = new Point(12, 124); + buttonAddAirBomber.Name = "buttonAddAirBomber"; + buttonAddAirBomber.Size = new Size(143, 42); + buttonAddAirBomber.TabIndex = 2; + buttonAddAirBomber.Text = "Добавление Бомбардировщика"; + buttonAddAirBomber.UseVisualStyleBackColor = true; + buttonAddAirBomber.Click += buttonAddAirBomber_Click; + // + // buttonAddAirPlane + // + buttonAddAirPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddAirPlane.Location = new Point(12, 77); + buttonAddAirPlane.Name = "buttonAddAirPlane"; + buttonAddAirPlane.Size = new Size(143, 41); + buttonAddAirPlane.TabIndex = 1; + buttonAddAirPlane.Text = "Добавление самолета"; + buttonAddAirPlane.UseVisualStyleBackColor = true; + buttonAddAirPlane.Click += buttonAddAirPlane_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(12, 31); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(143, 23); + comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(793, 644); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormAirPlaneCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(960, 644); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormAirPlaneCollection"; + Text = "FormAirPlaneCollection"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private Button buttonAddAirPlane; + private ComboBox comboBoxSelectorCompany; + private Button buttonAddAirBomber; + private PictureBox pictureBox; + private Button buttonGoToCheck; + private Button buttonDelAirPlane; + private MaskedTextBox maskedTextBox; + private Button buttonRefresh; } - - #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(); - comboBoxSelectorCompany = new ComboBox(); - buttonAddAirPlane = new Button(); - buttonAddAirBomber = new Button(); - pictureBox = new PictureBox(); - maskedTextBox = new MaskedTextBox(); - buttonDelAirPlane = new Button(); - buttonGoToCheck = new Button(); - buttonRefresh = new Button(); - groupBoxTools.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); - SuspendLayout(); - // - // groupBoxTools - // - groupBoxTools.Controls.Add(buttonRefresh); - groupBoxTools.Controls.Add(buttonGoToCheck); - groupBoxTools.Controls.Add(buttonDelAirPlane); - groupBoxTools.Controls.Add(maskedTextBox); - groupBoxTools.Controls.Add(buttonAddAirBomber); - groupBoxTools.Controls.Add(buttonAddAirPlane); - groupBoxTools.Controls.Add(comboBoxSelectorCompany); - groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(784, 0); - groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(214, 650); - groupBoxTools.TabIndex = 0; - groupBoxTools.TabStop = false; - groupBoxTools.Text = "Инструменты"; - // - // 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(14, 39); - comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; - comboBoxSelectorCompany.Size = new Size(188, 28); - comboBoxSelectorCompany.TabIndex = 0; - // - // buttonAddAirPlane - // - buttonAddAirPlane.Location = new Point(14, 128); - buttonAddAirPlane.Name = "buttonAddAirPlane"; - buttonAddAirPlane.Size = new Size(188, 42); - buttonAddAirPlane.TabIndex = 1; - buttonAddAirPlane.Text = "Добавление самолета"; - buttonAddAirPlane.UseVisualStyleBackColor = true; - // - // buttonAddAirBomber - // - buttonAddAirBomber.Location = new Point(14, 189); - buttonAddAirBomber.Name = "buttonAddAirBomber"; - buttonAddAirBomber.Size = new Size(188, 50); - buttonAddAirBomber.TabIndex = 2; - buttonAddAirBomber.Text = "Добавление Бомбардировщика"; - buttonAddAirBomber.UseVisualStyleBackColor = true; - // - // pictureBox - // - pictureBox.Dock = DockStyle.Fill; - pictureBox.Location = new Point(0, 0); - pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(784, 650); - pictureBox.TabIndex = 1; - pictureBox.TabStop = false; - // - // maskedTextBox - // - maskedTextBox.Location = new Point(14, 272); - maskedTextBox.Mask = "00"; - maskedTextBox.Name = "maskedTextBox"; - maskedTextBox.Size = new Size(188, 27); - maskedTextBox.TabIndex = 3; - maskedTextBox.ValidatingType = typeof(int); - // - // buttonDelAirPlane - // - buttonDelAirPlane.Location = new Point(14, 327); - buttonDelAirPlane.Name = "buttonDelAirPlane"; - buttonDelAirPlane.Size = new Size(188, 59); - buttonDelAirPlane.TabIndex = 4; - buttonDelAirPlane.Text = "Удалить самолет"; - buttonDelAirPlane.UseVisualStyleBackColor = true; - // - // buttonGoToCheck - // - buttonGoToCheck.Location = new Point(14, 443); - buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(188, 59); - buttonGoToCheck.TabIndex = 5; - buttonGoToCheck.Text = "Передать на тесты"; - buttonGoToCheck.UseVisualStyleBackColor = true; - // - // buttonRefresh - // - buttonRefresh.Location = new Point(14, 569); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(188, 59); - buttonRefresh.TabIndex = 6; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - // - // FormAirPlaneCollection - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(998, 650); - Controls.Add(pictureBox); - Controls.Add(groupBoxTools); - Name = "FormAirPlaneCollection"; - Text = "Коллекция самолетов"; - groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); - ResumeLayout(false); - } - - #endregion - - private GroupBox groupBoxTools; - private ComboBox comboBoxSelectorCompany; - private Button buttonAddAirBomber; - private Button buttonAddAirPlane; - private PictureBox pictureBox; - private Button buttonDelAirPlane; - private MaskedTextBox maskedTextBox; - private Button buttonGoToCheck; - private Button buttonRefresh; } \ No newline at end of file diff --git a/AirBomber/FormAirPlaneCollection.cs b/AirBomber/FormAirPlaneCollection.cs index 429d6cb..4f8289a 100644 --- a/AirBomber/FormAirPlaneCollection.cs +++ b/AirBomber/FormAirPlaneCollection.cs @@ -1,4 +1,5 @@ using AirBomber.CollectionGenericObjects; +using AirBomber.Drawnings; using System; using System.Collections.Generic; using System.ComponentModel; @@ -9,183 +10,184 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace AirBomber; - -public partial class FormBoatCollection : Form +namespace AirBomber { - /// - /// Компания - /// - private AbstractCompany? _company; - - /// - /// Конструктор - /// - public FormBoatCollection() + public partial class FormAirPlaneCollection : Form { - InitializeComponent(); - } + /// + /// Компания + /// + private AbstractCompany? _company; - /// - /// Выбор компании - /// - /// - /// - private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) - { - switch (comboBoxSelectorCompany.Text) + /// + /// Конструктор + /// + public FormAirPlaneCollection() { - case "Хранилище": - _company = new BoatSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } - } - - /// - /// Создание объекта класса-перемещения - /// - /// Тип создаваемого объекта - private void CreateObject(string type) - { - if (_company == null) - { - return; - } - DrawningBoat _drawningBoat; - Random random = new(); - switch (type) - { - case nameof(DrawningBoat): - _drawningBoat = new DrawningBoat(random.Next(30, 70), random.Next(100, 500), - GetColor(random)); - break; - case nameof(DrawningCatamaran): - _drawningBoat = new DrawningCatamaran(random.Next(30, 70), random.Next(100, 500), - GetColor(random), GetColor(random), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - break; - default: - return; - + InitializeComponent(); } - if (_company + _drawningBoat != -1) + /// + /// Выбор компании + /// + /// + /// + private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _company.Show(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } - } - - /// - /// Добавление обычного автомобиля - /// - /// - /// - private void buttonAddBoat_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBoat)); - - /// - /// Добавление спортивного автомобиля - /// - /// - /// - private void buttonAddCatamaran_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCatamaran)); - - /// - /// Получение цвета - /// - /// Генератор случайных чисел - /// - 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 ButtonRemoveBoat_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) - { - return; - } - - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) - { - return; - } - - int pos = Convert.ToInt32(maskedTextBoxPosition.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; - } - - DrawningBoat? airplane = null; - int counter = 100; - while (airplane == null) - { - airplane = _company.GetRandomObject(); - counter--; - if (counter <= 0) + switch (comboBoxSelectorCompany.Text) { - break; + case "Хранилище": + _company = new AirPlaneSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; } } - if (airplane == null) + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) { - return; + if (_company == null) + { + return; + } + DrawningAirPlane _drawningAirPlane; + Random random = new(); + switch (type) + { + case nameof(DrawningAirPlane): + _drawningAirPlane = new DrawningAirPlane(random.Next(30, 70), random.Next(100, 500), + GetColor(random)); + break; + case nameof(DrawningAirBomber): + _drawningAirPlane = new DrawningAirBomber(random.Next(30, 70), random.Next(100, 500), + GetColor(random), GetColor(random), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + break; + default: + return; + + } + + if (_company + _drawningAirPlane != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } } - FormCatamaran form = new FormCatamaran(); - form.SetBoat = airplane; - form.ShowDialog(); - } + /// + /// Добавление обычного автомобиля + /// + /// + /// + private void buttonAddAirPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirPlane)); - /// - /// Перерисовка коллекции - /// - /// - /// - private void ButtonRefresh_Click(object sender, EventArgs e) - { - if (_company == null) + /// + /// Добавление спортивного автомобиля + /// + /// + /// + private void buttonAddAirBomber_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirBomber)); + + /// + /// Получение цвета + /// + /// Генератор случайных чисел + /// + private static Color GetColor(Random random) { - return; + 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; } - pictureBox.Image = _company.Show(); + /// + /// Удаление объекта + /// + /// + /// + private void ButtonRemoveAirPlane_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; + } + + DrawningAirPlane? airplane = null; + int counter = 100; + while (airplane == null) + { + airplane = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (airplane == null) + { + return; + } + + FormAirBomber form = new FormAirBomber(); + form.SetAirPlane = airplane; + form.ShowDialog(); + } + + /// + /// Перерисовка коллекции + /// + /// + /// + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + } } -} \ No newline at end of file +} diff --git a/AirBomber/Program.cs b/AirBomber/Program.cs index 76b85fe..333ba5b 100644 --- a/AirBomber/Program.cs +++ b/AirBomber/Program.cs @@ -11,7 +11,7 @@ namespace AirBomber // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormAirBomber()); + Application.Run(new FormAirPlaneCollection()); } } } \ No newline at end of file