This commit is contained in:
kirin 2023-11-14 12:17:37 +04:00
parent 3be2467d2f
commit 800dd3ae26
6 changed files with 50 additions and 18 deletions

View File

@ -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);
}
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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();
}

View File

@ -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<DrawingLocomotiv>? 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) {