diff --git a/Sailboat/Sailboat/DrawingBoat.cs b/Sailboat/Sailboat/DrawingBoat.cs
index 2ad373f..147e12f 100644
--- a/Sailboat/Sailboat/DrawingBoat.cs
+++ b/Sailboat/Sailboat/DrawingBoat.cs
@@ -138,7 +138,7 @@ namespace Sailboat.DrawingObjects
g.DrawPolygon(pen, hull);
Brush addBrush = new
- SolidBrush(Color.Green);
+ SolidBrush(Color.Aqua);
g.FillEllipse(addBrush, _startPosX + 20, _startPosY + 100, 90, 40);
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 100, 90, 40);
diff --git a/Sailboat/Sailboat/DrawingSailboat.cs b/Sailboat/Sailboat/DrawingSailboat.cs
index 99e7490..6de2f1f 100644
--- a/Sailboat/Sailboat/DrawingSailboat.cs
+++ b/Sailboat/Sailboat/DrawingSailboat.cs
@@ -26,7 +26,7 @@ namespace Sailboat.DrawingObjects
{
return;
}
- Pen pen = new(Color.Black);
+ Pen pen = new(Color.Aqua);
Brush additionalBrush = new
SolidBrush(sailboat.AdditionalColor);
diff --git a/Sailboat/Sailboat/EntityBoat.cs b/Sailboat/Sailboat/EntityBoat.cs
index 7312ee4..85cdb6d 100644
--- a/Sailboat/Sailboat/EntityBoat.cs
+++ b/Sailboat/Sailboat/EntityBoat.cs
@@ -13,6 +13,14 @@ namespace Sailboat.Entities
public Color BodyColor { get; private set; }
public void setBodyColor(Color color) { BodyColor = color; }
public double Step => (double)Speed * 100 / Weight;
+ public void ChangeColor(Color color)
+ {
+ BodyColor = color;
+ }
+
+ ///
+ /// Конструктор с параметрами
+ ///
public EntityBoat(int speed, double weight, Color bodyColor)
{
Speed = speed;
diff --git a/Sailboat/Sailboat/EntitySailboat.cs b/Sailboat/Sailboat/EntitySailboat.cs
index af78d9b..e1f3f25 100644
--- a/Sailboat/Sailboat/EntitySailboat.cs
+++ b/Sailboat/Sailboat/EntitySailboat.cs
@@ -12,6 +12,14 @@ namespace Sailboat.Entities
public void setAdditionalColor(Color color) { AdditionalColor = color; }
public bool Hull { get; private set; }
public bool Sail { get; private set; }
+ public void ChangeAddColor(Color color)
+ {
+ AdditionalColor = color;
+ }
+
+ ///
+ /// Инициализация полей объекта-класса парусной лодки
+ ///
public EntitySailboat(int speed, double weight, Color bodyColor, Color
additionalColor, bool hull, bool sail) : base (speed, weight, bodyColor)
{
diff --git a/Sailboat/Sailboat/FormBoatCollection.cs b/Sailboat/Sailboat/FormBoatCollection.cs
index 72eef1d..8073762 100644
--- a/Sailboat/Sailboat/FormBoatCollection.cs
+++ b/Sailboat/Sailboat/FormBoatCollection.cs
@@ -59,10 +59,11 @@ namespace Sailboat
{
return;
}
- FormSailboat form = new();
- if (form.ShowDialog() == DialogResult.OK)
+ FormBoatConfig form = new FormBoatConfig(pictureBoxCollection.Width, pictureBoxCollection.Height);
+ form.Show();
+ Action? boatDelegate = new((plane) =>
{
- if (obj + form.SelectedBoat)
+ if (obj + plane)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowBoats();
@@ -71,7 +72,8 @@ namespace Sailboat
{
MessageBox.Show("Не удалось добавить объект");
}
- }
+ });
+ form.AddEvent(boatDelegate);
}
private void buttonRemoveBoat_Click(object sender, EventArgs e)
diff --git a/Sailboat/Sailboat/FormBoatConfig.Designer.cs b/Sailboat/Sailboat/FormBoatConfig.Designer.cs
index d572751..f20a7d4 100644
--- a/Sailboat/Sailboat/FormBoatConfig.Designer.cs
+++ b/Sailboat/Sailboat/FormBoatConfig.Designer.cs
@@ -176,7 +176,7 @@
this.labelModifiedObject.TabIndex = 8;
this.labelModifiedObject.Text = "Продвинутый";
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
+ this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LableObject_MouseDown);
//
// labelSimpleObject
//
@@ -187,7 +187,7 @@
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);
+ this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LableObject_MouseDown);
//
// checkBoxSail
//
@@ -326,7 +326,7 @@
this.buttonOk.TabIndex = 3;
this.buttonOk.Text = "Добавить";
this.buttonOk.UseVisualStyleBackColor = true;
- this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
+ this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
//
// buttonCancel
//
diff --git a/Sailboat/Sailboat/FormBoatConfig.cs b/Sailboat/Sailboat/FormBoatConfig.cs
index a79335f..db143ce 100644
--- a/Sailboat/Sailboat/FormBoatConfig.cs
+++ b/Sailboat/Sailboat/FormBoatConfig.cs
@@ -1,4 +1,6 @@
-using System;
+using Sailboat.DrawingObjects;
+using Sailboat.Entities;
+using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@@ -8,19 +10,18 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
-using Sailboat.DrawingObjects;
-using Sailboat.Generics;
-using Sailboat.MovementStrategy;
-using Sailboat.Entities;
-
namespace Sailboat
{
public partial class FormBoatConfig : Form
{
DrawingBoat? _boat = null;
- private event Action ? EventAddBoat;
- public FormBoatConfig()
+ private event Action? EventAddBoat;
+ public int _pictureWidth { get; private set; }
+ public int _pictureHeight { get; private set; }
+ public FormBoatConfig(int pictureWidth, int pictureHeight)
{
+ _pictureWidth = pictureWidth;
+ _pictureHeight = pictureHeight;
InitializeComponent();
panelBlack.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
@@ -53,18 +54,21 @@ namespace Sailboat
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)
+ private void LableObject_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;
@@ -81,34 +85,29 @@ namespace Sailboat
{
case "labelSimpleObject":
_boat = new DrawingBoat((int)numericUpDownSpeed.Value,
- (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
- pictureBoxObject.Height);
+ (int)numericUpDownWeight.Value, Color.White, _pictureWidth, _pictureHeight);
break;
case "labelModifiedObject":
_boat = new DrawingSailboat((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxHull.Checked,
- checkBoxSail.Checked, pictureBoxObject.Width,
- pictureBoxObject.Height);
+ checkBoxSail.Checked, _pictureWidth, _pictureHeight);
break;
}
DrawBoat();
}
-
private void LabelColor_DragDrop(object sender, DragEventArgs e)
{
- if (_boat == null)
+ if (_boat?.EntityBoat == null)
return;
- switch (((Label)sender).Name)
- {
- case "labelColor":
- _boat.EntityBoat.setBodyColor((Color)e.Data.GetData(typeof(Color)));
- break;
- case "labelAddColor":
- if (!(_boat is DrawingSailboat))
- return;
- (_boat.EntityBoat as EntitySailboat).setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
- break;
- }
+ Color bodyColor = (Color)e.Data.GetData(typeof(Color));
+ _boat.EntityBoat.ChangeColor(bodyColor);
+ DrawBoat();
+ }
+ private void addColorLabel_DragDrop(object sender, DragEventArgs e)
+ {
+ if ((_boat?.EntityBoat == null) || (_boat is DrawingSailboat == false))
+ return;
+ ((EntitySailboat)_boat.EntityBoat).ChangeAddColor((Color)e.Data.GetData(typeof(Color)));
DrawBoat();
}
private void LabelColor_DragEnter(object sender, DragEventArgs e)
@@ -122,8 +121,7 @@ namespace Sailboat
e.Effect = DragDropEffects.None;
}
}
-
- private void ButtonOk_Click(object sender, EventArgs e)
+ private void buttonOk_Click(object sender, EventArgs e)
{
EventAddBoat?.Invoke(_boat);
Close();