From d12fbd832b96e9c00cc8a67655b566ec22d82416 Mon Sep 17 00:00:00 2001 From: Denis Date: Fri, 7 Oct 2022 21:30:29 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=203?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0.=20=D0=9D?= =?UTF-8?q?=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B8=D0=B5=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=20=D0=BE?= =?UTF-8?q?=D1=82=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D0=B5=20=D0=BE=D0=B1?= =?UTF-8?q?=D1=8A=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirplaneWithRadar/Direction.cs | 2 +- .../AirplaneWithRadar/DrawningAirplane.cs | 6 +- .../DrawningAirplaneWithRadar.cs | 2 +- .../AirplaneWithRadar/EntityAirplane.cs | 2 +- .../FormAirplane.Designer.cs | 13 + .../AirplaneWithRadar/FormAirplane.cs | 36 ++- .../FormMapWithSetAirplane.Designer.cs | 239 ++++++++++++++++++ .../FormMapWithSetAirplane.cs | 164 ++++++++++++ .../FormMapWithSetAirplane.resx | 60 +++++ .../MapWithSetAirplaneGeneric.cs | 10 +- .../AirplaneWithRadar/Program.cs | 2 +- 11 files changed, 520 insertions(+), 16 deletions(-) create mode 100644 AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.Designer.cs create mode 100644 AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.cs create mode 100644 AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.resx diff --git a/AirplaneWithRadar/AirplaneWithRadar/Direction.cs b/AirplaneWithRadar/AirplaneWithRadar/Direction.cs index 216637f..a9ce121 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/Direction.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/Direction.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace AirplaneWithRadar { - internal enum Direction + public enum Direction { None = 0, Up = 1, diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplane.cs index fa164eb..92d02d6 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplane.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplane.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace AirplaneWithRadar { - internal class DrawningAirplane + public class DrawningAirplane { public EntityAirplane Airplane { get; protected set; } protected float _startPosX; @@ -84,9 +84,11 @@ namespace AirplaneWithRadar // Корпус g.DrawRectangle(pen, _startPosX, _startPosY + 10, 40, 10); + Brush darkBrush = new SolidBrush(Airplane?.BodyColor ?? Color.Black); + g.FillRectangle(darkBrush, _startPosX + 1, _startPosY + 11, 39, 9); // Окно - Brush darkBrush = new SolidBrush(Airplane?.BodyColor ?? Color.Black); + darkBrush = new SolidBrush(Color.Black); g.FillRectangle(darkBrush, _startPosX + 12, _startPosY + 13, 20, 2); // Хвост diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplaneWithRadar.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplaneWithRadar.cs index 74b1dc3..ee5367f 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplaneWithRadar.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplaneWithRadar.cs @@ -33,7 +33,7 @@ namespace AirplaneWithRadar if (airplaneWithRadar.Window) { - g.DrawEllipse(new Pen(Color.Black), _startPosX + 40, _startPosY + 13, 5, 5); + g.FillEllipse(dopBrush, _startPosX + 40, _startPosY + 13, 5, 5); } if (airplaneWithRadar.Ladder) diff --git a/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs index 1590cb7..be48f3b 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace AirplaneWithRadar { - internal class EntityAirplane + public class EntityAirplane { public int Speed { get; private set; } public float Weight { get; private set; } diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs index c6f0ae9..54aef14 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs @@ -39,6 +39,7 @@ this.buttonRight = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button(); this.buttonCreateModify = new System.Windows.Forms.Button(); + this.buttonSelectCar = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -154,11 +155,22 @@ this.buttonCreateModify.UseVisualStyleBackColor = true; this.buttonCreateModify.Click += new System.EventHandler(this.buttonCreateModify_Click); // + // buttonSelectCar + // + this.buttonSelectCar.Location = new System.Drawing.Point(560, 391); + this.buttonSelectCar.Name = "buttonSelectCar"; + this.buttonSelectCar.Size = new System.Drawing.Size(94, 29); + this.buttonSelectCar.TabIndex = 8; + this.buttonSelectCar.Text = "Выбрать"; + this.buttonSelectCar.UseVisualStyleBackColor = true; + this.buttonSelectCar.Click += new System.EventHandler(this.buttonSelectCar_Click); + // // FormAirplane // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 451); + this.Controls.Add(this.buttonSelectCar); this.Controls.Add(this.buttonCreateModify); this.Controls.Add(this.buttonUp); this.Controls.Add(this.buttonRight); @@ -190,5 +202,6 @@ private Button buttonRight; private Button buttonUp; private Button buttonCreateModify; + private Button buttonSelectCar; } } \ No newline at end of file diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs index eae7bbb..840125b 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs @@ -3,6 +3,10 @@ namespace AirplaneWithRadar public partial class FormAirplane : Form { private DrawningAirplane _airplane; + /// + /// + /// + public DrawningAirplane SelectedAirplane { get; private set; } public FormAirplane() { InitializeComponent(); @@ -27,8 +31,14 @@ namespace AirplaneWithRadar } private void ButtonCreate_Click(object sender, EventArgs e) { - Random rnd = new(); - _airplane = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + Random random = new(); + Color myColor = new Color(); + ColorDialog MyDialog = new ColorDialog(); + if (MyDialog.ShowDialog() == DialogResult.OK) + { + myColor = MyDialog.Color; + } + _airplane = new DrawningAirplane(random.Next(30, 50), random.Next(1000, 2000), myColor); SetData(); Draw(); } @@ -66,12 +76,28 @@ namespace AirplaneWithRadar private void buttonCreateModify_Click(object sender, EventArgs e) { Random rnd = new(); - _airplane = new DrawningAirplaneWithRadar(rnd.Next(100, 300), rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialogDop = new(); + if (dialogDop.ShowDialog() == DialogResult.OK) + { + dopColor = dialogDop.Color; + } + _airplane = new DrawningAirplaneWithRadar(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); SetData(); Draw(); } + + private void buttonSelectCar_Click(object sender, EventArgs e) + { + SelectedAirplane = _airplane; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.Designer.cs new file mode 100644 index 0000000..1136dd0 --- /dev/null +++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.Designer.cs @@ -0,0 +1,239 @@ +namespace AirplaneWithRadar +{ + partial class FormMapWithSetAirplane + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.groupBox = new System.Windows.Forms.GroupBox(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonShowOnMap = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + this.buttonRemoveAirplane = new System.Windows.Forms.Button(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.buttonAddAirplane = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.groupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.SuspendLayout(); + // + // groupBox + // + this.groupBox.Controls.Add(this.buttonDown); + this.groupBox.Controls.Add(this.buttonRight); + this.groupBox.Controls.Add(this.buttonLeft); + this.groupBox.Controls.Add(this.buttonUp); + this.groupBox.Controls.Add(this.buttonShowOnMap); + this.groupBox.Controls.Add(this.buttonShowStorage); + this.groupBox.Controls.Add(this.buttonRemoveAirplane); + this.groupBox.Controls.Add(this.maskedTextBoxPosition); + this.groupBox.Controls.Add(this.buttonAddAirplane); + this.groupBox.Controls.Add(this.comboBoxSelectorMap); + this.groupBox.Dock = System.Windows.Forms.DockStyle.Right; + this.groupBox.Location = new System.Drawing.Point(685, 0); + this.groupBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBox.Name = "groupBox"; + this.groupBox.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBox.Size = new System.Drawing.Size(229, 600); + this.groupBox.TabIndex = 0; + this.groupBox.TabStop = false; + this.groupBox.Text = "Инструменты"; + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(99, 537); + this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(34, 40); + this.buttonDown.TabIndex = 9; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(141, 537); + this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(34, 40); + this.buttonRight.TabIndex = 8; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonLeft + // + this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeft.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(58, 537); + this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(34, 40); + this.buttonLeft.TabIndex = 7; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(99, 489); + this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(34, 40); + this.buttonUp.TabIndex = 6; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonShowOnMap + // + this.buttonShowOnMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonShowOnMap.Location = new System.Drawing.Point(22, 416); + this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonShowOnMap.Name = "buttonShowOnMap"; + this.buttonShowOnMap.Size = new System.Drawing.Size(193, 40); + this.buttonShowOnMap.TabIndex = 5; + this.buttonShowOnMap.Text = "Посмотреть карту"; + this.buttonShowOnMap.UseVisualStyleBackColor = true; + this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); + // + // buttonShowStorage + // + this.buttonShowStorage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonShowStorage.Location = new System.Drawing.Point(22, 311); + this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(193, 40); + this.buttonShowStorage.TabIndex = 4; + this.buttonShowStorage.Text = "Посмотреть хранилище"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); + // + // buttonRemoveAirplane + // + this.buttonRemoveAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRemoveAirplane.Location = new System.Drawing.Point(22, 228); + this.buttonRemoveAirplane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonRemoveAirplane.Name = "buttonRemoveAirplane"; + this.buttonRemoveAirplane.Size = new System.Drawing.Size(193, 40); + this.buttonRemoveAirplane.TabIndex = 3; + this.buttonRemoveAirplane.Text = "Удалить самолет"; + this.buttonRemoveAirplane.UseVisualStyleBackColor = true; + this.buttonRemoveAirplane.Click += new System.EventHandler(this.ButtonRemoveAirplane_Click); + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(22, 189); + this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(193, 27); + this.maskedTextBoxPosition.TabIndex = 2; + // + // buttonAddAirplane + // + this.buttonAddAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonAddAirplane.Location = new System.Drawing.Point(22, 120); + this.buttonAddAirplane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonAddAirplane.Name = "buttonAddAirplane"; + this.buttonAddAirplane.Size = new System.Drawing.Size(193, 40); + this.buttonAddAirplane.TabIndex = 1; + this.buttonAddAirplane.Text = "Добавить самолет"; + this.buttonAddAirplane.UseVisualStyleBackColor = true; + this.buttonAddAirplane.Click += new System.EventHandler(this.ButtonAddAirplane_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта", + "Карта неба с облаками", + "Карта туманного неба с грозой"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(22, 44); + this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(193, 28); + this.comboBoxSelectorMap.TabIndex = 0; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); + // + // pictureBox + // + this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox.Location = new System.Drawing.Point(0, 0); + this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.pictureBox.Name = "pictureBox"; + this.pictureBox.Size = new System.Drawing.Size(685, 600); + this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBox.TabIndex = 1; + this.pictureBox.TabStop = false; + // + // FormMapWithSetAirplane + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(914, 600); + this.Controls.Add(this.pictureBox); + this.Controls.Add(this.groupBox); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormMapWithSetAirplane"; + this.Text = "FormMapWithSetAirplane"; + this.groupBox.ResumeLayout(false); + this.groupBox.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private GroupBox groupBox; + private Button buttonDown; + private Button buttonRight; + private Button buttonLeft; + private Button buttonUp; + private Button buttonShowOnMap; + private Button buttonShowStorage; + private Button buttonRemoveAirplane; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonAddAirplane; + private ComboBox comboBoxSelectorMap; + private PictureBox pictureBox; + } +} \ No newline at end of file diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.cs new file mode 100644 index 0000000..b5eba7a --- /dev/null +++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.cs @@ -0,0 +1,164 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using static System.Windows.Forms.DataFormats; + +namespace AirplaneWithRadar +{ + public partial class FormMapWithSetAirplane : Form + { + /// + /// Объект от класса карты с набором объектов + /// + private MapWithSetAirplaneGeneric _mapAirplaneCollectionGeneric; + public FormMapWithSetAirplane() + { + InitializeComponent(); + } + /// + /// Выбор карты + /// + /// + /// + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + AbstractMap map = null; + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + map = new SimpleMap(); + break; + case "Карта неба с облаками": + map = new SkyMap(); + break; + case "Карта туманного неба с грозой": + map = new FoggySkyMap(); + break; + } + if (map != null) + { + _mapAirplaneCollectionGeneric = new MapWithSetAirplaneGeneric( + pictureBox.Width, pictureBox.Height, map); + } + else + { + _mapAirplaneCollectionGeneric = null; + } + } + /// + /// Добавление объекта + /// + /// + /// + private void ButtonAddAirplane_Click(object sender, EventArgs e) + { + if (_mapAirplaneCollectionGeneric == null) + { + return; + } + FormAirplane form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + DrawningObjectAirplane airplane = new(form.SelectedAirplane); + if (_mapAirplaneCollectionGeneric + airplane != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapAirplaneCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + /// + /// Удаление объекта + /// + /// + /// + private void ButtonRemoveAirplane_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) + { + return; + } + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_mapAirplaneCollectionGeneric - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _mapAirplaneCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// + /// Вывод набора + /// + /// + /// + private void ButtonShowStorage_Click(object sender, EventArgs e) + { + if (_mapAirplaneCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapAirplaneCollectionGeneric.ShowSet(); + } + /// + /// Вывод карты + /// + /// + /// + private void ButtonShowOnMap_Click(object sender, EventArgs e) + { + if (_mapAirplaneCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapAirplaneCollectionGeneric.ShowOnMap(); + } + /// + /// Перемещение + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_mapAirplaneCollectionGeneric == null) + { + return; + } + //получаем имя кнопки + string name = ((Button)sender)?.Name ?? string.Empty; + Direction dir = Direction.None; + switch (name) + { + case "buttonUp": + dir = Direction.Up; + break; + case "buttonDown": + dir = Direction.Down; + break; + case "buttonLeft": + dir = Direction.Left; + break; + case "buttonRight": + dir = Direction.Right; + break; + } + pictureBox.Image = _mapAirplaneCollectionGeneric.MoveObject(dir); + } + } +} diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.resx b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplaneGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplaneGeneric.cs index e0954f0..69f4d04 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplaneGeneric.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplaneGeneric.cs @@ -28,9 +28,9 @@ _map = map; } // Перегрузка оператора сложения - public static int operator +(MapWithSetAirplaneGeneric map, T tractor) + public static int operator +(MapWithSetAirplaneGeneric map, T airplane) { - return map._setAirplane.Insert(tractor); + return map._setAirplane.Insert(airplane); } // Перегрузка оператора вычитания public static T operator -(MapWithSetAirplaneGeneric map, int position) @@ -98,7 +98,7 @@ private void DrawBackground(Graphics g) { Pen pen = new(Color.Black, 3); - Brush brush = new SolidBrush(Color.LightSlateGray); + Brush brush = new SolidBrush(Color.FromArgb(147, 146, 151)); g.FillRectangle(brush, 0, 0, _pictureWidth, _pictureHeight); for (int i = 0; i <= _pictureWidth / _placeSizeWidth; i++) { @@ -121,8 +121,8 @@ for (int i = _setAirplane.Count; i >= 0; i--) { - _setAirplane.Get(i)?.SetObject(_pictureWidth - _placeSizeWidth * curWidth - 10, - curHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight); + _setAirplane.Get(i)?.SetObject(_pictureWidth - _placeSizeWidth * curWidth - 80, + curHeight * _placeSizeHeight + 30, _pictureWidth, _pictureHeight); _setAirplane.Get(i)?.DrawningObject(g); if (curWidth < widthEl) diff --git a/AirplaneWithRadar/AirplaneWithRadar/Program.cs b/AirplaneWithRadar/AirplaneWithRadar/Program.cs index f8a0be0..7c1941f 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/Program.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/Program.cs @@ -11,7 +11,7 @@ namespace AirplaneWithRadar // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMap()); + Application.Run(new FormMapWithSetAirplane()); } } } \ No newline at end of file