diff --git a/WarmlyShip/WarmlyShip/DrawningShip.cs b/WarmlyShip/WarmlyShip/DrawningShip.cs
index 4958d26..aa4c10a 100644
--- a/WarmlyShip/WarmlyShip/DrawningShip.cs
+++ b/WarmlyShip/WarmlyShip/DrawningShip.cs
@@ -181,11 +181,25 @@
_startPosY = _pictureHeight.Value - _shipHeight;
}
}
- ///
- /// Получение текущей позиции объекта
- ///
- ///
- public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
+
+ public void SetBaseColor(Color color)
+ {
+ if (Ship is EntityWarmlyShip)
+ {
+ Ship = (EntityWarmlyShip)Ship;
+ if (Ship is not null)
+ {
+ Ship = new EntityWarmlyShip(Ship.Speed, Ship.Weight, color, (Ship as EntityWarmlyShip).DopColor, (Ship as EntityWarmlyShip).Pipes, (Ship as EntityWarmlyShip).FuelCompartment);
+ return;
+ }
+ }
+ Ship = new EntityShip(Ship.Speed, Ship.Weight, color);
+ }
+ ///
+ /// Получение текущей позиции объекта
+ ///
+ ///
+ public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosY, _startPosX + _shipWidth, _startPosY + _shipHeight);
}
diff --git a/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs
index 19fa9a2..9154fd6 100644
--- a/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs
+++ b/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs
@@ -53,5 +53,13 @@ namespace WarmlyShip
g.DrawRectangle(pen, _startPosX + 135, _startPosY + 70, 10, 5);
}
}
+ public void SetDopColor(Color color)
+ {
+ Ship = Ship as EntityWarmlyShip;
+ if (Ship is not null)
+ {
+ Ship = new EntityWarmlyShip(Ship.Speed, Ship.Weight, Ship.BodyColor, color, (Ship as EntityWarmlyShip).Pipes, (Ship as EntityWarmlyShip).FuelCompartment);
+ }
+ }
}
}
diff --git a/WarmlyShip/WarmlyShip/FormShipConfig.Designer.cs b/WarmlyShip/WarmlyShip/FormShipConfig.Designer.cs
index 580513b..91e35e3 100644
--- a/WarmlyShip/WarmlyShip/FormShipConfig.Designer.cs
+++ b/WarmlyShip/WarmlyShip/FormShipConfig.Designer.cs
@@ -275,7 +275,7 @@
this.labelDopColor.Text = "Доп. цвет";
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop);
- this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragEnter);
+ this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
//
// labelBaseColor
//
@@ -288,7 +288,7 @@
this.labelBaseColor.Text = "Цвет";
this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
- this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter);
+ this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
//
// pictureBoxObject
//
diff --git a/WarmlyShip/WarmlyShip/FormShipConfig.cs b/WarmlyShip/WarmlyShip/FormShipConfig.cs
index db9bb11..bba7b93 100644
--- a/WarmlyShip/WarmlyShip/FormShipConfig.cs
+++ b/WarmlyShip/WarmlyShip/FormShipConfig.cs
@@ -12,7 +12,7 @@ namespace WarmlyShip
{
public partial class FormShipConfig : Form
{
- private event ShipDelegate EventAddShip;
+ private event Action EventAddShip;
DrawningShip _ship = null;
public FormShipConfig()
@@ -26,7 +26,7 @@ namespace WarmlyShip
panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
- buttonCancel.Click += (s, e) => Close();
+ buttonCancel.Click += (sender, e) => Close();
}
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
@@ -41,11 +41,11 @@ namespace WarmlyShip
_ship?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
- public void AddEvent(ShipDelegate ev)
+ public void AddEvent(Action ev)
{
if (EventAddShip == null)
{
- EventAddShip = new ShipDelegate(ev);
+ EventAddShip = new(ev);
}
else
{
@@ -91,36 +91,11 @@ namespace WarmlyShip
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
- switch (e.Data.GetData(DataFormats.Text).ToString())
- {
- case "panelRed":
- labelBaseColor.BackColor = Color.Red;
- break;
- case "panelBlack":
- labelBaseColor.BackColor = Color.Black;
- break;
- case "panelGreen":
- labelBaseColor.BackColor = Color.Green;
- break;
- case "panelYellow":
- labelBaseColor.BackColor = Color.Yellow;
- break;
- case "panelBlue":
- labelBaseColor.BackColor = Color.Blue;
- break;
- case "panelPurple":
- labelBaseColor.BackColor = Color.Purple;
- break;
- case "panelGray":
- labelBaseColor.BackColor = Color.DarkGray;
- break;
- case "panelWhite":
- labelBaseColor.BackColor = Color.White;
- break;
- }
+ _ship.SetBaseColor((Color)e.Data.GetData(typeof(Color)));
+ DrawShip();
}
- private void LabelBaseColor_DragEnter(object sender, DragEventArgs e)
+ private void LabelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
@@ -134,45 +109,12 @@ namespace WarmlyShip
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
- switch (e.Data.GetData(DataFormats.Text).ToString())
+ if (_ship is DrawningWarmlyShip)
{
- case "panelRed":
- labelBaseColor.BackColor = Color.Red;
- break;
- case "panelBlack":
- labelBaseColor.BackColor = Color.Black;
- break;
- case "panelGreen":
- labelBaseColor.BackColor = Color.Green;
- break;
- case "panelYellow":
- labelBaseColor.BackColor = Color.Yellow;
- break;
- case "panelBlue":
- labelBaseColor.BackColor = Color.Blue;
- break;
- case "panelPurple":
- labelBaseColor.BackColor = Color.Purple;
- break;
- case "panelGray":
- labelBaseColor.BackColor = Color.DarkGray;
- break;
- case "panelWhite":
- labelBaseColor.BackColor = Color.White;
- break;
- }
- }
-
- private void LabelDopColor_DragEnter(object sender, DragEventArgs e)
- {
- if (e.Data.GetDataPresent(typeof(Color)))
- {
- e.Effect = DragDropEffects.Copy;
- }
- else
- {
- e.Effect = DragDropEffects.None;
+ var ship = _ship as DrawningWarmlyShip;
+ ship.SetDopColor((Color)e.Data.GetData(typeof(Color)));
}
+ DrawShip();
}
}
}
diff --git a/WarmlyShip/WarmlyShip/ShipDelegate.cs b/WarmlyShip/WarmlyShip/ShipDelegate.cs
deleted file mode 100644
index b6d3e65..0000000
--- a/WarmlyShip/WarmlyShip/ShipDelegate.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace WarmlyShip
-{
- ///
- /// Делегат для передачи объекта-коробля
- ///
- ///
- public delegate void ShipDelegate(DrawningShip car);
-}