diff --git a/ProjectBomber/ProjectBomber/DrawningBomber.cs b/ProjectBomber/ProjectBomber/DrawningBomber.cs index 3cdf655..13c722c 100644 --- a/ProjectBomber/ProjectBomber/DrawningBomber.cs +++ b/ProjectBomber/ProjectBomber/DrawningBomber.cs @@ -22,11 +22,11 @@ namespace ProjectBomber.DrawningObjects /// /// Ширина окна /// - private int _pictureWidth; + public int _pictureWidth; /// /// Высота окна /// - private int _pictureHeight; + public int _pictureHeight; /// /// Левая координата прорисовки бомбардировщика /// @@ -280,5 +280,9 @@ namespace ProjectBomber.DrawningObjects // Рисуем контур линии g.DrawPath(pen, path1); } + public void setColor(Color color) + { + EntityBomber.setColor(color); + } } } diff --git a/ProjectBomber/ProjectBomber/DrawningBomberAdvanced.cs b/ProjectBomber/ProjectBomber/DrawningBomberAdvanced.cs index 9ca1cda..ee67fb5 100644 --- a/ProjectBomber/ProjectBomber/DrawningBomberAdvanced.cs +++ b/ProjectBomber/ProjectBomber/DrawningBomberAdvanced.cs @@ -60,8 +60,13 @@ namespace ProjectBomber.DrawningObjects g.FillRectangle(additionalBrush, _startPosX + 10, _startPosY + 34, 50, 2); } } - } - + public void setAddColor(Color color) + { + if (EntityBomber is EntityBomberAdvanced bomber) + { + bomber.setAddColor(color); + } + } } } diff --git a/ProjectBomber/ProjectBomber/EntityBomber.cs b/ProjectBomber/ProjectBomber/EntityBomber.cs index e796f42..988e475 100644 --- a/ProjectBomber/ProjectBomber/EntityBomber.cs +++ b/ProjectBomber/ProjectBomber/EntityBomber.cs @@ -40,5 +40,9 @@ namespace ProjectBomber.Entities Weight = weight; BodyColor = bodyColor; } + public void setColor(Color color) + { + BodyColor = color; + } } } diff --git a/ProjectBomber/ProjectBomber/EntityBomberAdvanced.cs b/ProjectBomber/ProjectBomber/EntityBomberAdvanced.cs index 9bd4258..82492ac 100644 --- a/ProjectBomber/ProjectBomber/EntityBomberAdvanced.cs +++ b/ProjectBomber/ProjectBomber/EntityBomberAdvanced.cs @@ -47,5 +47,9 @@ namespace ProjectBomber.Entities FuelTanks = fuelTanks; Line = line; } + public void setAddColor(Color color) + { + AdditionalColor = color; + } } } diff --git a/ProjectBomber/ProjectBomber/FormPlaneCollection.cs b/ProjectBomber/ProjectBomber/FormPlaneCollection.cs index ddd9444..dfffa1a 100644 --- a/ProjectBomber/ProjectBomber/FormPlaneCollection.cs +++ b/ProjectBomber/ProjectBomber/FormPlaneCollection.cs @@ -90,12 +90,33 @@ _storage[ListBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes() return; } if (MessageBox.Show($"Удалить объект {ListBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, -MessageBoxIcon.Question) == DialogResult.Yes) + MessageBoxIcon.Question) == DialogResult.Yes) { _storage.DelSet(ListBoxStorages.SelectedItem.ToString()?? string.Empty); ReloadObjects(); } } + private void AddPlane(DrawningBomber plane) + { + if (ListBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[ListBoxStorages.SelectedItem.ToString() ?? string.Empty]; + if (obj == null) + { + return; + } + if ((obj + plane) != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowPlanes(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } /// /// Добавление объекта в набор /// @@ -107,25 +128,14 @@ MessageBoxIcon.Question) == DialogResult.Yes) { return; } - var obj = _storage[ListBoxStorages.SelectedItem.ToString() ?? - string.Empty]; + var obj = _storage[ListBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { return; } - FormBomber form = new FormBomber(); - if (form.ShowDialog() == DialogResult.OK) - { - if (obj + form.SelectedBomber) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowPlanes(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } - } + var formPlaneConfig = new FormPlaneConfig(); + formPlaneConfig.Show(); + formPlaneConfig.AddEvent(AddPlane); } /// /// Удаление объекта из набора diff --git a/ProjectBomber/ProjectBomber/FormPlaneConfig.Designer.cs b/ProjectBomber/ProjectBomber/FormPlaneConfig.Designer.cs new file mode 100644 index 0000000..75c9dc3 --- /dev/null +++ b/ProjectBomber/ProjectBomber/FormPlaneConfig.Designer.cs @@ -0,0 +1,382 @@ +namespace ProjectBomber +{ + partial class FormPlaneConfig + { + /// + /// 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.groupBox1 = new System.Windows.Forms.GroupBox(); + this.labelModifiedObject = new System.Windows.Forms.Label(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.groupBoxColors = new System.Windows.Forms.GroupBox(); + this.panelPurple = new System.Windows.Forms.Panel(); + this.panelBlack = new System.Windows.Forms.Panel(); + this.panelGray = new System.Windows.Forms.Panel(); + this.panelWhite = new System.Windows.Forms.Panel(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelRed = new System.Windows.Forms.Panel(); + this.checkBoxLine = new System.Windows.Forms.CheckBox(); + this.checkBoxFuelTanks = new System.Windows.Forms.CheckBox(); + this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.checkBoxBombs = new System.Windows.Forms.CheckBox(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.panelObject = new System.Windows.Forms.Panel(); + this.pictureBoxObject = new System.Windows.Forms.PictureBox(); + this.labelAddColor = new System.Windows.Forms.Label(); + this.labelColor = new System.Windows.Forms.Label(); + this.ButtonOk = new System.Windows.Forms.Button(); + this.buttonCanel = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + this.groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); + this.panelObject.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.labelModifiedObject); + this.groupBox1.Controls.Add(this.labelSimpleObject); + this.groupBox1.Controls.Add(this.groupBoxColors); + this.groupBox1.Controls.Add(this.checkBoxLine); + this.groupBox1.Controls.Add(this.checkBoxFuelTanks); + this.groupBox1.Controls.Add(this.numericUpDownWeight); + this.groupBox1.Controls.Add(this.checkBoxBombs); + this.groupBox1.Controls.Add(this.numericUpDownSpeed); + this.groupBox1.Controls.Add(this.label2); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Location = new System.Drawing.Point(12, 12); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(530, 225); + this.groupBox1.TabIndex = 0; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Параметры"; + // + // labelModifiedObject + // + this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelModifiedObject.Location = new System.Drawing.Point(400, 183); + this.labelModifiedObject.Name = "labelModifiedObject"; + this.labelModifiedObject.Size = new System.Drawing.Size(93, 31); + this.labelModifiedObject.TabIndex = 9; + this.labelModifiedObject.Text = "Продвинутый"; + this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // labelSimpleObject + // + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Location = new System.Drawing.Point(273, 183); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(99, 31); + this.labelSimpleObject.TabIndex = 8; + this.labelSimpleObject.Text = "Простой"; + this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // groupBoxColors + // + this.groupBoxColors.Controls.Add(this.panelPurple); + this.groupBoxColors.Controls.Add(this.panelBlack); + this.groupBoxColors.Controls.Add(this.panelGray); + this.groupBoxColors.Controls.Add(this.panelWhite); + this.groupBoxColors.Controls.Add(this.panelYellow); + this.groupBoxColors.Controls.Add(this.panelBlue); + this.groupBoxColors.Controls.Add(this.panelGreen); + this.groupBoxColors.Controls.Add(this.panelRed); + this.groupBoxColors.Location = new System.Drawing.Point(273, 32); + this.groupBoxColors.Name = "groupBoxColors"; + this.groupBoxColors.Size = new System.Drawing.Size(245, 120); + this.groupBoxColors.TabIndex = 7; + this.groupBoxColors.TabStop = false; + this.groupBoxColors.Text = "Цвета"; + // + // panelPurple + // + this.panelPurple.BackColor = System.Drawing.Color.Purple; + this.panelPurple.Location = new System.Drawing.Point(192, 73); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(45, 40); + this.panelPurple.TabIndex = 7; + this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlack + // + this.panelBlack.BackColor = System.Drawing.Color.Black; + this.panelBlack.Location = new System.Drawing.Point(130, 73); + this.panelBlack.Name = "panelBlack"; + this.panelBlack.Size = new System.Drawing.Size(45, 40); + this.panelBlack.TabIndex = 6; + this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGray + // + this.panelGray.BackColor = System.Drawing.Color.Gray; + this.panelGray.Location = new System.Drawing.Point(68, 73); + this.panelGray.Name = "panelGray"; + this.panelGray.Size = new System.Drawing.Size(45, 40); + this.panelGray.TabIndex = 5; + this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelWhite + // + this.panelWhite.BackColor = System.Drawing.Color.White; + this.panelWhite.Location = new System.Drawing.Point(6, 73); + this.panelWhite.Name = "panelWhite"; + this.panelWhite.Size = new System.Drawing.Size(45, 40); + this.panelWhite.TabIndex = 4; + this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelYellow + // + this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.Location = new System.Drawing.Point(192, 19); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(45, 40); + this.panelYellow.TabIndex = 3; + this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlue + // + this.panelBlue.BackColor = System.Drawing.Color.Blue; + this.panelBlue.Location = new System.Drawing.Point(130, 19); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(45, 40); + this.panelBlue.TabIndex = 2; + this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGreen + // + this.panelGreen.BackColor = System.Drawing.Color.Green; + this.panelGreen.Location = new System.Drawing.Point(68, 19); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(45, 40); + this.panelGreen.TabIndex = 1; + this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelRed + // + this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.Location = new System.Drawing.Point(6, 19); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(45, 40); + this.panelRed.TabIndex = 0; + this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // checkBoxLine + // + this.checkBoxLine.AutoSize = true; + this.checkBoxLine.Location = new System.Drawing.Point(30, 183); + this.checkBoxLine.Name = "checkBoxLine"; + this.checkBoxLine.Size = new System.Drawing.Size(155, 17); + this.checkBoxLine.TabIndex = 6; + this.checkBoxLine.Text = "Признак наличия полосы"; + this.checkBoxLine.UseVisualStyleBackColor = true; + // + // checkBoxFuelTanks + // + this.checkBoxFuelTanks.AutoSize = true; + this.checkBoxFuelTanks.Location = new System.Drawing.Point(30, 149); + this.checkBoxFuelTanks.Name = "checkBoxFuelTanks"; + this.checkBoxFuelTanks.Size = new System.Drawing.Size(204, 17); + this.checkBoxFuelTanks.TabIndex = 5; + this.checkBoxFuelTanks.Text = "Признак наличия топливных баков"; + this.checkBoxFuelTanks.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(91, 71); + this.numericUpDownWeight.Name = "numericUpDownWeight"; + this.numericUpDownWeight.Size = new System.Drawing.Size(75, 20); + this.numericUpDownWeight.TabIndex = 4; + // + // checkBoxBombs + // + this.checkBoxBombs.AutoSize = true; + this.checkBoxBombs.Location = new System.Drawing.Point(30, 116); + this.checkBoxBombs.Name = "checkBoxBombs"; + this.checkBoxBombs.Size = new System.Drawing.Size(143, 17); + this.checkBoxBombs.TabIndex = 3; + this.checkBoxBombs.Text = "Признак наличия бомб"; + this.checkBoxBombs.UseVisualStyleBackColor = true; + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Increment = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownSpeed.Location = new System.Drawing.Point(91, 32); + this.numericUpDownSpeed.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownSpeed.Name = "numericUpDownSpeed"; + this.numericUpDownSpeed.Size = new System.Drawing.Size(75, 20); + this.numericUpDownSpeed.TabIndex = 2; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(27, 73); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(29, 13); + this.label2.TabIndex = 1; + this.label2.Text = "Вес:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(27, 32); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(58, 13); + this.label1.TabIndex = 0; + this.label1.Text = "Скорость:"; + // + // panelObject + // + this.panelObject.AllowDrop = true; + this.panelObject.Controls.Add(this.pictureBoxObject); + this.panelObject.Controls.Add(this.labelAddColor); + this.panelObject.Controls.Add(this.labelColor); + this.panelObject.Location = new System.Drawing.Point(558, 12); + this.panelObject.Name = "panelObject"; + this.panelObject.Size = new System.Drawing.Size(230, 187); + this.panelObject.TabIndex = 1; + this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); + this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); + // + // pictureBoxObject + // + this.pictureBoxObject.Location = new System.Drawing.Point(19, 48); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(190, 125); + this.pictureBoxObject.TabIndex = 2; + this.pictureBoxObject.TabStop = false; + // + // labelAddColor + // + this.labelAddColor.AllowDrop = true; + this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelAddColor.Location = new System.Drawing.Point(122, 18); + this.labelAddColor.Name = "labelAddColor"; + this.labelAddColor.Size = new System.Drawing.Size(88, 27); + this.labelAddColor.TabIndex = 1; + this.labelAddColor.Text = "Доп. цвет"; + this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelAddColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelAddColor_DragDrop); + this.labelAddColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter); + // + // labelColor + // + this.labelColor.AllowDrop = true; + this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelColor.Location = new System.Drawing.Point(17, 18); + this.labelColor.Name = "labelColor"; + this.labelColor.Size = new System.Drawing.Size(86, 27); + this.labelColor.TabIndex = 0; + this.labelColor.Text = "Цвет"; + this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop); + this.labelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter); + // + // ButtonOk + // + this.ButtonOk.Location = new System.Drawing.Point(577, 210); + this.ButtonOk.Name = "ButtonOk"; + this.ButtonOk.Size = new System.Drawing.Size(84, 27); + this.ButtonOk.TabIndex = 2; + this.ButtonOk.Text = "Добавить"; + this.ButtonOk.UseVisualStyleBackColor = true; + this.ButtonOk.Click += new System.EventHandler(this.ButtonOk_Click); + // + // buttonCanel + // + this.buttonCanel.Location = new System.Drawing.Point(683, 210); + this.buttonCanel.Name = "buttonCanel"; + this.buttonCanel.Size = new System.Drawing.Size(84, 27); + this.buttonCanel.TabIndex = 3; + this.buttonCanel.Text = "Отмена"; + this.buttonCanel.UseVisualStyleBackColor = true; + // + // FormPlaneConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 243); + this.Controls.Add(this.buttonCanel); + this.Controls.Add(this.ButtonOk); + this.Controls.Add(this.panelObject); + this.Controls.Add(this.groupBox1); + this.Name = "FormPlaneConfig"; + this.Text = "FormPlaneConfig"; + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + this.panelObject.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.NumericUpDown numericUpDownWeight; + private System.Windows.Forms.CheckBox checkBoxBombs; + private System.Windows.Forms.NumericUpDown numericUpDownSpeed; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.CheckBox checkBoxFuelTanks; + private System.Windows.Forms.Label labelModifiedObject; + private System.Windows.Forms.Label labelSimpleObject; + private System.Windows.Forms.GroupBox groupBoxColors; + private System.Windows.Forms.Panel panelPurple; + private System.Windows.Forms.Panel panelBlack; + private System.Windows.Forms.Panel panelGray; + private System.Windows.Forms.Panel panelWhite; + private System.Windows.Forms.Panel panelYellow; + private System.Windows.Forms.Panel panelBlue; + private System.Windows.Forms.Panel panelGreen; + private System.Windows.Forms.Panel panelRed; + private System.Windows.Forms.CheckBox checkBoxLine; + private System.Windows.Forms.Panel panelObject; + private System.Windows.Forms.PictureBox pictureBoxObject; + private System.Windows.Forms.Label labelAddColor; + private System.Windows.Forms.Label labelColor; + private System.Windows.Forms.Button ButtonOk; + private System.Windows.Forms.Button buttonCanel; + } +} \ No newline at end of file diff --git a/ProjectBomber/ProjectBomber/FormPlaneConfig.cs b/ProjectBomber/ProjectBomber/FormPlaneConfig.cs new file mode 100644 index 0000000..4a4fa22 --- /dev/null +++ b/ProjectBomber/ProjectBomber/FormPlaneConfig.cs @@ -0,0 +1,176 @@ +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 ProjectBomber.DrawningObjects; +using ProjectBomber.Entities; + +namespace ProjectBomber +{ + public partial class FormPlaneConfig : Form + { + /// + /// Переменная-выбранный самолет + /// + DrawningBomber _plane = null; + /// + /// Событие + /// + private event Action EventAddPlane; + /// + /// Конструктор + /// + public FormPlaneConfig() + { + InitializeComponent(); + panelBlack.MouseDown += PanelColor_MouseDown; + panelPurple.MouseDown += PanelColor_MouseDown; + panelGray.MouseDown += PanelColor_MouseDown; + panelGreen.MouseDown += PanelColor_MouseDown; + panelRed.MouseDown += PanelColor_MouseDown; + panelWhite.MouseDown += PanelColor_MouseDown; + panelYellow.MouseDown += PanelColor_MouseDown; + panelBlue.MouseDown += PanelColor_MouseDown; + buttonCanel.Click += (s, e) => Close(); + } + /// + /// Отрисовать самолет + /// + private void DrawPlane() + { + Bitmap bmp = new Bitmap(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _plane?.SetPosition(5, 5); + _plane?.DrawTransport(gr); + if (_plane is DrawningBomber) + (_plane as DrawningBomber).DrawTransport(gr); + else + _plane?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + /// + /// Проверка получаемой информации (ее типа на соответствие требуемому) + /// + /// + /// + private void PanelObject_DragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + /// + /// Действия при приеме перетаскиваемой информации + /// + /// + /// + private void PanelObject_DragDrop(object sender, DragEventArgs e) + { + switch (e.Data?.GetData(DataFormats.Text).ToString()) + { + case "labelSimpleObject": + _plane = new DrawningBomber((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + case "labelModifiedObject": + _plane = new DrawningBomberAdvanced((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxBombs.Checked, + checkBoxFuelTanks.Checked, checkBoxLine.Checked, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + } + DrawPlane(); + } + /// + /// Добавление события + /// + /// Привязанный метод + public void AddEvent(Action ev) + { + if (EventAddPlane == null) + { + EventAddPlane = ev; + } + else + { + EventAddPlane += ev; + } + } + /// + /// Добавление машины + /// + /// + /// + private void ButtonOk_Click(object sender, EventArgs e) + { + EventAddPlane?.Invoke(_plane); + Close(); + } + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, + DragDropEffects.Move | DragDropEffects.Copy); + } + /// + /// Передаем информацию при нажатии на Label + /// + /// + /// + private void LabelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name, + DragDropEffects.Move | DragDropEffects.Copy); + } + /// + /// Проверка получаемой информации (ее типа на соответствие требуемому) + /// + /// + /// + private void labelColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + /// + /// Действия при приеме перетаскиваемой информации об обычном цвете + /// + /// + /// + private void LabelColor_DragDrop(object sender, DragEventArgs e) + { + + if (_plane is DrawningBomber plane) + { + labelColor.BackColor = (Color)e.Data.GetData(typeof(Color)); + plane.setColor((Color)e.Data.GetData(typeof(Color))); + } + DrawPlane(); + } + private void LabelAddColor_DragDrop(object sender, DragEventArgs e) + { + if (_plane is DrawningBomberAdvanced bomber) + { + labelAddColor.BackColor = (Color)e.Data.GetData(typeof(Color)); + bomber.setAddColor((Color)e.Data.GetData(typeof(Color))); + } + DrawPlane(); + } + } +} diff --git a/ProjectBomber/ProjectBomber/FormPlaneConfig.resx b/ProjectBomber/ProjectBomber/FormPlaneConfig.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ProjectBomber/ProjectBomber/FormPlaneConfig.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/ProjectBomber/ProjectBomber/PlanesGenericCollection.cs b/ProjectBomber/ProjectBomber/PlanesGenericCollection.cs index 9042780..e2df145 100644 --- a/ProjectBomber/ProjectBomber/PlanesGenericCollection.cs +++ b/ProjectBomber/ProjectBomber/PlanesGenericCollection.cs @@ -21,11 +21,11 @@ namespace ProjectBomber.Generics /// /// Ширина окна прорисовки /// - private readonly int _pictureWidth; + private readonly int pictureWidth; /// /// Высота окна прорисовки /// - private readonly int _pictureHeight; + private readonly int pictureHeight; /// /// Размер занимаемого объектом места (ширина) /// @@ -47,8 +47,8 @@ namespace ProjectBomber.Generics { int width = picWidth / _placeSizeWidth; int height = picHeight / _placeSizeHeight; - _pictureWidth = picWidth; - _pictureHeight = picHeight; + pictureWidth = picWidth; + pictureHeight = picHeight; _collection = new SetGeneric(width * height); } /// @@ -57,15 +57,14 @@ namespace ProjectBomber.Generics /// /// /// - public static bool operator +(PlanesGenericCollection collect, T + public static int operator +(PlanesGenericCollection collect, T obj) { if (obj == null) { - return false; + return -1; } - collect?._collection.Insert(obj); - return true; + return collect?._collection.Insert(obj) ?? -1; } /// /// Перегрузка оператора вычитания @@ -97,7 +96,7 @@ namespace ProjectBomber.Generics /// public Bitmap ShowPlanes() { - Bitmap bmp = new Bitmap(_pictureWidth, _pictureHeight); + Bitmap bmp = new Bitmap(pictureWidth, pictureHeight); Graphics gr = Graphics.FromImage(bmp); DrawBackground(gr); DrawObjects(gr); @@ -110,9 +109,8 @@ namespace ProjectBomber.Generics private void DrawBackground(Graphics g) { Pen pen = new Pen(Color.Black, 3); - int numColumns = _pictureWidth / _placeSizeWidth; - int numRows = _pictureHeight / _placeSizeHeight; - + int numColumns = pictureWidth / _placeSizeWidth; + int numRows = pictureHeight / _placeSizeHeight; for (int i = 0; i <= numColumns; i++) { for (int j = 0; j <= numRows; ++j) @@ -122,7 +120,6 @@ namespace ProjectBomber.Generics int y = j * _placeSizeHeight; g.DrawLine(pen, x, y, x + _placeSizeWidth / 2, y); } - g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, numRows * _placeSizeHeight); } } @@ -132,11 +129,13 @@ namespace ProjectBomber.Generics /// private void DrawObjects(Graphics g) { - int numColumns = _pictureWidth / _placeSizeWidth; + int numColumns = pictureWidth / _placeSizeWidth; int column = numColumns - 1; int row = 0; foreach (var plane in _collection.GetPlanes()) { + plane._pictureHeight = pictureHeight; + plane._pictureWidth = pictureWidth; // Установка позиции бомбардировщика int xPosition = column * _placeSizeWidth; int yPosition = row * _placeSizeHeight; diff --git a/ProjectBomber/ProjectBomber/ProjectBomber.csproj b/ProjectBomber/ProjectBomber/ProjectBomber.csproj index da00a5f..0995e87 100644 --- a/ProjectBomber/ProjectBomber/ProjectBomber.csproj +++ b/ProjectBomber/ProjectBomber/ProjectBomber.csproj @@ -80,6 +80,12 @@ FormPlaneCollection.cs + + Form + + + FormPlaneConfig.cs + @@ -96,6 +102,9 @@ FormPlaneCollection.cs + + FormPlaneConfig.cs + ResXFileCodeGenerator Resources.Designer.cs diff --git a/ProjectBomber/ProjectBomber/SetGeneric.cs b/ProjectBomber/ProjectBomber/SetGeneric.cs index 7daede8..6c43c39 100644 --- a/ProjectBomber/ProjectBomber/SetGeneric.cs +++ b/ProjectBomber/ProjectBomber/SetGeneric.cs @@ -39,12 +39,12 @@ namespace ProjectBomber.Generics /// /// Добавляемый самолет /// - public bool Insert(T plane) + public int Insert(T plane) { if (_places.Count == 0) { _places.Add(plane); - return true; + return 0; } else { @@ -57,10 +57,10 @@ namespace ProjectBomber.Generics _places[i] = _places[_places.Count - 1]; _places[_places.Count - 1] = temp; } - return true; + return 0; } } - return true; + return 0; } /// /// Добавление объекта в набор на конкретную позицию