diff --git a/Sailboat/Sailboat/BoatDelegate.cs b/Sailboat/Sailboat/BoatDelegate.cs
new file mode 100644
index 0000000..377892f
--- /dev/null
+++ b/Sailboat/Sailboat/BoatDelegate.cs
@@ -0,0 +1,11 @@
+using Sailboat.DrawingObjects;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Sailboat
+{
+ internal delegate void BoatDelegate(DrawingBoat boat);
+}
diff --git a/Sailboat/Sailboat/FormBoatConfig.Designer.cs b/Sailboat/Sailboat/FormBoatConfig.Designer.cs
index 895b8b5..a1bac2b 100644
--- a/Sailboat/Sailboat/FormBoatConfig.Designer.cs
+++ b/Sailboat/Sailboat/FormBoatConfig.Designer.cs
@@ -28,19 +28,343 @@
///
private void InitializeComponent()
{
+ this.groupBoxColors = new System.Windows.Forms.GroupBox();
+ this.panelPurple = new System.Windows.Forms.Panel();
+ this.panelYellow = new System.Windows.Forms.Panel();
+ this.panelBlack = new System.Windows.Forms.Panel();
+ this.panelBlue = new System.Windows.Forms.Panel();
+ this.panelGray = new System.Windows.Forms.Panel();
+ this.panelWhite = new System.Windows.Forms.Panel();
+ this.panelGreen = new System.Windows.Forms.Panel();
+ this.panelRed = new System.Windows.Forms.Panel();
+ this.groupBoxParameters = new System.Windows.Forms.GroupBox();
+ this.labelSpeed = new System.Windows.Forms.Label();
+ this.labelWeight = new System.Windows.Forms.Label();
+ this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
+ this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
+ this.checkBoxHull = new System.Windows.Forms.CheckBox();
+ this.checkBoxSail = new System.Windows.Forms.CheckBox();
+ this.labelSimpleObject = new System.Windows.Forms.Label();
+ this.labelModifiedObject = new System.Windows.Forms.Label();
+ this.panel1 = new System.Windows.Forms.Panel();
+ this.labelAddColor = new System.Windows.Forms.Label();
+ this.labelColor = new System.Windows.Forms.Label();
+ this.pictureBoxObject = new System.Windows.Forms.PictureBox();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.groupBoxColors.SuspendLayout();
+ this.groupBoxParameters.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
+ this.panel1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.SuspendLayout();
//
+ // groupBoxColors
+ //
+ this.groupBoxColors.Controls.Add(this.panelPurple);
+ this.groupBoxColors.Controls.Add(this.panelYellow);
+ this.groupBoxColors.Controls.Add(this.panelBlack);
+ this.groupBoxColors.Controls.Add(this.panelBlue);
+ this.groupBoxColors.Controls.Add(this.panelGray);
+ this.groupBoxColors.Controls.Add(this.panelWhite);
+ this.groupBoxColors.Controls.Add(this.panelGreen);
+ this.groupBoxColors.Controls.Add(this.panelRed);
+ this.groupBoxColors.Location = new System.Drawing.Point(345, 26);
+ this.groupBoxColors.Name = "groupBoxColors";
+ this.groupBoxColors.Size = new System.Drawing.Size(284, 179);
+ this.groupBoxColors.TabIndex = 0;
+ this.groupBoxColors.TabStop = false;
+ this.groupBoxColors.Text = "Цвета";
+ //
+ // panelPurple
+ //
+ this.panelPurple.BackColor = System.Drawing.Color.Purple;
+ this.panelPurple.Location = new System.Drawing.Point(217, 101);
+ this.panelPurple.Name = "panelPurple";
+ this.panelPurple.Size = new System.Drawing.Size(50, 50);
+ this.panelPurple.TabIndex = 7;
+ //
+ // panelYellow
+ //
+ this.panelYellow.BackColor = System.Drawing.Color.Yellow;
+ this.panelYellow.Location = new System.Drawing.Point(217, 35);
+ this.panelYellow.Name = "panelYellow";
+ this.panelYellow.Size = new System.Drawing.Size(50, 50);
+ this.panelYellow.TabIndex = 3;
+ //
+ // panelBlack
+ //
+ this.panelBlack.BackColor = System.Drawing.Color.Black;
+ this.panelBlack.Location = new System.Drawing.Point(150, 101);
+ this.panelBlack.Name = "panelBlack";
+ this.panelBlack.Size = new System.Drawing.Size(50, 50);
+ this.panelBlack.TabIndex = 6;
+ //
+ // panelBlue
+ //
+ this.panelBlue.BackColor = System.Drawing.Color.Blue;
+ this.panelBlue.Location = new System.Drawing.Point(150, 35);
+ this.panelBlue.Name = "panelBlue";
+ this.panelBlue.Size = new System.Drawing.Size(50, 50);
+ this.panelBlue.TabIndex = 2;
+ //
+ // panelGray
+ //
+ this.panelGray.BackColor = System.Drawing.Color.Gray;
+ this.panelGray.Location = new System.Drawing.Point(83, 101);
+ this.panelGray.Name = "panelGray";
+ this.panelGray.Size = new System.Drawing.Size(50, 50);
+ this.panelGray.TabIndex = 5;
+ //
+ // panelWhite
+ //
+ this.panelWhite.BackColor = System.Drawing.Color.White;
+ this.panelWhite.Location = new System.Drawing.Point(16, 101);
+ this.panelWhite.Name = "panelWhite";
+ this.panelWhite.Size = new System.Drawing.Size(50, 50);
+ this.panelWhite.TabIndex = 4;
+ //
+ // panelGreen
+ //
+ this.panelGreen.BackColor = System.Drawing.Color.Green;
+ this.panelGreen.Location = new System.Drawing.Point(83, 35);
+ this.panelGreen.Name = "panelGreen";
+ this.panelGreen.Size = new System.Drawing.Size(50, 50);
+ this.panelGreen.TabIndex = 1;
+ //
+ // panelRed
+ //
+ this.panelRed.BackColor = System.Drawing.Color.Red;
+ this.panelRed.Location = new System.Drawing.Point(16, 35);
+ this.panelRed.Name = "panelRed";
+ this.panelRed.Size = new System.Drawing.Size(50, 50);
+ this.panelRed.TabIndex = 0;
+ //
+ // groupBoxParameters
+ //
+ this.groupBoxParameters.Controls.Add(this.labelModifiedObject);
+ this.groupBoxParameters.Controls.Add(this.labelSimpleObject);
+ this.groupBoxParameters.Controls.Add(this.checkBoxSail);
+ this.groupBoxParameters.Controls.Add(this.checkBoxHull);
+ 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.Controls.Add(this.groupBoxColors);
+ this.groupBoxParameters.Location = new System.Drawing.Point(12, 12);
+ this.groupBoxParameters.Name = "groupBoxParameters";
+ this.groupBoxParameters.Size = new System.Drawing.Size(640, 285);
+ this.groupBoxParameters.TabIndex = 1;
+ this.groupBoxParameters.TabStop = false;
+ this.groupBoxParameters.Text = "Параметры";
+ //
+ // labelSpeed
+ //
+ this.labelSpeed.AutoSize = true;
+ this.labelSpeed.Location = new System.Drawing.Point(25, 36);
+ this.labelSpeed.Name = "labelSpeed";
+ this.labelSpeed.Size = new System.Drawing.Size(76, 20);
+ this.labelSpeed.TabIndex = 1;
+ this.labelSpeed.Text = "Скорость:";
+ //
+ // labelWeight
+ //
+ this.labelWeight.AutoSize = true;
+ this.labelWeight.Location = new System.Drawing.Point(25, 79);
+ this.labelWeight.Name = "labelWeight";
+ this.labelWeight.Size = new System.Drawing.Size(36, 20);
+ this.labelWeight.TabIndex = 2;
+ this.labelWeight.Text = "Вес:";
+ //
+ // numericUpDownSpeed
+ //
+ this.numericUpDownSpeed.Location = new System.Drawing.Point(118, 34);
+ 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(141, 27);
+ this.numericUpDownSpeed.TabIndex = 3;
+ this.numericUpDownSpeed.Value = new decimal(new int[] {
+ 100,
+ 0,
+ 0,
+ 0});
+ //
+ // numericUpDownWeight
+ //
+ this.numericUpDownWeight.Location = new System.Drawing.Point(118, 77);
+ 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(141, 27);
+ this.numericUpDownWeight.TabIndex = 4;
+ this.numericUpDownWeight.Value = new decimal(new int[] {
+ 100,
+ 0,
+ 0,
+ 0});
+ //
+ // checkBoxHull
+ //
+ this.checkBoxHull.AutoSize = true;
+ this.checkBoxHull.Location = new System.Drawing.Point(6, 127);
+ this.checkBoxHull.Name = "checkBoxHull";
+ this.checkBoxHull.Size = new System.Drawing.Size(237, 24);
+ this.checkBoxHull.TabIndex = 5;
+ this.checkBoxHull.Text = "Наличие усиленного корпуса";
+ this.checkBoxHull.UseVisualStyleBackColor = true;
+ //
+ // checkBoxSail
+ //
+ this.checkBoxSail.AutoSize = true;
+ this.checkBoxSail.Location = new System.Drawing.Point(6, 168);
+ this.checkBoxSail.Name = "checkBoxSail";
+ this.checkBoxSail.Size = new System.Drawing.Size(169, 24);
+ this.checkBoxSail.TabIndex = 6;
+ this.checkBoxSail.Text = "Наличие парусника";
+ this.checkBoxSail.UseVisualStyleBackColor = true;
+ //
+ // labelSimpleObject
+ //
+ this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.labelSimpleObject.Location = new System.Drawing.Point(345, 225);
+ this.labelSimpleObject.Name = "labelSimpleObject";
+ this.labelSimpleObject.Size = new System.Drawing.Size(140, 40);
+ this.labelSimpleObject.TabIndex = 7;
+ this.labelSimpleObject.Text = "Простой";
+ this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
+ //
+ // labelModifiedObject
+ //
+ this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.labelModifiedObject.Location = new System.Drawing.Point(489, 225);
+ this.labelModifiedObject.Name = "labelModifiedObject";
+ this.labelModifiedObject.Size = new System.Drawing.Size(140, 40);
+ this.labelModifiedObject.TabIndex = 8;
+ this.labelModifiedObject.Text = "Продвинутый";
+ this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ //
+ // panel1
+ //
+ this.panel1.Controls.Add(this.pictureBoxObject);
+ this.panel1.Controls.Add(this.labelAddColor);
+ this.panel1.Controls.Add(this.labelColor);
+ this.panel1.Location = new System.Drawing.Point(658, 12);
+ this.panel1.Name = "panel1";
+ this.panel1.Size = new System.Drawing.Size(362, 330);
+ this.panel1.TabIndex = 2;
+ //
+ // labelAddColor
+ //
+ this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.labelAddColor.Location = new System.Drawing.Point(182, 16);
+ this.labelAddColor.Name = "labelAddColor";
+ this.labelAddColor.Size = new System.Drawing.Size(140, 40);
+ this.labelAddColor.TabIndex = 10;
+ this.labelAddColor.Text = "Доп. цвет";
+ this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ //
+ // labelColor
+ //
+ this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.labelColor.Location = new System.Drawing.Point(38, 16);
+ this.labelColor.Name = "labelColor";
+ this.labelColor.Size = new System.Drawing.Size(140, 40);
+ this.labelColor.TabIndex = 9;
+ this.labelColor.Text = "Цвет";
+ this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ //
+ // pictureBoxObject
+ //
+ this.pictureBoxObject.Location = new System.Drawing.Point(3, 61);
+ this.pictureBoxObject.Name = "pictureBoxObject";
+ this.pictureBoxObject.Size = new System.Drawing.Size(356, 266);
+ this.pictureBoxObject.TabIndex = 11;
+ this.pictureBoxObject.TabStop = false;
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(694, 348);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(140, 40);
+ this.buttonAdd.TabIndex = 3;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(840, 348);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(140, 40);
+ this.buttonCancel.TabIndex = 4;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ //
// FormBoatConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
+ this.ClientSize = new System.Drawing.Size(1032, 394);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonAdd);
+ this.Controls.Add(this.panel1);
+ this.Controls.Add(this.groupBoxParameters);
this.Name = "FormBoatConfig";
this.Text = "Создание объекта";
+ this.groupBoxColors.ResumeLayout(false);
+ this.groupBoxParameters.ResumeLayout(false);
+ this.groupBoxParameters.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
+ this.panel1.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.ResumeLayout(false);
}
#endregion
+
+ private GroupBox groupBoxColors;
+ private Panel panelYellow;
+ private Panel panelBlue;
+ private Panel panelGreen;
+ private Panel panelRed;
+ private Panel panelPurple;
+ private Panel panelBlack;
+ private Panel panelGray;
+ private Panel panelWhite;
+ private GroupBox groupBoxParameters;
+ private Label labelModifiedObject;
+ private Label labelSimpleObject;
+ private CheckBox checkBoxSail;
+ private CheckBox checkBoxHull;
+ private NumericUpDown numericUpDownWeight;
+ private NumericUpDown numericUpDownSpeed;
+ private Label labelWeight;
+ private Label labelSpeed;
+ private Panel panel1;
+ private PictureBox pictureBoxObject;
+ private Label labelAddColor;
+ private Label labelColor;
+ private Button buttonAdd;
+ private Button buttonCancel;
}
}
\ No newline at end of file
diff --git a/Sailboat/Sailboat/FormBoatConfig.cs b/Sailboat/Sailboat/FormBoatConfig.cs
index 99708c6..ab8a453 100644
--- a/Sailboat/Sailboat/FormBoatConfig.cs
+++ b/Sailboat/Sailboat/FormBoatConfig.cs
@@ -8,13 +8,107 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using Sailboat.DrawingObjects;
+using Sailboat.Generics;
+using Sailboat.MovementStrategy;
+
namespace Sailboat
{
public partial class FormBoatConfig : Form
{
+ ///
+ /// Переменная-выбранная машина
+ ///
+ DrawingBoat? _boat = null;
+ ///
+ /// Событие
+ ///
+ private event BoatDelegate? EventAddBoat;
+ ///
+ /// Конструктор
+ ///
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;
+ // TODO buttonCancel.Click with lambda
+ }
+
+ private void DrawCar()
+ {
+ Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _boat?.SetPosition(5, 5);
+ _boat?.DrawTransport(gr);
+ pictureBoxObject.Image = bmp;
+ }
+ public void AddEvent(BoatDelegate ev)
+ {
+ if (EventAddBoat == null)
+ {
+ EventAddBoat = ev;
+ }
+ else
+ {
+ EventAddBoat += ev;
+ }
+ }
+ private void PanelColor_MouseDown(object sender, MouseEventArgs e)
+ {
+ (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
+ }
+
+ 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":
+ _boat = new DrawingBoat((int)numericUpDownSpeed.Value,
+ (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
+ pictureBoxObject.Height);
+ break;
+ case "labelModifiedObject":
+ _boat = new DrawingSailboat((int)numericUpDownSpeed.Value,
+ (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxHull.Checked,
+ checkBoxSail.Checked, pictureBoxObject.Width,
+ pictureBoxObject.Height);
+ break;
+ }
+ DrawCar();
+ }
+ private void ButtonOk_Click(object sender, EventArgs e)
+ {
+ EventAddBoat?.Invoke(_boat);
+ Close();
}
}
}