diff --git a/Bulldozer/Bulldozer/DrawingObjects/DrawingBulldozer.cs b/Bulldozer/Bulldozer/DrawingObjects/DrawingBulldozer.cs index 6f623d8..fc088a3 100644 --- a/Bulldozer/Bulldozer/DrawingObjects/DrawingBulldozer.cs +++ b/Bulldozer/Bulldozer/DrawingObjects/DrawingBulldozer.cs @@ -15,11 +15,11 @@ namespace Bulldozer.DrawingObjects /// /// Ширина окна /// - private int _pictureWidth; + public int _pictureWidth; /// /// Высота окна /// - private int _pictureHeight; + public int _pictureHeight; /// /// Координата прорисовки по оси X /// @@ -64,11 +64,16 @@ namespace Bulldozer.DrawingObjects /// Высота прорисовки бульдозера protected DrawingBulldozer(int speed, double weight, Color bodyColor, Color additionalColor, int width, int height, int bulldozerWidth, int bulldozerHeight) { - _pictureWidth = width; - _pictureHeight = height; - _bulldozerWidth = bulldozerWidth; - _bulldozerHeight = bulldozerHeight; - EntityBulldozer = new EntityBulldozer(speed, weight, bodyColor, additionalColor); + if (width < _bulldozerWidth || height < _bulldozerHeight) + { + return; + } + + _pictureWidth = width; + _pictureHeight = height; + _bulldozerWidth = bulldozerWidth; + _bulldozerHeight = bulldozerHeight; + EntityBulldozer = new EntityBulldozer(speed, weight, bodyColor, additionalColor); } /// @@ -133,7 +138,7 @@ namespace Bulldozer.DrawingObjects /// Изменение направления перемещения /// /// Направление - public void MoveBulldozer(DirectionType direction) + public void MoveTransport(DirectionType direction) { if (!CanMove(direction) || EntityBulldozer == null) { @@ -163,7 +168,7 @@ namespace Bulldozer.DrawingObjects /// Прорисовка объекта /// /// - public virtual void DrawBulldozer(Graphics g) + public virtual void DrawTransport(Graphics g) { if (EntityBulldozer == null) { diff --git a/Bulldozer/Bulldozer/DrawingObjects/DrawingUpgradedBulldozer.cs b/Bulldozer/Bulldozer/DrawingObjects/DrawingUpgradedBulldozer.cs index eef24ea..06c6817 100644 --- a/Bulldozer/Bulldozer/DrawingObjects/DrawingUpgradedBulldozer.cs +++ b/Bulldozer/Bulldozer/DrawingObjects/DrawingUpgradedBulldozer.cs @@ -25,19 +25,18 @@ namespace Bulldozer.DrawingObjects EntityBulldozer = new EntityBulldozerUpgraded(speed, weight, bodyColor, additionalColor, dopColor, blade, ripper); } } - - public override void DrawBulldozer(Graphics g) + public override void DrawTransport(Graphics g) { if (EntityBulldozer is not EntityBulldozerUpgraded upgradedBulldozer) { return; } - Pen dopPen = new(upgradedBulldozer.DopColor); Brush dopBrush = new SolidBrush(upgradedBulldozer.DopColor); + Pen dopPen = new Pen(upgradedBulldozer.DopColor); /// /// Отрисовка отвала бульдозера /// - base.DrawBulldozer(g); + base.DrawTransport(g); if (upgradedBulldozer.Blade) { Point point1 = new Point(_startPosX + 8, _startPosY + 29); @@ -51,6 +50,7 @@ namespace Bulldozer.DrawingObjects g.DrawRectangle(dopPen, _startPosX + 8, _startPosY + 29, 8, 8); // обводка основания отвала g.DrawPolygon(dopPen, triangle); // обводка отвала } + /// /// Отрисовка рыхлителя бульдозера /// diff --git a/Bulldozer/Bulldozer/Entities/EntityBulldozer.cs b/Bulldozer/Bulldozer/Entities/EntityBulldozer.cs index c2e09fa..c10f135 100644 --- a/Bulldozer/Bulldozer/Entities/EntityBulldozer.cs +++ b/Bulldozer/Bulldozer/Entities/EntityBulldozer.cs @@ -22,7 +22,6 @@ namespace Bulldozer.Entities public Color AdditionalColor { get; private set; } - public Color DopColor { get; private set; } /// /// Шаг перемещения бульдозера /// @@ -40,8 +39,10 @@ namespace Bulldozer.Entities BodyColor = bodyColor; AdditionalColor = additionalColor; } + public void SetBodyColor(Color bodyColor) + { + BodyColor = bodyColor; + } } - - } diff --git a/Bulldozer/Bulldozer/Entities/EntityBulldozerUpgraded.cs b/Bulldozer/Bulldozer/Entities/EntityBulldozerUpgraded.cs index e22f4ed..957904b 100644 --- a/Bulldozer/Bulldozer/Entities/EntityBulldozerUpgraded.cs +++ b/Bulldozer/Bulldozer/Entities/EntityBulldozerUpgraded.cs @@ -10,6 +10,7 @@ /// Отвал бульдозера /// public bool Blade { get; private set; } + /// /// Рыхлитель бульдозера /// @@ -25,11 +26,16 @@ /// Отвал бульдозера /// Рыхлитель бульдозера public EntityBulldozerUpgraded(int speed, double weight, Color bodyColor, Color additionalColor, Color dopColor, bool blade, bool ripper) : - base(speed, weight, bodyColor, additionalColor) + base(speed, weight, bodyColor, additionalColor) { DopColor = dopColor; Blade = blade; Ripper = ripper; } + + public void SetDopColor(Color dopColor) + { + DopColor = dopColor; + } } } diff --git a/Bulldozer/Bulldozer/FormBulldozer.cs b/Bulldozer/Bulldozer/FormBulldozer.cs index f235f47..722bfa0 100644 --- a/Bulldozer/Bulldozer/FormBulldozer.cs +++ b/Bulldozer/Bulldozer/FormBulldozer.cs @@ -41,7 +41,7 @@ namespace Bulldozer } Bitmap bmp = new(pictureBoxBulldozer.Width, pictureBoxBulldozer.Height); Graphics gr = Graphics.FromImage(bmp); - _drawingBulldozer.DrawBulldozer(gr); + _drawingBulldozer.DrawTransport(gr); pictureBoxBulldozer.Image = bmp; } @@ -60,16 +60,16 @@ namespace Bulldozer switch (name) { case "buttonUp": - _drawingBulldozer.MoveBulldozer(DirectionType.Up); + _drawingBulldozer.MoveTransport(DirectionType.Up); break; case "buttonDown": - _drawingBulldozer.MoveBulldozer(DirectionType.Down); + _drawingBulldozer.MoveTransport(DirectionType.Down); break; case "buttonLeft": - _drawingBulldozer.MoveBulldozer(DirectionType.Left); + _drawingBulldozer.MoveTransport(DirectionType.Left); break; case "buttonRight": - _drawingBulldozer.MoveBulldozer(DirectionType.Right); + _drawingBulldozer.MoveTransport(DirectionType.Right); break; } Draw(); diff --git a/Bulldozer/Bulldozer/FormBulldozerCollection.cs b/Bulldozer/Bulldozer/FormBulldozerCollection.cs index df57677..f498020 100644 --- a/Bulldozer/Bulldozer/FormBulldozerCollection.cs +++ b/Bulldozer/Bulldozer/FormBulldozerCollection.cs @@ -90,6 +90,7 @@ namespace Bulldozer /// /// /// + private void buttonAddBulldozer_Click(object sender, EventArgs e) { if (listBoxBulldozerStorages.SelectedIndex == -1) @@ -97,27 +98,34 @@ namespace Bulldozer MessageBox.Show("Выберите набор в списке.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + var formBulldozerConfig = new FormBulldozerConfig(); + formBulldozerConfig.AddEvent(AddBulldozer); + formBulldozerConfig.Show(); + } + private void AddBulldozer(DrawingBulldozer bulldozer) + { + bulldozer._pictureWidth = pictureBoxCollection.Width; + bulldozer._pictureHeight = pictureBoxCollection.Height; + + if (listBoxBulldozerStorages.SelectedIndex == -1) return; + var obj = _storage[listBoxBulldozerStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { - MessageBox.Show("Выбранный набор не найден.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - FormBulldozer form = new(); - if (form.ShowDialog() == DialogResult.OK) + if (obj + bulldozer > -1) { - if (obj + form.SelectedBulldozer > -1) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowBulldozers(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowBulldozers(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } } + /// /// Удаление объекта из набора /// diff --git a/Bulldozer/Bulldozer/FormBulldozerConfig.Designer.cs b/Bulldozer/Bulldozer/FormBulldozerConfig.Designer.cs new file mode 100644 index 0000000..3ddc87c --- /dev/null +++ b/Bulldozer/Bulldozer/FormBulldozerConfig.Designer.cs @@ -0,0 +1,435 @@ +namespace Bulldozer +{ + partial class FormBulldozerConfig + { + /// + /// 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.groupBoxParameters = new System.Windows.Forms.GroupBox(); + this.groupBoxMarks = new System.Windows.Forms.GroupBox(); + this.checkBoxRipper = new System.Windows.Forms.CheckBox(); + this.checkBoxBlade = new System.Windows.Forms.CheckBox(); + 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.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.labelWeight = new System.Windows.Forms.Label(); + this.labelSpeed = new System.Windows.Forms.Label(); + this.pictureBoxObject = new System.Windows.Forms.PictureBox(); + this.panelObject = new System.Windows.Forms.Panel(); + this.labelAddColor = new System.Windows.Forms.Label(); + this.labelColor = new System.Windows.Forms.Label(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBoxParameters.SuspendLayout(); + this.groupBoxMarks.SuspendLayout(); + this.groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); + this.panelObject.SuspendLayout(); + this.SuspendLayout(); + // + // groupBoxParameters + // + this.groupBoxParameters.Controls.Add(this.groupBoxMarks); + this.groupBoxParameters.Controls.Add(this.labelModifiedObject); + this.groupBoxParameters.Controls.Add(this.labelSimpleObject); + this.groupBoxParameters.Controls.Add(this.groupBoxColors); + this.groupBoxParameters.Controls.Add(this.numericUpDownWeight); + this.groupBoxParameters.Controls.Add(this.numericUpDownSpeed); + this.groupBoxParameters.Controls.Add(this.labelWeight); + this.groupBoxParameters.Controls.Add(this.labelSpeed); + this.groupBoxParameters.Location = new System.Drawing.Point(10, 10); + this.groupBoxParameters.Margin = new System.Windows.Forms.Padding(2); + this.groupBoxParameters.Name = "groupBoxParameters"; + this.groupBoxParameters.Padding = new System.Windows.Forms.Padding(2); + this.groupBoxParameters.Size = new System.Drawing.Size(586, 272); + this.groupBoxParameters.TabIndex = 0; + this.groupBoxParameters.TabStop = false; + this.groupBoxParameters.Text = "Параметры"; + // + // groupBoxMarks + // + this.groupBoxMarks.Controls.Add(this.checkBoxRipper); + this.groupBoxMarks.Controls.Add(this.checkBoxBlade); + this.groupBoxMarks.Location = new System.Drawing.Point(24, 133); + this.groupBoxMarks.Name = "groupBoxMarks"; + this.groupBoxMarks.Size = new System.Drawing.Size(250, 116); + this.groupBoxMarks.TabIndex = 9; + this.groupBoxMarks.TabStop = false; + this.groupBoxMarks.Text = "Признаки"; + // + // checkBoxRipper + // + this.checkBoxRipper.AutoSize = true; + this.checkBoxRipper.Location = new System.Drawing.Point(17, 41); + this.checkBoxRipper.Margin = new System.Windows.Forms.Padding(2); + this.checkBoxRipper.Name = "checkBoxRipper"; + this.checkBoxRipper.Size = new System.Drawing.Size(170, 24); + this.checkBoxRipper.TabIndex = 4; + this.checkBoxRipper.Text = "Наличие рыхлителя"; + this.checkBoxRipper.UseVisualStyleBackColor = true; + // + // checkBoxBlade + // + this.checkBoxBlade.AutoSize = true; + this.checkBoxBlade.Location = new System.Drawing.Point(17, 74); + this.checkBoxBlade.Margin = new System.Windows.Forms.Padding(2); + this.checkBoxBlade.Name = "checkBoxBlade"; + this.checkBoxBlade.Size = new System.Drawing.Size(143, 24); + this.checkBoxBlade.TabIndex = 5; + this.checkBoxBlade.Text = "Наличие отвала"; + this.checkBoxBlade.UseVisualStyleBackColor = true; + // + // labelModifiedObject + // + this.labelModifiedObject.BackColor = System.Drawing.SystemColors.ActiveCaption; + this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelModifiedObject.Location = new System.Drawing.Point(450, 180); + this.labelModifiedObject.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelModifiedObject.Name = "labelModifiedObject"; + this.labelModifiedObject.Size = new System.Drawing.Size(107, 69); + this.labelModifiedObject.TabIndex = 8; + this.labelModifiedObject.Text = "Продвинутый"; + this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelModifiedObject.MouseDown += labelObject_MouseDown; + // + // labelSimpleObject + // + this.labelSimpleObject.BackColor = System.Drawing.SystemColors.ActiveCaption; + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Location = new System.Drawing.Point(329, 180); + this.labelSimpleObject.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(102, 69); + this.labelSimpleObject.TabIndex = 7; + this.labelSimpleObject.Text = "Простой"; + this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelSimpleObject.MouseDown += 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(311, 16); + this.groupBoxColors.Margin = new System.Windows.Forms.Padding(2); + this.groupBoxColors.Name = "groupBoxColors"; + this.groupBoxColors.Padding = new System.Windows.Forms.Padding(2); + this.groupBoxColors.Size = new System.Drawing.Size(259, 155); + this.groupBoxColors.TabIndex = 6; + this.groupBoxColors.TabStop = false; + this.groupBoxColors.Text = "Цвета"; + this.groupBoxColors.DragDrop += PanelObject_DragDrop; + this.groupBoxColors.DragEnter += PanelObject_DragEnter; + // + // panelPurple + // + this.panelPurple.BackColor = System.Drawing.Color.Purple; + this.panelPurple.Location = new System.Drawing.Point(194, 90); + this.panelPurple.Margin = new System.Windows.Forms.Padding(2); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(43, 43); + this.panelPurple.TabIndex = 1; + this.panelPurple.MouseDown += panelColor_MouseDown; + // + // panelBlack + // + this.panelBlack.BackColor = System.Drawing.Color.Black; + this.panelBlack.Location = new System.Drawing.Point(135, 90); + this.panelBlack.Margin = new System.Windows.Forms.Padding(2); + this.panelBlack.Name = "panelBlack"; + this.panelBlack.Size = new System.Drawing.Size(43, 43); + this.panelBlack.TabIndex = 1; + this.panelBlack.MouseDown += panelColor_MouseDown; + // + // panelGray + // + this.panelGray.BackColor = System.Drawing.Color.Gray; + this.panelGray.Location = new System.Drawing.Point(77, 90); + this.panelGray.Margin = new System.Windows.Forms.Padding(2); + this.panelGray.Name = "panelGray"; + this.panelGray.Size = new System.Drawing.Size(43, 43); + this.panelGray.TabIndex = 1; + this.panelGray.MouseDown += panelColor_MouseDown; + // + // panelWhite + // + this.panelWhite.BackColor = System.Drawing.Color.White; + this.panelWhite.Location = new System.Drawing.Point(18, 90); + this.panelWhite.Margin = new System.Windows.Forms.Padding(2); + this.panelWhite.Name = "panelWhite"; + this.panelWhite.Size = new System.Drawing.Size(43, 43); + this.panelWhite.TabIndex = 1; + this.panelWhite.MouseDown += panelColor_MouseDown; + // + // panelYellow + // + this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.Location = new System.Drawing.Point(194, 34); + this.panelYellow.Margin = new System.Windows.Forms.Padding(2); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(43, 43); + this.panelYellow.TabIndex = 1; + this.panelYellow.MouseDown += panelColor_MouseDown; + // + // panelBlue + // + this.panelBlue.BackColor = System.Drawing.Color.Blue; + this.panelBlue.Location = new System.Drawing.Point(135, 34); + this.panelBlue.Margin = new System.Windows.Forms.Padding(2); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(43, 43); + this.panelBlue.TabIndex = 1; + this.panelBlue.MouseDown += panelColor_MouseDown; + // + // panelGreen + // + this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0))))); + this.panelGreen.Location = new System.Drawing.Point(77, 34); + this.panelGreen.Margin = new System.Windows.Forms.Padding(2); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(43, 43); + this.panelGreen.TabIndex = 1; + this.panelGreen.MouseDown += panelColor_MouseDown; + // + // panelRed + // + this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.Location = new System.Drawing.Point(18, 34); + this.panelRed.Margin = new System.Windows.Forms.Padding(2); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(43, 43); + this.panelRed.TabIndex = 0; + this.panelRed.MouseDown += panelColor_MouseDown; + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(117, 75); + this.numericUpDownWeight.Margin = new System.Windows.Forms.Padding(2); + this.numericUpDownWeight.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownWeight.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownWeight.Name = "numericUpDownWeight"; + this.numericUpDownWeight.Size = new System.Drawing.Size(144, 27); + this.numericUpDownWeight.TabIndex = 3; + this.numericUpDownWeight.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(117, 42); + this.numericUpDownSpeed.Margin = new System.Windows.Forms.Padding(2); + this.numericUpDownSpeed.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownSpeed.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownSpeed.Name = "numericUpDownSpeed"; + this.numericUpDownSpeed.Size = new System.Drawing.Size(144, 27); + this.numericUpDownSpeed.TabIndex = 2; + this.numericUpDownSpeed.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // labelWeight + // + this.labelWeight.AutoSize = true; + this.labelWeight.Location = new System.Drawing.Point(24, 80); + this.labelWeight.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelWeight.Name = "labelWeight"; + this.labelWeight.Size = new System.Drawing.Size(33, 20); + this.labelWeight.TabIndex = 1; + this.labelWeight.Text = "Вес"; + // + // labelSpeed + // + this.labelSpeed.AutoSize = true; + this.labelSpeed.Location = new System.Drawing.Point(24, 43); + this.labelSpeed.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelSpeed.Name = "labelSpeed"; + this.labelSpeed.Size = new System.Drawing.Size(73, 20); + this.labelSpeed.TabIndex = 0; + this.labelSpeed.Text = "Скорость"; + // + // pictureBoxObject + // + this.pictureBoxObject.Location = new System.Drawing.Point(26, 49); + this.pictureBoxObject.Margin = new System.Windows.Forms.Padding(2); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(286, 140); + this.pictureBoxObject.TabIndex = 1; + this.pictureBoxObject.TabStop = false; + // + // panelObject + // + this.panelObject.AllowDrop = true; + this.panelObject.Controls.Add(this.labelAddColor); + this.panelObject.Controls.Add(this.labelColor); + this.panelObject.Controls.Add(this.pictureBoxObject); + this.panelObject.Location = new System.Drawing.Point(621, 18); + this.panelObject.Margin = new System.Windows.Forms.Padding(2); + this.panelObject.Name = "panelObject"; + this.panelObject.Size = new System.Drawing.Size(334, 202); + this.panelObject.TabIndex = 2; + this. panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // + // labelAddColor + // + this.labelAddColor.AllowDrop = true; + this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelAddColor.Location = new System.Drawing.Point(180, 7); + this.labelAddColor.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelAddColor.Name = "labelAddColor"; + this.labelAddColor.Size = new System.Drawing.Size(132, 40); + this.labelAddColor.TabIndex = 3; + this.labelAddColor.Text = "Дополн. цвет"; + this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelAddColor.DragDrop += labelColor_dragDrop; + this.labelAddColor.DragEnter += labelColor_dragEnter; + // + // labelColor + // + this.labelColor.AllowDrop = true; + this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelColor.Location = new System.Drawing.Point(26, 7); + this.labelColor.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelColor.Name = "labelColor"; + this.labelColor.Size = new System.Drawing.Size(132, 40); + this.labelColor.TabIndex = 2; + this.labelColor.Text = "Основной цвет"; + this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelColor.DragDrop += labelColor_dragDrop; + this.labelColor.DragEnter += labelColor_dragEnter; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(626, 233); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(152, 41); + this.buttonAdd.TabIndex = 3; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += buttonAdd_Click; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(794, 233); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(152, 41); + this.buttonCancel.TabIndex = 4; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // FormBulldozerConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(978, 291); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.panelObject); + this.Controls.Add(this.groupBoxParameters); + this.Margin = new System.Windows.Forms.Padding(2); + this.Name = "FormBulldozerConfig"; + this.Text = "Создание объекта"; + this.groupBoxParameters.ResumeLayout(false); + this.groupBoxParameters.PerformLayout(); + this.groupBoxMarks.ResumeLayout(false); + this.groupBoxMarks.PerformLayout(); + this.groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); + this.panelObject.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxParameters; + private CheckBox checkBoxBlade; + private CheckBox checkBoxRipper; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelWeight; + private Label labelSpeed; + private Label labelModifiedObject; + private Label labelSimpleObject; + private GroupBox groupBoxColors; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelGray; + private Panel panelWhite; + private Panel panelYellow; + private Panel panelBlue; + private Panel panelGreen; + private Panel panelRed; + private PictureBox pictureBoxObject; + private Panel panelObject; + private Label labelAddColor; + private Label labelColor; + private Button buttonAdd; + private Button buttonCancel; + private GroupBox groupBoxMarks; + } +} \ No newline at end of file diff --git a/Bulldozer/Bulldozer/FormBulldozerConfig.cs b/Bulldozer/Bulldozer/FormBulldozerConfig.cs new file mode 100644 index 0000000..a519b95 --- /dev/null +++ b/Bulldozer/Bulldozer/FormBulldozerConfig.cs @@ -0,0 +1,146 @@ +using Bulldozer.Entities; +using Bulldozer.DrawingObjects; + +namespace Bulldozer +{ + public partial class FormBulldozerConfig : Form + { + /// + /// Переменная-выбранный бульдозер + /// + DrawingBulldozer? _bulldozer = null; + + /// + /// Делегат для передачи объекта-бульдозера + /// + private event Action? EventAddBulldozer; + + /// + /// Конструктор + /// + public FormBulldozerConfig() + { + 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; + buttonCancel.Click += (s, e) => Close(); + } + + private void DrawBulldozer() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _bulldozer?.SetPosition(5, 5); + _bulldozer?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + /// + /// Добавление события + /// + /// Привязанный метод + public void AddEvent(Action ev) + { + if (EventAddBulldozer == null) + { + EventAddBulldozer = ev; + } + else + { + EventAddBulldozer += ev; + } + } + /// + /// Передаем информацию при нажатии на Label + /// + /// + /// + private void labelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); + } + + /// + /// Проверка получаемой информации (ее типа на соответствие требуемому) + /// + /// + /// + 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": + _bulldozer = new DrawingBulldozer((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Cyan, pictureBoxObject.Width, pictureBoxObject.Height); + break; + case "labelModifiedObject": + _bulldozer = new DrawingBulldozerUpgraded((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, Color.Blue,checkBoxRipper.Checked, checkBoxBlade.Checked, pictureBoxObject.Width, pictureBoxObject.Height); + break; + } + DrawBulldozer(); + } + + public void panelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + private void labelColor_dragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(typeof(Color)) ?? false) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + private void labelColor_dragDrop(object sender, DragEventArgs e) + { + if (_bulldozer == null) + return; + switch (((Label)sender).Name) + { + case "labelColor": + _bulldozer?.EntityBulldozer?.SetBodyColor((Color) e.Data.GetData(typeof(Color))); + break; + case "labelAddColor": + if (!(_bulldozer is DrawingBulldozerUpgraded)) + return; + (_bulldozer.EntityBulldozer as EntityBulldozerUpgraded)?.SetDopColor(dopColor: (Color) e.Data.GetData(typeof(Color))); + break; + } + DrawBulldozer(); + } + /// + /// Добавление бульдозера + /// + /// + /// + private void buttonAdd_Click(object sender, EventArgs e) + { + EventAddBulldozer?.Invoke(_bulldozer); + Close(); + } + } +} diff --git a/Bulldozer/Bulldozer/FormBulldozerConfig.resx b/Bulldozer/Bulldozer/FormBulldozerConfig.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Bulldozer/Bulldozer/FormBulldozerConfig.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/Bulldozer/Bulldozer/Generics/BulldozersGenericCollection.cs b/Bulldozer/Bulldozer/Generics/BulldozersGenericCollection.cs index 5102687..31c227c 100644 --- a/Bulldozer/Bulldozer/Generics/BulldozersGenericCollection.cs +++ b/Bulldozer/Bulldozer/Generics/BulldozersGenericCollection.cs @@ -68,6 +68,7 @@ namespace Bulldozer.Generics } return obj; } + /// /// Получение объекта IMoveableObject /// @@ -77,6 +78,7 @@ namespace Bulldozer.Generics { return (U?)_collection[pos]?.GetMoveableObject; } + /// /// Вывод всего набора объектов /// @@ -89,6 +91,7 @@ namespace Bulldozer.Generics DrawObjects(gr); return bmp; } + /// /// Метод отрисовки фона /// @@ -109,6 +112,7 @@ namespace Bulldozer.Generics _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); } } + /// /// Метод прорисовки объектов /// @@ -128,14 +132,16 @@ namespace Bulldozer.Generics int row = heightObjCount - 1 - (i / widthObjCount); bulldozer.SetPosition(col * _placeSizeWidth + 3, row * _placeSizeHeight + 3); - bulldozer?.DrawBulldozer(g); + bulldozer?.DrawTransport(g); i++; } + if (i > totalObjects) { return; } - } + } + } } } diff --git a/Bulldozer/Bulldozer/Generics/SetGeneric.cs b/Bulldozer/Bulldozer/Generics/SetGeneric.cs index 33aa1c1..9873cb8 100644 --- a/Bulldozer/Bulldozer/Generics/SetGeneric.cs +++ b/Bulldozer/Bulldozer/Generics/SetGeneric.cs @@ -17,10 +17,12 @@ namespace Bulldozer.Generics /// Количество объектов в списке /// public int Count => _places.Count; + /// /// Максимальное количество объектов в списке /// private readonly int _maxCount; + /// /// Конструктор /// @@ -30,6 +32,7 @@ namespace Bulldozer.Generics _maxCount = count; _places = new List(); } + /// /// Добавление объекта в набор /// @@ -54,6 +57,7 @@ namespace Bulldozer.Generics _places.Insert(position, bulldozer); return position; } + /// /// Удаление объекта из набора с конкретной позиции /// @@ -63,9 +67,12 @@ namespace Bulldozer.Generics { if (position < 0 || position >= Count) return false; + + _places.RemoveAt(position); return true; } + /// /// Получение объекта из набора по позиции /// @@ -80,6 +87,7 @@ namespace Bulldozer.Generics } return _places[position]; } + /// /// Получение объекта из набора по позиции /// @@ -98,6 +106,7 @@ namespace Bulldozer.Generics _places.Insert(position, value); } } + /// /// Проход по списку /// diff --git a/Bulldozer/Bulldozer/MovementStrategy/DrawingObjectBulldozer.cs b/Bulldozer/Bulldozer/MovementStrategy/DrawingObjectBulldozer.cs index 9073766..98bc35a 100644 --- a/Bulldozer/Bulldozer/MovementStrategy/DrawingObjectBulldozer.cs +++ b/Bulldozer/Bulldozer/MovementStrategy/DrawingObjectBulldozer.cs @@ -26,6 +26,6 @@ namespace Bulldozer.MovementStrategy } public int GetStep => (int)(_drawingBulldozer?.EntityBulldozer?.Step ?? 0); public bool CheckCanMove(DirectionType direction) => _drawingBulldozer?.CanMove(direction) ?? false; - public void MoveObject(DirectionType direction) => _drawingBulldozer?.MoveBulldozer(direction); + public void MoveObject(DirectionType direction) => _drawingBulldozer?.MoveTransport(direction); } }