From bac06ec21fd3bff3eb4744857b85a8c096c90a31 Mon Sep 17 00:00:00 2001 From: chtzsch ~ Date: Wed, 15 Nov 2023 13:45:37 +0300 Subject: [PATCH] lab5 --- .../speed_Boat/BoatsGenericCollection.cs | 4 +- speed_Boat/speed_Boat/DrawingSpeedBoat.cs | 38 +- speed_Boat/speed_Boat/EntityBoat.cs | 5 +- speed_Boat/speed_Boat/EntitySpeedboat.cs | 6 +- speed_Boat/speed_Boat/FormBoatCollection.cs | 33 +- .../speed_Boat/FormBoatConfig.Designer.cs | 389 ++++++++++++++++++ speed_Boat/speed_Boat/FormBoatConfig.cs | 146 +++++++ speed_Boat/speed_Boat/FormBoatConfig.resx | 120 ++++++ speed_Boat/speed_Boat/SpeedBoatMovement.cs | 8 +- 9 files changed, 711 insertions(+), 38 deletions(-) create mode 100644 speed_Boat/speed_Boat/FormBoatConfig.Designer.cs create mode 100644 speed_Boat/speed_Boat/FormBoatConfig.cs create mode 100644 speed_Boat/speed_Boat/FormBoatConfig.resx diff --git a/speed_Boat/speed_Boat/BoatsGenericCollection.cs b/speed_Boat/speed_Boat/BoatsGenericCollection.cs index 3b86da7..0da3495 100644 --- a/speed_Boat/speed_Boat/BoatsGenericCollection.cs +++ b/speed_Boat/speed_Boat/BoatsGenericCollection.cs @@ -119,9 +119,11 @@ namespace speed_Boat.Generics int width_Col = _pictureWidth / _placeSizeWidth;//количество колонок в окне прорисовки foreach (var boat in _collection.GetBoats()) { + boat.screenWidth = _pictureWidth; + boat.screenHeight = _pictureHeight; if(boat != null) { - boat.SetPosition(col * _placeSizeWidth, i / width_Col * _placeSizeHeight); + boat.SetPosition(col * _placeSizeWidth, (i / width_Col) * _placeSizeHeight); col++; if (col > 2) col = 0; diff --git a/speed_Boat/speed_Boat/DrawingSpeedBoat.cs b/speed_Boat/speed_Boat/DrawingSpeedBoat.cs index 26a4120..ae95ea9 100644 --- a/speed_Boat/speed_Boat/DrawingSpeedBoat.cs +++ b/speed_Boat/speed_Boat/DrawingSpeedBoat.cs @@ -28,34 +28,36 @@ namespace SpeedBoatLab.Drawings { return; } + Point[] points; Pen pen = new(Color.Black); Brush additionalBrush = new SolidBrush(speedBoat.SecondColor); - #region Координаты защитного стекла - Point g1 = new Point(startXCoord + 70, startYCoord + 25); - Point g2 = new Point(startXCoord + 80, startYCoord + 20); - Point g3 = new Point(startXCoord + 80, startYCoord + 60); - Point g4 = new Point(startXCoord + 70, startYCoord + 55); - Point[] pointsGlass = { g1, g2, g3, g4 }; - #endregion + base.DrawTransport(g); + //Защитное стекло + if (speedBoat.isProtectedGlass) + { + points = new Point[] + { + new Point(startXCoord + 70, startYCoord + 25), + new Point(startXCoord + 80, startYCoord + 20), + new Point(startXCoord + 80, startYCoord + 60), + new Point(startXCoord + 70, startYCoord + 55) + }; + g.FillPolygon(additionalBrush, points); + g.DrawPolygon(pen, points); + } //мотор if (speedBoat.isMotor) { g.DrawRectangle(pen, startXCoord + 10, startYCoord + 30, widthBoat - 90, heightBoat - 60); g.FillRectangle(additionalBrush, startXCoord + 10, startYCoord + 30, widthBoat - 90, heightBoat - 60); - } - - //защитное стекло - if (speedBoat.isProtectedGlass) - { - g.DrawPolygon(pen, pointsGlass); - - g.FillPolygon(new SolidBrush(Color.Aqua), pointsGlass); - } - - base.DrawTransport(g); + } + } + public void SetExtraColor(Color color) + { + (_entityBoat as EntitySpeedboat).SecondColor = color; } } } diff --git a/speed_Boat/speed_Boat/EntityBoat.cs b/speed_Boat/speed_Boat/EntityBoat.cs index bf44246..2bbb4a0 100644 --- a/speed_Boat/speed_Boat/EntityBoat.cs +++ b/speed_Boat/speed_Boat/EntityBoat.cs @@ -38,6 +38,9 @@ namespace SpeedBoatLab.Entity Weight = weight; MainColor = mainColor; } - + public void setColor(Color newBaseColor) + { + MainColor = newBaseColor; + } } } diff --git a/speed_Boat/speed_Boat/EntitySpeedboat.cs b/speed_Boat/speed_Boat/EntitySpeedboat.cs index b4c5052..6a7f10b 100644 --- a/speed_Boat/speed_Boat/EntitySpeedboat.cs +++ b/speed_Boat/speed_Boat/EntitySpeedboat.cs @@ -25,7 +25,7 @@ namespace SpeedBoatLab.Entity /// /// Доп. цвет /// - public Color SecondColor { get; private set; } + public Color SecondColor { get; set; } /// /// Параметры катера @@ -37,5 +37,9 @@ namespace SpeedBoatLab.Entity isProtectedGlass = _isProtectedGlass; SecondColor = secondColor; } + public void ChangeDopColor(Color newDopColor) + { + SecondColor = newDopColor; + } } } diff --git a/speed_Boat/speed_Boat/FormBoatCollection.cs b/speed_Boat/speed_Boat/FormBoatCollection.cs index caf92ac..3bbd817 100644 --- a/speed_Boat/speed_Boat/FormBoatCollection.cs +++ b/speed_Boat/speed_Boat/FormBoatCollection.cs @@ -10,7 +10,7 @@ using System.Windows.Forms; using SpeedBoatLab.Drawings; using speed_Boat.Generics; using speed_Boat.MovementStrategy; - +using speed_Boat; namespace SpeedBoatLab { @@ -36,7 +36,7 @@ namespace SpeedBoatLab int index = storagesListBox.SelectedIndex; storagesListBox.Items.Clear(); - + for (int i = 0; i < _storage.Keys.Count; i++) { storagesListBox.Items.Add(_storage.Keys[i]); @@ -75,7 +75,7 @@ namespace SpeedBoatLab private void storageListBox_SelectedIndexChanged(object sender, EventArgs e) { pictureBoxCollection.Image = - _storage[storagesListBox.SelectedItem?.ToString() ?? string.Empty]?.ShowBoats(); + _storage[storagesListBox.SelectedItem?.ToString() ?? string.Empty]?.ShowBoats(); } /// /// Удаление набора @@ -94,12 +94,20 @@ namespace SpeedBoatLab } } + /// /// Добавление объекта в набор /// /// /// private void ButtonAddBoat_Click(object sender, EventArgs e) + { + var FormBoatConfig = new FormBoatConfig(); + FormBoatConfig.AddEvent(new(AddBoat)); + FormBoatConfig.Show(); + } + + public void AddBoat(DrawingBoat? boat) { if (storagesListBox.SelectedIndex == -1) { @@ -110,19 +118,14 @@ namespace SpeedBoatLab { return; } - - FormSpeedBoat form = new(); - if (form.ShowDialog() == DialogResult.OK) + if (obj + boat) { - if (obj + form.SelectedBoat) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowBoats(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowBoats(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } } /// diff --git a/speed_Boat/speed_Boat/FormBoatConfig.Designer.cs b/speed_Boat/speed_Boat/FormBoatConfig.Designer.cs new file mode 100644 index 0000000..1e5ab42 --- /dev/null +++ b/speed_Boat/speed_Boat/FormBoatConfig.Designer.cs @@ -0,0 +1,389 @@ +namespace speed_Boat +{ + partial class FormBoatConfig + { + /// + /// 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() + { + groupBox1 = new System.Windows.Forms.GroupBox(); + labelModifyedObject = new System.Windows.Forms.Label(); + labelSimpleObject = new System.Windows.Forms.Label(); + checkBoxIsProtectedGlass = new System.Windows.Forms.CheckBox(); + checkBoxIsMotor = new System.Windows.Forms.CheckBox(); + groupBox2 = new System.Windows.Forms.GroupBox(); + panelWhite = new System.Windows.Forms.Panel(); + panelYellow = new System.Windows.Forms.Panel(); + panelGray = new System.Windows.Forms.Panel(); + panelBlue = new System.Windows.Forms.Panel(); + panelGreen = new System.Windows.Forms.Panel(); + panelPurple = new System.Windows.Forms.Panel(); + panelRed = new System.Windows.Forms.Panel(); + panelBlack = new System.Windows.Forms.Panel(); + numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + label2 = new System.Windows.Forms.Label(); + label1 = new System.Windows.Forms.Label(); + panelobject = new System.Windows.Forms.Panel(); + LabelDopColor = new System.Windows.Forms.Label(); + LabelBaseColor = new System.Windows.Forms.Label(); + pictureBoxObject = new System.Windows.Forms.PictureBox(); + buttonCancel = new System.Windows.Forms.Button(); + buttonOk = new System.Windows.Forms.Button(); + groupBox1.SuspendLayout(); + groupBox2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + panelobject.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + SuspendLayout(); + // + // groupBox1 + // + groupBox1.Controls.Add(labelModifyedObject); + groupBox1.Controls.Add(labelSimpleObject); + groupBox1.Controls.Add(checkBoxIsProtectedGlass); + groupBox1.Controls.Add(checkBoxIsMotor); + groupBox1.Controls.Add(groupBox2); + groupBox1.Controls.Add(numericUpDownWeight); + groupBox1.Controls.Add(numericUpDownSpeed); + groupBox1.Controls.Add(label2); + groupBox1.Controls.Add(label1); + groupBox1.Location = new System.Drawing.Point(12, 12); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new System.Drawing.Size(316, 426); + groupBox1.TabIndex = 0; + groupBox1.TabStop = false; + groupBox1.Text = "Параметры"; + // + // labelModifyedObject + // + labelModifyedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + labelModifyedObject.Location = new System.Drawing.Point(156, 370); + labelModifyedObject.Name = "labelModifyedObject"; + labelModifyedObject.RightToLeft = System.Windows.Forms.RightToLeft.No; + labelModifyedObject.Size = new System.Drawing.Size(114, 30); + labelModifyedObject.TabIndex = 12; + labelModifyedObject.Text = "Продвинутый"; + labelModifyedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + labelModifyedObject.MouseDown += labelSimpleObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + labelSimpleObject.Location = new System.Drawing.Point(35, 370); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new System.Drawing.Size(114, 30); + labelSimpleObject.TabIndex = 11; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += labelSimpleObject_MouseDown; + // + // checkBoxIsProtectedGlass + // + checkBoxIsProtectedGlass.AutoSize = true; + checkBoxIsProtectedGlass.Location = new System.Drawing.Point(20, 152); + checkBoxIsProtectedGlass.Name = "checkBoxIsProtectedGlass"; + checkBoxIsProtectedGlass.Size = new System.Drawing.Size(281, 24); + checkBoxIsProtectedGlass.TabIndex = 10; + checkBoxIsProtectedGlass.Text = "Признак наличия защитного стекла"; + checkBoxIsProtectedGlass.UseVisualStyleBackColor = true; + // + // checkBoxIsMotor + // + checkBoxIsMotor.AutoSize = true; + checkBoxIsMotor.Location = new System.Drawing.Point(20, 122); + checkBoxIsMotor.Name = "checkBoxIsMotor"; + checkBoxIsMotor.Size = new System.Drawing.Size(210, 24); + checkBoxIsMotor.TabIndex = 9; + checkBoxIsMotor.Text = "Признак наличия мотора"; + checkBoxIsMotor.UseVisualStyleBackColor = true; + // + // groupBox2 + // + groupBox2.Controls.Add(panelWhite); + groupBox2.Controls.Add(panelYellow); + groupBox2.Controls.Add(panelGray); + groupBox2.Controls.Add(panelBlue); + groupBox2.Controls.Add(panelGreen); + groupBox2.Controls.Add(panelPurple); + groupBox2.Controls.Add(panelRed); + groupBox2.Controls.Add(panelBlack); + groupBox2.Location = new System.Drawing.Point(20, 183); + groupBox2.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + groupBox2.Name = "groupBox2"; + groupBox2.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); + groupBox2.Size = new System.Drawing.Size(261, 173); + groupBox2.TabIndex = 8; + groupBox2.TabStop = false; + groupBox2.Text = "Цвета"; + // + // panelWhite + // + panelWhite.AllowDrop = true; + panelWhite.BackColor = System.Drawing.Color.White; + panelWhite.Location = new System.Drawing.Point(191, 104); + panelWhite.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new System.Drawing.Size(50, 50); + panelWhite.TabIndex = 3; + panelWhite.MouseDown += PanelColor_MouseDown; + // + // panelYellow + // + panelYellow.AllowDrop = true; + panelYellow.BackColor = System.Drawing.Color.Yellow; + panelYellow.Location = new System.Drawing.Point(191, 37); + panelYellow.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new System.Drawing.Size(50, 50); + panelYellow.TabIndex = 1; + panelYellow.MouseDown += PanelColor_MouseDown; + // + // panelGray + // + panelGray.AllowDrop = true; + panelGray.BackColor = System.Drawing.Color.Gray; + panelGray.Location = new System.Drawing.Point(135, 104); + panelGray.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + panelGray.Name = "panelGray"; + panelGray.Size = new System.Drawing.Size(50, 50); + panelGray.TabIndex = 4; + panelGray.MouseDown += PanelColor_MouseDown; + // + // panelBlue + // + panelBlue.AllowDrop = true; + panelBlue.BackColor = System.Drawing.Color.Blue; + panelBlue.Location = new System.Drawing.Point(79, 104); + panelBlue.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new System.Drawing.Size(50, 50); + panelBlue.TabIndex = 5; + panelBlue.MouseDown += PanelColor_MouseDown; + // + // panelGreen + // + panelGreen.AllowDrop = true; + panelGreen.BackColor = System.Drawing.Color.Green; + panelGreen.Location = new System.Drawing.Point(135, 37); + panelGreen.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new System.Drawing.Size(50, 50); + panelGreen.TabIndex = 1; + panelGreen.MouseDown += PanelColor_MouseDown; + // + // panelPurple + // + panelPurple.AllowDrop = true; + panelPurple.BackColor = System.Drawing.Color.Purple; + panelPurple.Location = new System.Drawing.Point(23, 104); + panelPurple.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new System.Drawing.Size(50, 50); + panelPurple.TabIndex = 2; + panelPurple.MouseDown += PanelColor_MouseDown; + // + // panelRed + // + panelRed.AllowDrop = true; + panelRed.BackColor = System.Drawing.Color.Red; + panelRed.Location = new System.Drawing.Point(79, 37); + panelRed.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + panelRed.Name = "panelRed"; + panelRed.Size = new System.Drawing.Size(50, 50); + panelRed.TabIndex = 1; + panelRed.MouseDown += PanelColor_MouseDown; + // + // panelBlack + // + panelBlack.AllowDrop = true; + panelBlack.BackColor = System.Drawing.Color.Black; + panelBlack.Location = new System.Drawing.Point(23, 37); + panelBlack.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new System.Drawing.Size(50, 50); + panelBlack.TabIndex = 0; + panelBlack.MouseDown += PanelColor_MouseDown; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new System.Drawing.Point(98, 77); + numericUpDownWeight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + numericUpDownWeight.Name = "numericUpDownWeight"; + numericUpDownWeight.Size = new System.Drawing.Size(137, 27); + numericUpDownWeight.TabIndex = 7; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new System.Drawing.Point(98, 38); + numericUpDownSpeed.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + numericUpDownSpeed.Name = "numericUpDownSpeed"; + numericUpDownSpeed.Size = new System.Drawing.Size(137, 27); + numericUpDownSpeed.TabIndex = 6; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // label2 + // + label2.AutoSize = true; + label2.Location = new System.Drawing.Point(20, 79); + label2.Name = "label2"; + label2.Size = new System.Drawing.Size(36, 20); + label2.TabIndex = 5; + label2.Text = "Вес:"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new System.Drawing.Point(20, 41); + label1.Name = "label1"; + label1.Size = new System.Drawing.Size(76, 20); + label1.TabIndex = 4; + label1.Text = "Скорость:"; + // + // panelobject + // + panelobject.AllowDrop = true; + panelobject.Controls.Add(LabelDopColor); + panelobject.Controls.Add(LabelBaseColor); + panelobject.Controls.Add(pictureBoxObject); + panelobject.Location = new System.Drawing.Point(334, 22); + panelobject.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + panelobject.Name = "panelobject"; + panelobject.Size = new System.Drawing.Size(272, 346); + panelobject.TabIndex = 11; + panelobject.DragDrop += panelobject_DragDrop; + panelobject.DragEnter += panelobject_DragEnter; + // + // LabelDopColor + // + LabelDopColor.AllowDrop = true; + LabelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + LabelDopColor.Location = new System.Drawing.Point(142, 21); + LabelDopColor.Name = "LabelDopColor"; + LabelDopColor.Size = new System.Drawing.Size(114, 30); + LabelDopColor.TabIndex = 3; + LabelDopColor.Text = "Доп.цвет"; + LabelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + LabelDopColor.DragDrop += LabelDopColor_DragDrop; + LabelDopColor.DragEnter += LabelDopColor_DragEnter; + // + // LabelBaseColor + // + LabelBaseColor.AllowDrop = true; + LabelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + LabelBaseColor.Location = new System.Drawing.Point(14, 21); + LabelBaseColor.Name = "LabelBaseColor"; + LabelBaseColor.Size = new System.Drawing.Size(114, 30); + LabelBaseColor.TabIndex = 2; + LabelBaseColor.Text = "Цвет"; + LabelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + LabelBaseColor.DragDrop += LabelBaseColor_DragDrop; + LabelBaseColor.DragEnter += LabelBaseColor_DragEnter; + // + // pictureBoxObject + // + pictureBoxObject.Location = new System.Drawing.Point(14, 69); + pictureBoxObject.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new System.Drawing.Size(242, 258); + pictureBoxObject.TabIndex = 1; + pictureBoxObject.TabStop = false; + // + // buttonCancel + // + buttonCancel.Location = new System.Drawing.Point(504, 381); + buttonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new System.Drawing.Size(86, 31); + buttonCancel.TabIndex = 14; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // buttonOk + // + buttonOk.Location = new System.Drawing.Point(348, 381); + buttonOk.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + buttonOk.Name = "buttonOk"; + buttonOk.Size = new System.Drawing.Size(86, 31); + buttonOk.TabIndex = 13; + buttonOk.Text = "Добавить"; + buttonOk.UseVisualStyleBackColor = true; + buttonOk.Click += buttonOk_Click; + // + // FormBoatConfig + // + AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + ClientSize = new System.Drawing.Size(634, 450); + Controls.Add(buttonCancel); + Controls.Add(buttonOk); + Controls.Add(panelobject); + Controls.Add(groupBox1); + Name = "FormBoatConfig"; + Text = "Создание объекта"; + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + groupBox2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + panelobject.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + ResumeLayout(false); + } + + #endregion + + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.NumericUpDown numericUpDownWeight; + private System.Windows.Forms.NumericUpDown numericUpDownSpeed; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label labelModifyedObject; + private System.Windows.Forms.Label labelSimpleObject; + private System.Windows.Forms.CheckBox checkBoxIsProtectedGlass; + private System.Windows.Forms.CheckBox checkBoxIsMotor; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.Panel panelWhite; + private System.Windows.Forms.Panel panelYellow; + private System.Windows.Forms.Panel panelGray; + private System.Windows.Forms.Panel panelBlue; + private System.Windows.Forms.Panel panelGreen; + private System.Windows.Forms.Panel panelPurple; + private System.Windows.Forms.Panel panelRed; + private System.Windows.Forms.Panel panelBlack; + private System.Windows.Forms.Panel panelobject; + private System.Windows.Forms.Label LabelDopColor; + private System.Windows.Forms.Label LabelBaseColor; + private System.Windows.Forms.PictureBox pictureBoxObject; + private System.Windows.Forms.Button buttonCancel; + private System.Windows.Forms.Button buttonOk; + } +} \ No newline at end of file diff --git a/speed_Boat/speed_Boat/FormBoatConfig.cs b/speed_Boat/speed_Boat/FormBoatConfig.cs new file mode 100644 index 0000000..ac45abd --- /dev/null +++ b/speed_Boat/speed_Boat/FormBoatConfig.cs @@ -0,0 +1,146 @@ +using SpeedBoatLab.Drawings; +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; + +namespace speed_Boat +{ + public partial class FormBoatConfig : Form + { + private event Action EventAddBoat; + DrawingBoat _boat = null; + public FormBoatConfig() + { + 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, a) => Close(); + } + + public void AddEvent(Action ev) + { + if (EventAddBoat == null) + { + EventAddBoat = new Action(ev); + } + else + { + EventAddBoat += ev; + } + } + + private void DrawBoat() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _boat?.SetPosition(5, 5); + _boat?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + private void labelSimpleObject_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)) + { + 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": + _boat = new DrawingBoat((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + case "labelModifyedObject": + _boat = new DrawingSpeedBoat((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxIsMotor.Checked, + checkBoxIsProtectedGlass.Checked, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + + } + DrawBoat(); + } + + private void buttonOk_Click(object sender, EventArgs e) + { + EventAddBoat?.Invoke(_boat); + Close(); + } + + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + + private void LabelBaseColor_DragDrop(object sender, DragEventArgs e) + { + if (_boat != null) + { + _boat.SetBodyColor((Color)e.Data.GetData(typeof(Color))); + DrawBoat(); + } + else return; + } + + private void LabelDopColor_DragDrop(object sender, DragEventArgs e) + { + if (_boat is not DrawingSpeedBoat MotorBoat || _boat == null) + { + return; + } + MotorBoat.SetExtraColor((Color)e.Data.GetData(typeof(Color))); + DrawBoat(); + } + + private void LabelBaseColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void LabelDopColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + } +} diff --git a/speed_Boat/speed_Boat/FormBoatConfig.resx b/speed_Boat/speed_Boat/FormBoatConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/speed_Boat/speed_Boat/FormBoatConfig.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/speed_Boat/speed_Boat/SpeedBoatMovement.cs b/speed_Boat/speed_Boat/SpeedBoatMovement.cs index 7059236..de71bf0 100644 --- a/speed_Boat/speed_Boat/SpeedBoatMovement.cs +++ b/speed_Boat/speed_Boat/SpeedBoatMovement.cs @@ -21,11 +21,11 @@ namespace SpeedBoatLab.Drawings /// /// Ширина окна /// - private int screenWidth; + public int screenWidth; /// /// Высота окна /// - private int screenHeight; + public int screenHeight; /// /// Х-координата обьекта @@ -238,5 +238,9 @@ namespace SpeedBoatLab.Drawings g.FillEllipse(mainBrush, startXCoord + 25, startYCoord + 25, widthBoat - 50, heightBoat - 50); g.FillPolygon(mainBrush, pointsBoat); } + public void SetBodyColor(Color color) + { + (_entityBoat as EntityBoat).setColor(color); + } } }