diff --git a/ProjectLocomotive/ProjectLocomotive/DrawningElectroLocomotive.cs b/ProjectLocomotive/ProjectLocomotive/DrawningElectroLocomotive.cs
new file mode 100644
index 0000000..395b329
--- /dev/null
+++ b/ProjectLocomotive/ProjectLocomotive/DrawningElectroLocomotive.cs
@@ -0,0 +1,90 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectLocomotive
+{
+ internal class DrawningElectroLocomotive : DrawningLocomotive
+ {
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Цвет кузова
+ /// Дополнительный цвет
+ /// Признак наличия "рогов" для подключения
+ /// Признак наличия отсека электро-батарей
+ public DrawningElectroLocomotive(int speed, float weight, Color bodyColor, Color
+ dopColor, bool electroLines, bool electroBattery) :
+ base(speed, weight, bodyColor, 110, 60)
+ {
+ Locomotivе = new EntityElectricLocomotive(speed, weight, bodyColor, dopColor, electroLines,
+ electroBattery);
+ }
+ public override void DrawTransport(Graphics g)
+ {
+ if (Locomotivе is not EntityElectricLocomotive elLocc)
+ {
+ return;
+ }
+ Pen pen = new(Color.Black);
+ Brush dopBrush = new SolidBrush(elLocc.DopColor);
+ if (elLocc.ElectroLines)
+ {
+ g.DrawLine(pen, _startPosX + 20, _startPosY, _startPosX + 5, _startPosY - 12);
+ g.DrawLine(pen, _startPosX + 20, _startPosY, _startPosX + 35, _startPosY - 12);
+ g.DrawLine(pen, _startPosX + 70, _startPosY, _startPosX + 55, _startPosY - 12);
+ g.DrawLine(pen, _startPosX + 70, _startPosY, _startPosX + 85, _startPosY - 12);
+ // g.DrawEllipse(pen, _startPosX + 90, _startPosY, 20, 20);
+ // g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 20, 20);
+ // g.DrawRectangle(pen, _startPosX + 90, _startPosY + 10, 20, 40);
+ // g.DrawRectangle(pen, _startPosX + 90, _startPosY, 15, 15);
+ // g.DrawRectangle(pen, _startPosX + 90, _startPosY + 45, 15, 15);
+ // g.FillEllipse(dopBrush, _startPosX + 90, _startPosY, 20, 20);
+ // g.FillEllipse(dopBrush, _startPosX + 90, _startPosY + 40, 20, 20);
+ // g.FillRectangle(dopBrush, _startPosX + 90, _startPosY + 10, 20,
+ //40);
+ // g.FillRectangle(dopBrush, _startPosX + 90, _startPosY + 1, 15,
+ //15);
+ // g.FillRectangle(dopBrush, _startPosX + 90, _startPosY + 45, 15,
+ //15);
+ // g.DrawEllipse(pen, _startPosX, _startPosY, 20, 20);
+ // g.DrawEllipse(pen, _startPosX, _startPosY + 40, 20, 20);
+ // g.DrawRectangle(pen, _startPosX, _startPosY + 10, 20, 40);
+ // g.DrawRectangle(pen, _startPosX + 5, _startPosY, 14, 15);
+ // g.DrawRectangle(pen, _startPosX + 5, _startPosY + 45, 14, 15);
+ // g.FillEllipse(dopBrush, _startPosX, _startPosY, 20, 20);
+ // g.FillEllipse(dopBrush, _startPosX, _startPosY + 40, 20, 20);
+ // g.FillRectangle(dopBrush, _startPosX + 1, _startPosY + 10, 25,
+ //40);
+ // g.FillRectangle(dopBrush, _startPosX + 5, _startPosY + 1, 15, 15);
+ // g.FillRectangle(dopBrush, _startPosX + 5, _startPosY + 45, 15,
+ //15);
+ // g.DrawRectangle(pen, _startPosX + 35, _startPosY, 39, 15);
+ // g.DrawRectangle(pen, _startPosX + 35, _startPosY + 45, 39, 15);
+ // g.FillRectangle(dopBrush, _startPosX + 35, _startPosY + 1, 40,
+ //15);
+ // g.FillRectangle(dopBrush, _startPosX + 35, _startPosY + 45, 40,
+ //15);
+ }
+ //_startPosX += 10;
+ //_startPosY += 5;
+ base.DrawTransport(g);
+ //_startPosX -= 10;
+ //_startPosY -= 5;
+ if (elLocc.ElectroBattery)
+ {
+ Brush brblack = new SolidBrush(Color.Black);
+ g.FillRectangle(brblack, _startPosX + 40, _startPosY + 25, 15, 5);
+ g.FillRectangle(brblack, _startPosX + 60, _startPosY + 25, 15, 5);
+ g.FillRectangle(brblack, _startPosX + 5, _startPosY + 25, 15, 5);
+ //g.FillRectangle(brblack, _startPosX + 70, _startPosY + 3, 5, 10);
+ //g.FillRectangle(dopBrush, _startPosX, _startPosY + 5, 10, 50);
+ //g.DrawRectangle(pen, _startPosX, _startPosY + 5, 10, 50);
+ }
+ }
+ }
+}
diff --git a/ProjectLocomotive/ProjectLocomotive/DrawningLocomotive.cs b/ProjectLocomotive/ProjectLocomotive/DrawningLocomotive.cs
index fd3163e..ad2118a 100644
--- a/ProjectLocomotive/ProjectLocomotive/DrawningLocomotive.cs
+++ b/ProjectLocomotive/ProjectLocomotive/DrawningLocomotive.cs
@@ -14,15 +14,15 @@ namespace ProjectLocomotive
///
/// Класс-сущность
///
- public EntityLocomotive Locomotivе { private set; get; }
+ public EntityLocomotive Locomotivе { get; protected set; }
///
/// Левая координата отрисовки локомотива
///
- private float _startPosX;
+ protected float _startPosX;
///
/// Верхняя кооридната отрисовки локомотива
///
- private float _startPosY;
+ protected float _startPosY;
///
/// Ширина окна отрисовки
///
@@ -50,6 +50,21 @@ namespace ProjectLocomotive
Locomotivе = new EntityLocomotive(speed, weight, bodyColor);
}
///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Цвет кузова
+ /// Ширина отрисовки автомобиля
+ /// Высота отрисовки автомобиля
+ protected DrawningLocomotive(int speed, float weight, Color bodyColor, int
+ carWidth, int carHeight) :
+ this(speed, weight, bodyColor)
+ {
+ _LocWidth = carWidth;
+ _LocHeight = carHeight;
+ }
+ ///
/// Установка позиции автомобиля
///
/// Координата X
@@ -118,7 +133,7 @@ namespace ProjectLocomotive
/// Отрисовка автомобиля
///
///
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
diff --git a/ProjectLocomotive/ProjectLocomotive/EntityElectricLocomotive.cs b/ProjectLocomotive/ProjectLocomotive/EntityElectricLocomotive.cs
new file mode 100644
index 0000000..4b17262
--- /dev/null
+++ b/ProjectLocomotive/ProjectLocomotive/EntityElectricLocomotive.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectLocomotive
+{
+ internal class EntityElectricLocomotive : EntityLocomotive
+ {
+ ///
+ /// Дополнительный цвет
+ ///
+ public Color DopColor { get; private set; }
+ ///
+ /// Признак наличия "рогов" для подключения
+ ///
+ public bool ElectroLines { get; private set; }
+ ///
+ /// Признак наличия отсека электро-батарей
+ ///
+ public bool ElectroBattery { get; private set; }
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Цвет кузова
+ /// Дополнительный цвет
+ /// Признак наличия "рогов" для подключения
+ /// Признак наличия отсека электро-батарей
+
+ public EntityElectricLocomotive(int speed, float weight, Color bodyColor, Color
+ dopColor, bool electroLines, bool electroBattery) :
+ base(speed, weight, bodyColor)
+ {
+ DopColor = dopColor;
+ ElectroLines = electroLines = true;
+ ElectroBattery = electroBattery = true;
+ }
+ }
+}
diff --git a/ProjectLocomotive/ProjectLocomotive/FormLocomotive.Designer.cs b/ProjectLocomotive/ProjectLocomotive/FormLocomotive.Designer.cs
index 30a2ee7..1a7a23d 100644
--- a/ProjectLocomotive/ProjectLocomotive/FormLocomotive.Designer.cs
+++ b/ProjectLocomotive/ProjectLocomotive/FormLocomotive.Designer.cs
@@ -38,6 +38,7 @@
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.statusStrip = new System.Windows.Forms.StatusStrip();
+ this.buttonCreateModif = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
@@ -88,19 +89,6 @@
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
this.buttonLeft.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize);
//
- // buttonRight
- //
- this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonRight.BackgroundImage = global::ProjectLocomotive.Properties.Resources.right;
- this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonRight.Location = new System.Drawing.Point(711, 375);
- this.buttonRight.Name = "buttonRight";
- this.buttonRight.Size = new System.Drawing.Size(30, 30);
- this.buttonRight.TabIndex = 5;
- this.buttonRight.UseVisualStyleBackColor = true;
- this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
- this.buttonRight.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize);
- //
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
@@ -114,6 +102,19 @@
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
this.buttonDown.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize);
//
+ // buttonRight
+ //
+ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonRight.BackgroundImage = global::ProjectLocomotive.Properties.Resources.right;
+ this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonRight.Location = new System.Drawing.Point(711, 375);
+ this.buttonRight.Name = "buttonRight";
+ this.buttonRight.Size = new System.Drawing.Size(30, 30);
+ this.buttonRight.TabIndex = 5;
+ this.buttonRight.UseVisualStyleBackColor = true;
+ this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
+ this.buttonRight.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize);
+ //
// toolStripStatusLabelSpeed
//
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
@@ -144,11 +145,22 @@
this.statusStrip.Size = new System.Drawing.Size(800, 32);
this.statusStrip.TabIndex = 1;
//
+ // buttonCreateModif
+ //
+ this.buttonCreateModif.Location = new System.Drawing.Point(120, 375);
+ this.buttonCreateModif.Name = "buttonCreateModif";
+ this.buttonCreateModif.Size = new System.Drawing.Size(138, 30);
+ this.buttonCreateModif.TabIndex = 7;
+ this.buttonCreateModif.Text = "Модификация";
+ this.buttonCreateModif.UseVisualStyleBackColor = true;
+ this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
+ //
// FormLocomotive
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft);
@@ -178,5 +190,6 @@
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private StatusStrip statusStrip;
+ private Button buttonCreateModif;
}
}
\ No newline at end of file
diff --git a/ProjectLocomotive/ProjectLocomotive/FormLocomotive.cs b/ProjectLocomotive/ProjectLocomotive/FormLocomotive.cs
index c082a4f..f361b4c 100644
--- a/ProjectLocomotive/ProjectLocomotive/FormLocomotive.cs
+++ b/ProjectLocomotive/ProjectLocomotive/FormLocomotive.cs
@@ -20,6 +20,17 @@ namespace ProjectLocomotive
pictureBoxLocomotive.Image = bmp;
}
///
+ ///
+ ///
+ private void SetData()
+ {
+ Random rnd = new();
+ _elloc.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
+ toolStripStatusLabelSpeed.Text = $": {_elloc.Locomotiv.Speed}";
+ toolStripStatusLabelWeight.Text = $": {_elloc.Locomotiv.Weight}";
+ toolStripStatusLabelBodyColor.Text = $": {_elloc.Locomotiv.BodyColor.Name}";
+ }
+ ///
/// ""
///
///
@@ -29,10 +40,7 @@ namespace ProjectLocomotive
{
Random rnd = new();
_elloc = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
- _elloc.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
- toolStripStatusLabelSpeed.Text = $": {_elloc.Locomotiv.Speed}";
- toolStripStatusLabelWeight.Text = $": {_elloc.Locomotiv.Weight}";
- toolStripStatusLabelBodyColor.Text = $": {_elloc.Locomotiv.BodyColor.Name}";
+ SetData();
Draw();
}
///
@@ -71,5 +79,20 @@ namespace ProjectLocomotive
_elloc?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
Draw();
}
+ ///
+ /// ""
+ ///
+ ///
+ ///
+ private void ButtonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ _elloc = new DrawningElectroLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
+ Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ Color.FromArgb(rnd.Next(1, 100), rnd.Next(1, 100), rnd.Next(1, 100)),
+ Convert.ToBoolean(rnd.Next(0, 1)), Convert.ToBoolean(rnd.Next(0, 1)));
+ SetData();
+ Draw();
+ }
}
}
\ No newline at end of file