PIbd-23_Vrazhkin_S_A_Electr.../lab1/DrawingObjects/DrawingElectricLocomotiv.cs

44 lines
2.0 KiB
C#
Raw Permalink Normal View History

2023-10-17 13:49:31 +04:00
using System.Drawing.Drawing2D;
namespace ElectricLocomotive;
2023-10-03 11:53:51 +04:00
public class DrawingElectricLocomotiv : DrawingLocomotiv
{
2023-11-14 12:17:37 +04:00
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,
2023-10-17 13:49:31 +04:00
height, mainColor, dopColor)
2023-10-03 11:53:51 +04:00
{
2023-11-14 12:17:37 +04:00
this.isBattery = isBattery;
this.isRoga = isRoga;
2023-10-03 11:53:51 +04:00
if (EntityLocomotiv != null)
{
2023-10-17 13:49:31 +04:00
EntityLocomotiv = new EntityElectricLocomotiv(speed, weight, batteryColor, rogaColor, mainColor, dopColor);
2023-10-03 11:53:51 +04:00
}
}
2023-11-14 12:17:37 +04:00
public void ChangeAddColor(Color col)
{
((EntityElectricLocomotiv)EntityLocomotiv).BatteryColor = col;
((EntityElectricLocomotiv)EntityLocomotiv).RogaColor = col;
}
2023-10-03 11:53:51 +04:00
public override void DrawLoco(Graphics g)
{
if (EntityLocomotiv == null) return;
base.DrawLoco(g);
if (EntityLocomotiv is not EntityElectricLocomotiv electricLocomotiv) return;
SolidBrush batteryBrush = new(electricLocomotiv.BatteryColor);
Pen rogaPen = new(electricLocomotiv.RogaColor);
2023-11-14 12:17:37 +04:00
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);
}
2023-10-03 11:53:51 +04:00
}
}