diff --git a/lab1/DrawingObjects/DrawingElectricLocomotiv.cs b/lab1/DrawingObjects/DrawingElectricLocomotiv.cs index 65935d8..e0b5200 100644 --- a/lab1/DrawingObjects/DrawingElectricLocomotiv.cs +++ b/lab1/DrawingObjects/DrawingElectricLocomotiv.cs @@ -4,15 +4,24 @@ namespace ElectricLocomotive; public class DrawingElectricLocomotiv : DrawingLocomotiv { - public DrawingElectricLocomotiv(int speed, double weight, int width, int height, Color mainColor, Color dopColor, Color batteryColor, Color rogaColor) : base(speed, weight, width, + private bool isBattery; + private bool isRoga; + public DrawingElectricLocomotiv(bool isBattery, bool isRoga, int speed, double weight, int width, int height, Color mainColor, Color dopColor, Color batteryColor, Color rogaColor) : base(speed, weight, width, height, mainColor, dopColor) { + this.isBattery = isBattery; + this.isRoga = isRoga; if (EntityLocomotiv != null) { EntityLocomotiv = new EntityElectricLocomotiv(speed, weight, batteryColor, rogaColor, mainColor, dopColor); } } + public void ChangeAddColor(Color col) + { + ((EntityElectricLocomotiv)EntityLocomotiv).BatteryColor = col; + ((EntityElectricLocomotiv)EntityLocomotiv).RogaColor = col; + } public override void DrawLoco(Graphics g) { if (EntityLocomotiv == null) return; @@ -20,11 +29,16 @@ public class DrawingElectricLocomotiv : DrawingLocomotiv if (EntityLocomotiv is not EntityElectricLocomotiv electricLocomotiv) return; SolidBrush batteryBrush = new(electricLocomotiv.BatteryColor); Pen rogaPen = new(electricLocomotiv.RogaColor); - //Roga - g.DrawLine(rogaPen, new Point(_startPosX + _vehicleWidth / 2, _startPosY + 30), new Point(_startPosX + _vehicleWidth / 2 + 10, _startPosY + 15)); - g.DrawLine(rogaPen, new Point(_startPosX + _vehicleWidth / 2 + 10, _startPosY + 15), new Point(_startPosX + _vehicleWidth / 2, _startPosY)); - //battery - Point[] batteryPoints = { new Point(_startPosX + _vehicleWidth - 10,_startPosY + _vehicleHeight - 25), new Point(_startPosX + _vehicleWidth, _startPosY + _vehicleHeight - 20), new Point(_startPosX + _vehicleWidth, _startPosY + _vehicleHeight - 55), new Point(_startPosX + _vehicleWidth - 10, _startPosY + _vehicleHeight - 50) }; - g.FillPolygon(batteryBrush, batteryPoints); + if (this.isRoga) + { + g.DrawLine(rogaPen, new Point(_startPosX + _vehicleWidth / 2, _startPosY + 30), new Point(_startPosX + _vehicleWidth / 2 + 10, _startPosY + 15)); + g.DrawLine(rogaPen, new Point(_startPosX + _vehicleWidth / 2 + 10, _startPosY + 15), new Point(_startPosX + _vehicleWidth / 2, _startPosY)); + } + + if (this.isBattery) + { + Point[] batteryPoints = { new Point(_startPosX + _vehicleWidth - 10,_startPosY + _vehicleHeight - 25), new Point(_startPosX + _vehicleWidth, _startPosY + _vehicleHeight - 20), new Point(_startPosX + _vehicleWidth, _startPosY + _vehicleHeight - 55), new Point(_startPosX + _vehicleWidth - 10, _startPosY + _vehicleHeight - 50) }; + g.FillPolygon(batteryBrush, batteryPoints); + } } } \ No newline at end of file diff --git a/lab1/DrawingObjects/DrawingLocomotiv.cs b/lab1/DrawingObjects/DrawingLocomotiv.cs index 049598d..83be214 100644 --- a/lab1/DrawingObjects/DrawingLocomotiv.cs +++ b/lab1/DrawingObjects/DrawingLocomotiv.cs @@ -41,6 +41,14 @@ namespace ElectricLocomotive _pictureHeight = height; EntityLocomotiv = new EntityLocomotiv(speed, weight, mainColor, dopColor); } + + public void ChangeColor(Color col) + { + if (EntityLocomotiv == null) + return; + EntityLocomotiv.ColorBody = col; + EntityLocomotiv.ColorWindow = col; + } public bool CanMove(DirectionType direction) { if (EntityLocomotiv == null) @@ -96,6 +104,11 @@ namespace ElectricLocomotive break; } } + public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight) + { + _pictureHeight = pictureBoxHeight; + _pictureWidth = pictureBoxWidth; + } public virtual void DrawLoco(Graphics g) { if (EntityLocomotiv == null) return; diff --git a/lab1/Entities/EntityElectricLocomotiv.cs b/lab1/Entities/EntityElectricLocomotiv.cs index 5314e0f..28d0d89 100644 --- a/lab1/Entities/EntityElectricLocomotiv.cs +++ b/lab1/Entities/EntityElectricLocomotiv.cs @@ -2,8 +2,8 @@ public class EntityElectricLocomotiv : EntityLocomotiv { - public Color BatteryColor { get; private set; } - public Color RogaColor { get; private set; } + public Color BatteryColor { get; set; } + public Color RogaColor { get; set; } public EntityElectricLocomotiv(int speed,double weight, Color batteryColor, Color rogaColor, Color mainColor, Color dopColor) : base(speed, weight, mainColor, dopColor) { BatteryColor = batteryColor; diff --git a/lab1/Entities/EntityLocomotiv.cs b/lab1/Entities/EntityLocomotiv.cs index 5a32b76..17d0b17 100644 --- a/lab1/Entities/EntityLocomotiv.cs +++ b/lab1/Entities/EntityLocomotiv.cs @@ -9,8 +9,8 @@ namespace ElectricLocomotive { public class EntityLocomotiv { - public int Speed { get; private set; } - public double Weight { get; private set; } + public int Speed { get; set; } + public double Weight { get; set; } public double Step => (double)Speed * 100 / Weight; public Color ColorBody = Color.Black; public Color ColorWindow = Color.Blue; diff --git a/lab1/FormLocomotiv.cs b/lab1/FormLocomotiv.cs index e872ea1..bcbf3bf 100644 --- a/lab1/FormLocomotiv.cs +++ b/lab1/FormLocomotiv.cs @@ -43,7 +43,7 @@ namespace ElectricLocomotive { if (dialog.ShowDialog() == DialogResult.OK) dopColor = dialog.Color; - _drawingLocomotiv = new DrawingElectricLocomotiv(random.Next(100, 300), random.Next(1000, 3000), locoBox.Width, locoBox.Height, color, dopColor, batteryColor, rogaColor); + _drawingLocomotiv = new DrawingElectricLocomotiv(true, true, random.Next(100, 300), random.Next(1000, 3000), locoBox.Width, locoBox.Height, color, dopColor, batteryColor, rogaColor); _drawingLocomotiv.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } diff --git a/lab1/FormLocomotivCollection.cs b/lab1/FormLocomotivCollection.cs index 668f858..1020bd1 100644 --- a/lab1/FormLocomotivCollection.cs +++ b/lab1/FormLocomotivCollection.cs @@ -30,17 +30,22 @@ public partial class FormLocomotivCollection : Form { if (obj == null) { return; } - FormLocomotiv form = new(); - if (form.ShowDialog() == DialogResult.OK) { - if (obj + form.SelectedLocomotiv) { + FormLocoConfig form = new(); + form.Show(); + Action? monorailDelegate = new((m) => { + bool q = (obj + m); + if (q) + { MessageBox.Show("Объект добавлен"); + m.ChangePictureBoxSize(collectionPictureBox.Width, collectionPictureBox.Height); collectionPictureBox.Image = obj.ShowLocos(); } - else { + else + { MessageBox.Show("Не удалось добавить объект"); } - - } + }); + form.AddEvent(monorailDelegate); } private void deleteLoco_Click(object sender, EventArgs e) { if (storageListBox.SelectedIndex == -1) {