diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingPlain.cs b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingPlain.cs index f4601a2..f887fe3 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingPlain.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingPlain.cs @@ -20,16 +20,20 @@ namespace AirPlaneWithRadar { Plain = new EntetyPlain(speed, weight, bodycolor); } - protected DrawingPlain(int speed, float weight,Color bodyColor,int plainWidth,int plainHeight): - this(speed,weight, bodyColor) + protected DrawingPlain(int speed, float weight, Color bodyColor, int plainWidth, int plainHeight) : + this(speed, weight, bodyColor) { this.plainWidth = plainWidth; this.plainHeight = plainHeight; } - - public void setPosition(int x,int y,int width,int height) + public void ReColor(Color col) { - if (x + plainWidth > width || y + plainHeight > height || plainHeight > height || plainWidth > width || x <0 || y<0) + Plain.BodyColor = col; + } + + public void setPosition(int x, int y, int width, int height) + { + if (x + plainWidth > width || y + plainHeight > height || plainHeight > height || plainWidth > width || x < 0 || y < 0) return; else { @@ -39,11 +43,11 @@ namespace AirPlaneWithRadar pictureHeight = height; } } - public void MoveTransport (Direction direction) + public void MoveTransport(Direction direction) { - if(!pictureWidth.HasValue || !pictureHeight.HasValue) - { return; } - switch (direction) + if (!pictureWidth.HasValue || !pictureHeight.HasValue) + { return; } + switch (direction) { case Direction.Right: if (startPosX + plainWidth + Plain.Step < pictureWidth) @@ -51,7 +55,7 @@ namespace AirPlaneWithRadar break; case Direction.Left: - if (startPosX -Plain.Step > 0) + if (startPosX - Plain.Step > 0) startPosX -= Plain.Step; break; case Direction.Down: @@ -59,47 +63,47 @@ namespace AirPlaneWithRadar startPosY += Plain.Step; break; case Direction.Up: - if (startPosY - Plain.Step >0) + if (startPosY - Plain.Step > 0) startPosY -= Plain.Step; break; } } - public virtual void DrawTransoprt (Graphics g) + public virtual void DrawTransoprt(Graphics g) { - if(startPosX < 0 || startPosY < 0 || !pictureHeight.HasValue || !pictureWidth.HasValue) + if (startPosX < 0 || startPosY < 0 || !pictureHeight.HasValue || !pictureWidth.HasValue) { return; } Pen pen = new Pen(Color.Black); - + g.DrawRectangle(pen, startPosX, startPosY, 20, 30); g.DrawRectangle(pen, startPosX, startPosY + 30, 100, 30); - g.DrawRectangle(pen, startPosX+100, startPosY + 40, 20, 15); + g.DrawRectangle(pen, startPosX + 100, startPosY + 40, 20, 15); //koleso1 g.DrawRectangle(pen, startPosX + 30, startPosY + 60, 5, 10); - g.DrawEllipse(pen, startPosX+28, startPosY+70, 9, 9); + g.DrawEllipse(pen, startPosX + 28, startPosY + 70, 9, 9); //koleso2 g.DrawRectangle(pen, startPosX + 80, startPosY + 60, 5, 10); g.DrawEllipse(pen, startPosX + 78, startPosY + 70, 9, 9); - + //Korpys Brush br = new SolidBrush(Plain?.BodyColor ?? Color.Black); - g.FillRectangle(br, startPosX+3, startPosY + 33, 94, 24); - g.FillRectangle(br, startPosX+1, startPosY+1, 19, 29); - + g.FillRectangle(br, startPosX + 3, startPosY + 33, 94, 24); + g.FillRectangle(br, startPosX + 1, startPosY + 1, 19, 29); + //krilya Brush brWings = new SolidBrush(Color.Black); g.FillRectangle(brWings, startPosX + 30, startPosY + 40, 40, 8); - - + + //cabina Brush brCabine = new SolidBrush(Color.Blue); g.FillRectangle(brCabine, startPosX + 101, startPosY + 41, 19, 14); - + @@ -109,7 +113,7 @@ namespace AirPlaneWithRadar { pictureWidth = width; pictureHeight = height; - if(pictureWidth < plainWidth || pictureHeight < plainHeight) + if (pictureWidth < plainWidth || pictureHeight < plainHeight) { pictureWidth = null; pictureHeight = null; @@ -118,7 +122,7 @@ namespace AirPlaneWithRadar if (startPosX + plainWidth > pictureWidth) startPosX = pictureWidth.Value - plainWidth; - if(startPosY + plainHeight > pictureHeight) + if (startPosY + plainHeight > pictureHeight) startPosY = pictureHeight.Value - plainHeight; } public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingRadarPlane.cs b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingRadarPlane.cs index 9747a0e..3d83e59 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingRadarPlane.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingRadarPlane.cs @@ -9,13 +9,18 @@ namespace AirPlaneWithRadar { internal class DrawingRadarPlane : DrawingPlain { - public DrawingRadarPlane(int speed, float weight, Color bodyColor,Color dopColor, bool radar, bool oilBox) : base(speed, weight, bodyColor, 110, 60) + public DrawingRadarPlane(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool oilBox) : base(speed, weight, bodyColor, 110, 60) { Plain = new RadioPlane(speed, weight, bodyColor, dopColor, radar, oilBox); } + + public void ReColorDop(Color dopCol) + { + (Plain as RadioPlane).DopColor = dopCol; + } public override void DrawTransoprt(Graphics g) { - if(Plain is not RadioPlane radioPlane) + if (Plain is not RadioPlane radioPlane) { return; } @@ -27,7 +32,7 @@ namespace AirPlaneWithRadar g.DrawRectangle(pen, startPosX + 40, startPosY + 48, 20, 10); g.FillRectangle(doBrush, startPosX + 40, startPosY + 48, 20, 10); - g.DrawRectangle(pen, startPosX , startPosY+15, 30, 10); + g.DrawRectangle(pen, startPosX, startPosY + 15, 30, 10); g.FillRectangle(doBrush, startPosX, startPosY + 15, 30, 10); } if (radioPlane.Radar) @@ -35,7 +40,7 @@ namespace AirPlaneWithRadar g.FillRectangle(doBrush, startPosX + 55, startPosY + 20, 10, 10); g.FillEllipse(doBrush, startPosX + 40, startPosY + 13, 40, 10); } - + } } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/EntetyPlain.cs b/AirPlaneWithRadar/AirPlaneWithRadar/EntetyPlain.cs index 4c3c4e0..1f270f3 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/EntetyPlain.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/EntetyPlain.cs @@ -9,9 +9,9 @@ namespace AirPlaneWithRadar public class EntetyPlain { - public int Speed { get;private set; } - public float Weight { get; private set; } - public Color BodyColor { get; private set; } + public int Speed { get; private set; } + public float Weight { get; private set; } + public Color BodyColor { get; set; } public float Step => Speed * 100 / Weight; public EntetyPlain(int speed, float weight, Color bodyColor) @@ -22,6 +22,5 @@ namespace AirPlaneWithRadar BodyColor = bodyColor; } - } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs index 362a990..00a5bb1 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs @@ -87,7 +87,26 @@ namespace AirPlaneWithRadar { var formPlainConfig = new FormPlaneConfig(); + formPlainConfig.AddEvent(ReactEv); formPlainConfig.Show(); + + } + public void ReactEv(DrawingPlain dp) + { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawingObjectPlane(dp)) >= 0) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } private void ButtonRemovePlain_Click(object sender, EventArgs e) { diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormPlaneConfig.cs b/AirPlaneWithRadar/AirPlaneWithRadar/FormPlaneConfig.cs index 09f136f..438562e 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormPlaneConfig.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormPlaneConfig.cs @@ -14,7 +14,7 @@ namespace AirPlaneWithRadar { DrawingPlain _Plane = null; - private event PlainDelegate EventAddPlane; + private event Action EventAddPlane; public FormPlaneConfig() { @@ -40,7 +40,7 @@ namespace AirPlaneWithRadar pictureBoxObject.Image = bmp; } - public void AddEvent(PlainDelegate ev) + public void AddEvent(Action ev) { if (EventAddPlane == null) { @@ -120,12 +120,24 @@ namespace AirPlaneWithRadar private void LabelBaseColor_DragDrop(object sender, DragEventArgs e) { - + if (_Plane is null) return; + var col = e.Data.GetData(typeof(Color)); + Color newCol = (Color)col; + labelBaseColor.BackColor = newCol; + _Plane?.ReColor(newCol); + DrawPlane(); } private void LabelDopColor_DragDrop(object sender, DragEventArgs e) { - + if (_Plane is DrawingRadarPlane) + { + var col = e.Data.GetData(typeof(Color)); + Color newCol = (Color)col; + labelDopColor.BackColor = newCol; + (_Plane as DrawingRadarPlane).ReColorDop(newCol); + DrawPlane(); + } }