diff --git a/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs
index 7c82bea..e0624df 100644
--- a/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs
+++ b/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs
@@ -3,96 +3,24 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using ProjectElectricLocomotive.DrawningObjects;
+using ProjectElectricLocomotive.Entities;
-namespace ElectricLocomotive
+namespace ProjectElectricLocomotive.DrawingObjects
{
- public class DrawningElectricLocomotive
+ public class DrawingElectricLocomotive : DrawningLocomotive
{
- public EntityElectricLocomotive? EntityElectricLocomotive { get; private set; }
- private int _pictureWidth;
- private int _pictureHeight;
- private int _startPosX;
- private int _startPosY;
- private readonly int _locomWidth = 80;
- private readonly int _locomHeight = 52;
- /// Скорость
- /// Вес
- /// Цвет кузова
- /// Дополнительный цвет
- /// Признак наличия токоприемника
- /// Признак наличия отсеков под электрические батареи
- /// Ширина картинки
- /// Высота картинки
- /// true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах
- public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool pantograph, bool compartment, int width, int height)
+ public DrawingElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor,
+ bool pantograph, bool compartment, int width, int height) : base(speed, weight, bodyColor, width, height, 80, 52)
{
- if (width < _locomWidth || height < _locomHeight)
+ if (EntityLocomotive != null)
{
- return false;
- }
- _pictureWidth = width;
- _pictureHeight = height;
- EntityElectricLocomotive = new EntityElectricLocomotive();
- EntityElectricLocomotive.Init(speed, weight, bodyColor, additionalColor, pantograph, compartment);
- return true;
- }
- /// Координата X
- /// Координата Y
- public void SetPosition(int x, int y)
- {
- if (x < 0 || x + _locomWidth > _pictureWidth)
- {
- x = _pictureWidth - _locomWidth;
- }
- if (y < 0 || y + _locomHeight > _pictureHeight)
- {
- y = _pictureHeight - _locomHeight;
- }
- _startPosX = x;
- _startPosY = y;
- }
- /// Направление
- public void MoveTransport(Direction direction)
- {
- if (EntityElectricLocomotive == null)
- {
- return;
- }
- switch (direction)
- {
- //влево
- case Direction.Left:
- if (_startPosX - EntityElectricLocomotive.Step > 0)
- {
- _startPosX -= (int)EntityElectricLocomotive.Step;
- }
- break;
- //вверх
- case Direction.Up:
- if (_startPosY - EntityElectricLocomotive.Step > 0)
- {
- _startPosY -= (int)EntityElectricLocomotive.Step;
- }
- break;
- //вправо
- case Direction.Right:
- if (_startPosX + EntityElectricLocomotive.Step + _locomWidth < _pictureWidth)
- {
- _startPosX += (int)EntityElectricLocomotive.Step;
- }
- break;
- case Direction.Down:
- if (_startPosY + EntityElectricLocomotive.Step + _locomHeight < _pictureHeight)
- {
- _startPosY += (int)EntityElectricLocomotive.Step;
- }
- break;
+ EntityLocomotive = new EntityElectricLocomotive(speed, width, bodyColor, additionalColor, pantograph, compartment);
}
}
- ///
- public void DrawTransport(Graphics g)
+ public override void DrawTransport(Graphics g)
{
- if (EntityElectricLocomotive == null)
+ if (EntityLocomotive is not EntityElectricLocomotive electricLocomotive)
{
return;
}
@@ -100,74 +28,30 @@ namespace ElectricLocomotive
Pen pen = new(Color.Black);
Brush blackBrush = new SolidBrush(Color.Black);
Brush windows = new SolidBrush(Color.LightBlue);
- Brush bodyColor = new SolidBrush(EntityElectricLocomotive.BodyColor);
- Brush additionalBrush = new SolidBrush(EntityElectricLocomotive.AdditionalColor);
+ Brush bodyColor = new SolidBrush(electricLocomotive.BodyColor);
+ Brush additionalBrush = new SolidBrush(electricLocomotive.AdditionalColor);
- if (EntityElectricLocomotive.Pantograph)
+ if (electricLocomotive.Pantograph)
{
- // Токоприемники
g.FillRectangle(blackBrush, _startPosX + 30, _startPosY + 15, 20, 5);
g.DrawLine(pen, _startPosX + 30, _startPosY + 15, _startPosX + 50, _startPosY + 2);
g.DrawLine(pen, _startPosX + 40, _startPosY + 15, _startPosX + 60, _startPosY + 2);
}
- // Локомотив
- g.FillPolygon(bodyColor, new Point[]
- {
- new Point(_startPosX, _startPosY + 40),
- new Point(_startPosX, _startPosY + 30),
- new Point(_startPosX + 20, _startPosY + 20),
- new Point(_startPosX + 70, _startPosY + 20),
- new Point(_startPosX +80, _startPosY + 20),
- new Point(_startPosX +80, _startPosY + 40),
- new Point(_startPosX +75, _startPosY + 45),
- new Point(_startPosX +5, _startPosY + 45),
- new Point(_startPosX, _startPosY + 40),
- }
- );
-
- if (EntityElectricLocomotive.Compartment)
+ if (electricLocomotive.Compartment)
{
g.DrawRectangle(pen, _startPosX + 40, _startPosY + 24, 25, 11);
g.FillPolygon(additionalBrush, new Point[]
- {
- new Point(_startPosX + 41, _startPosY + 25),
- new Point(_startPosX + 65, _startPosY + 25),
- new Point(_startPosX + 65, _startPosY + 35),
- new Point(_startPosX + 41, _startPosY + 35),
- new Point(_startPosX + 41, _startPosY + 25),
- }
- );
+ {
+ new Point(_startPosX + 41, _startPosY + 25),
+ new Point(_startPosX + 65, _startPosY + 25),
+ new Point(_startPosX + 65, _startPosY + 35),
+ new Point(_startPosX + 41, _startPosY + 35),
+ new Point(_startPosX + 41, _startPosY + 25),
+ }
+ );
}
-
- g.DrawPolygon(pen, new Point[]
- {
- new Point(_startPosX, _startPosY + 40),
- new Point(_startPosX, _startPosY + 30),
- new Point(_startPosX + 20, _startPosY + 20),
- new Point(_startPosX + 70, _startPosY + 20),
- new Point(_startPosX + 80, _startPosY + 20),
- new Point(_startPosX + 80, _startPosY + 40),
- new Point(_startPosX + 75, _startPosY + 45),
- new Point(_startPosX + 5, _startPosY + 45),
- new Point(_startPosX, _startPosY + 40),
- }
- );
-
- // Окна
- g.FillEllipse(windows, _startPosX + 10, _startPosY + 24, 10, 10);
- g.DrawEllipse(pen, _startPosX + 10, _startPosY + 25, 10, 10);
-
- g.FillRectangle(windows, _startPosX + 25, _startPosY + 25, 10, 5);
- g.DrawRectangle(pen, _startPosX + 25, _startPosY + 25, 10, 5);
-
- // Колёса
- // Локомотив
- g.FillEllipse(blackBrush, _startPosX + 10, _startPosY + 45, 10, 10);
- g.FillEllipse(blackBrush, _startPosX + 25, _startPosY + 45, 10, 10);
-
- g.FillEllipse(blackBrush, _startPosX + 50, _startPosY + 45, 10, 10);
- g.FillEllipse(blackBrush, _startPosX + 65, _startPosY + 45, 10, 10);
+ base.DrawTransport(g);
}
}
-}
\ No newline at end of file
+}
diff --git a/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs
new file mode 100644
index 0000000..762cdc3
--- /dev/null
+++ b/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs
@@ -0,0 +1,161 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ElectricLocomotive;
+using ProjectElectricLocomotive.Entities;
+using ProjectElectricLocomotive.Properties;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement;
+
+namespace ProjectElectricLocomotive.DrawningObjects
+{
+ public class DrawningLocomotive
+ {
+ public EntityLocomotive? EntityLocomotive { get; protected set; }
+
+ protected int _pictureWidth;
+ protected int _pictureHeight;
+ protected int _startPosX;
+ protected int _startPosY;
+ protected readonly int _locomWidth = 80;
+ protected readonly int _locomHeight = 52;
+ /// Скорость
+ /// Вес
+ /// Цвет кузова
+ /// Ширина картинки
+ /// Высота картинки
+
+ public DrawningLocomotive(int speed, double weight, Color bodyColor, int width, int heigth)
+ {
+ if (width < _locomWidth || heigth < _locomHeight)
+ {
+ return;
+ }
+ _pictureWidth = width;
+ _pictureHeight = heigth;
+ EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
+ }
+ /// Скорость
+ /// Вес
+ /// Цвет кузова
+ /// Ширина картинки
+ /// Высота картинки
+ /// Ширина картинки
+ /// Высота картинки
+ protected DrawningLocomotive(int speed, double weight, Color bodyColor, int width,
+ int height, int locomWidth, int locomHeight)
+ {
+ if (width < _locomWidth || height < _locomHeight)
+ {
+ return;
+ }
+ _pictureWidth = width;
+ _pictureHeight = height;
+ _locomWidth = locomWidth;
+ _locomHeight = locomHeight;
+ EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
+ }
+ /// Координата X
+ /// Координата Y
+ public void SetPosition(int x, int y)
+ {
+ if (x < 0 || x + _locomWidth > _pictureWidth)
+ {
+ x = _pictureWidth - _locomWidth;
+ }
+ if (y < 0 || y + _locomHeight > _pictureHeight)
+ {
+ y = _pictureHeight - _locomHeight;
+ }
+ _startPosX = x;
+ _startPosY = y;
+ }
+ /// Направление
+ public void MoveTransport(Direction direction)
+ {
+ if (EntityLocomotive == null)
+ {
+ return;
+ }
+ switch (direction)
+ {
+ case Direction.Left:
+ if (_startPosX - EntityLocomotive.Step > 0)
+ {
+ _startPosX -= (int)EntityLocomotive.Step;
+ }
+ break;
+ case Direction.Up:
+ if (_startPosY - EntityLocomotive.Step > 0)
+ {
+ _startPosY -= (int)EntityLocomotive.Step;
+ }
+ break;
+ case Direction.Right:
+ if (_startPosX + EntityLocomotive.Step + _locomWidth < _pictureWidth)
+ {
+ _startPosX += (int)EntityLocomotive.Step;
+ }
+ break;
+ case Direction.Down:
+ if (_startPosY + EntityLocomotive.Step + _locomHeight < _pictureHeight)
+ {
+ _startPosY += (int)EntityLocomotive.Step;
+ }
+ break;
+ }
+ }
+ ///
+ public virtual void DrawTransport(Graphics g)
+ {
+ {
+ if (EntityLocomotive == null) return;
+ }
+
+ Pen pen = new(Color.Black);
+ Brush blackBrush = new SolidBrush(Color.Black);
+ Brush windows = new SolidBrush(Color.LightBlue);
+ Brush bodyColor = new SolidBrush(EntityLocomotive.BodyColor);
+ g.FillPolygon(bodyColor, new Point[]
+ {
+ new Point(_startPosX, _startPosY + 40),
+ new Point(_startPosX, _startPosY + 30),
+ new Point(_startPosX + 20, _startPosY + 20),
+ new Point(_startPosX + 70, _startPosY + 20),
+ new Point(_startPosX + 80, _startPosY + 20),
+ new Point(_startPosX + 80, _startPosY + 40),
+ new Point(_startPosX + 75, _startPosY + 45),
+ new Point(_startPosX + 5, _startPosY + 45),
+ new Point(_startPosX, _startPosY + 40),
+ }
+ );
+ g.DrawPolygon(pen, new Point[]
+ {
+ new Point(_startPosX, _startPosY + 40),
+ new Point(_startPosX, _startPosY + 30),
+ new Point(_startPosX + 20, _startPosY + 20),
+ new Point(_startPosX + 70, _startPosY + 20),
+ new Point(_startPosX + 80, _startPosY + 20),
+ new Point(_startPosX + 80, _startPosY + 40),
+ new Point(_startPosX + 75, _startPosY + 45),
+ new Point(_startPosX + 5, _startPosY + 45),
+ new Point(_startPosX, _startPosY + 40),
+ }
+ );
+
+ g.FillEllipse(windows, _startPosX + 10, _startPosY + 24, 10, 10);
+ g.DrawEllipse(pen, _startPosX + 10, _startPosY + 25, 10, 10);
+
+ g.FillRectangle(windows, _startPosX + 25, _startPosY + 25, 10, 5);
+ g.DrawRectangle(pen, _startPosX + 25, _startPosY + 25, 10, 5);
+
+
+ g.FillEllipse(blackBrush, _startPosX + 10, _startPosY + 45, 10, 10);
+ g.FillEllipse(blackBrush, _startPosX + 25, _startPosY + 45, 10, 10);
+
+ g.FillEllipse(blackBrush, _startPosX + 50, _startPosY + 45, 10, 10);
+ g.FillEllipse(blackBrush, _startPosX + 65, _startPosY + 45, 10, 10);
+ }
+ }
+}
diff --git a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs
index e54c539..1f148e3 100644
--- a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs
+++ b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs
@@ -1,31 +1,24 @@
-using System;
+using ProjectElectricLocomotive.Entities;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace ElectricLocomotive
+namespace ProjectElectricLocomotive.Entities
{
- public class EntityElectricLocomotive
+ public class EntityElectricLocomotive : EntityLocomotive
{
- public int Speed { get; private set; }
- public double Weight { get; private set; }
- public Color BodyColor { get; private set; }
public Color AdditionalColor { get; private set; }
public bool Pantograph { get; private set; }
public bool Compartment { get; private set; }
- public double Step => (double)Speed * 100 / Weight;
- /// Скорость
- /// Вес локомотива
- /// Основной цвет
+
/// Дополнительный цвет
/// Признак наличия токоприемника
/// Признак наличия отсеков под электрические батареи
- public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool pantograph, bool compartment)
+ public EntityElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool pantograph,
+ bool compartment) : base(speed, weight, bodyColor)
{
- Speed = speed;
- Weight = weight;
- BodyColor = bodyColor;
AdditionalColor = additionalColor;
Pantograph = pantograph;
Compartment = compartment;
diff --git a/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs
new file mode 100644
index 0000000..da602cf
--- /dev/null
+++ b/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectElectricLocomotive.Entities
+{
+ public class EntityLocomotive
+ {
+ public int Speed { get; private set; }
+ public double Weight { get; private set; }
+ public Color BodyColor { get; private set; }
+ public double Step => (double)Speed * 100 / Weight;
+
+ /// Скорость
+ /// Вес локомотива
+ /// Основной цвет
+ public EntityLocomotive (int speed, double weight, Color bodyColor)
+ {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodyColor;
+ }
+ }
+}
diff --git a/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.csproj b/ElectricLocomotive/ElectricLocomotive/ProjectElectricLocomotive.csproj
similarity index 100%
rename from ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.csproj
rename to ElectricLocomotive/ElectricLocomotive/ProjectElectricLocomotive.csproj
diff --git a/ElectricLocomotive/ElectricLocomotive/Properties/Resources.Designer.cs b/ElectricLocomotive/ElectricLocomotive/Properties/Resources.Designer.cs
index 13a990a..d973a85 100644
--- a/ElectricLocomotive/ElectricLocomotive/Properties/Resources.Designer.cs
+++ b/ElectricLocomotive/ElectricLocomotive/Properties/Resources.Designer.cs
@@ -8,7 +8,7 @@
//
//------------------------------------------------------------------------------
-namespace ElectricLocomotive.Properties {
+namespace ProjectElectricLocomotive.Properties {
using System;
@@ -39,7 +39,7 @@ namespace ElectricLocomotive.Properties {
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
- global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ElectricLocomotive.Properties.Resources", typeof(Resources).Assembly);
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectElectricLocomotive.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
diff --git a/ElectricLocomotive/ElectricLocomotive.sln b/ElectricLocomotive/ProjectElectricLocomotive.sln
similarity index 84%
rename from ElectricLocomotive/ElectricLocomotive.sln
rename to ElectricLocomotive/ProjectElectricLocomotive.sln
index 8cf9c0a..37fda21 100644
--- a/ElectricLocomotive/ElectricLocomotive.sln
+++ b/ElectricLocomotive/ProjectElectricLocomotive.sln
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34031.279
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectricLocomotive", "ElectricLocomotive\ElectricLocomotive.csproj", "{A7A62158-ECC2-48DA-81F7-565BB5CE1E0D}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectElectricLocomotive", "ElectricLocomotive\ProjectElectricLocomotive.csproj", "{A7A62158-ECC2-48DA-81F7-565BB5CE1E0D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution