diff --git a/WarmlyLocomotive/DirectionType.cs b/WarmlyLocomotive/Drawnings/DirectionType.cs
similarity index 84%
rename from WarmlyLocomotive/DirectionType.cs
rename to WarmlyLocomotive/Drawnings/DirectionType.cs
index e197473..6f792c4 100644
--- a/WarmlyLocomotive/DirectionType.cs
+++ b/WarmlyLocomotive/Drawnings/DirectionType.cs
@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace WarmlyLocomotive;
+namespace WarmlyLocomotive.Drawnings;
public enum DirectionType
{
diff --git a/WarmlyLocomotive/DrawningWarmlyLocomotive.cs b/WarmlyLocomotive/Drawnings/DrawningLocomotive.cs
similarity index 54%
rename from WarmlyLocomotive/DrawningWarmlyLocomotive.cs
rename to WarmlyLocomotive/Drawnings/DrawningLocomotive.cs
index fdd0111..cbd2f8c 100644
--- a/WarmlyLocomotive/DrawningWarmlyLocomotive.cs
+++ b/WarmlyLocomotive/Drawnings/DrawningLocomotive.cs
@@ -1,13 +1,15 @@
-namespace WarmlyLocomotive;
+using WarmlyLocomotive.Entities;
+
+namespace WarmlyLocomotive.Drawnings;
///
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
///
-public class DrawningWarmlyLocomotive
+public class DrawningLocomotive
{
///
/// Класс-сущность
///
- public EntityWarmlyLocomotive? EntityWarmlyLocomotive { get; private set; }
+ public EntityLocomotive? EntityLocomotive { get; protected set; }
///
/// Ширина окна
///
@@ -17,36 +19,88 @@ public class DrawningWarmlyLocomotive
///
private int? _pictureHeight;
///
- /// Левая координата прорисовки автомобиля
+ /// Левая координата прорисовки паровоза
///
- private int? _startPosX;
+ protected int? _startPosX;
///
- /// Верхняя кооридната прорисовки автомобиля
+ /// Верхняя кооридната прорисовки паровоза
///
- private int? _startPosY;
+ protected int? _startPosY;
///
- /// Ширина прорисовки автомобиля
+ /// Ширина прорисовки паровоза
///
private readonly int _drawningLocomotiveWidth = 150;
///
- /// Высота прорисовки автомобиля
+ /// Высота прорисовки паровоза
///
private readonly int _drawningLocomotiveHeight = 100;
- ///
- /// Инициализация свойств
- ///
- public void Init(int speed, double weight, Color bodyColor, Color
- additionalColor, bool tube, bool fuelTank)
+ ///
+ /// Координата X объекта
+ ///
+ public int? GetPosX => _startPosX;
+
+ ///
+ /// Координата Y объекта
+ ///
+ public int? GetPosY => _startPosY;
+
+ ///
+ /// Ширина объекта
+ ///
+ public int GetWidth => _drawningLocomotiveWidth;
+
+ ///
+ /// Высота объекта
+ ///
+ public int GetHeight => _drawningLocomotiveHeight;
+
+
+ ///
+ /// Пустой конструктор
+ ///
+ private DrawningLocomotive()
{
- EntityWarmlyLocomotive = new EntityWarmlyLocomotive();
- EntityWarmlyLocomotive.Init(speed, weight, bodyColor, additionalColor,
- tube, fuelTank);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
+
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ public DrawningLocomotive(int speed, double weight, Color bodyColor) : this()
+ {
+ EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
+ }
+
+ ///
+ /// Конструктор для наследников
+ ///
+ /// Ширина прорисовки паровоза
+ /// Высота прорисовки паровоза
+ protected DrawningLocomotive(int drawningLocomotiveWidth, int drawningLocomotiveHeight) : this()
+ {
+ _drawningLocomotiveWidth = drawningLocomotiveWidth;
+ _pictureHeight = drawningLocomotiveHeight;
+ }
+
+ //public void Init(int speed, double weight, Color bodyColor, Color
+ //additionalColor, bool tube, bool fuelTank)
+ //{
+ // EntityWarmlyLocomotive = new EntityWarmlyLocomotive();
+ // EntityWarmlyLocomotive.Init(speed, weight, bodyColor, additionalColor,
+ // tube, fuelTank);
+ // _pictureWidth = null;
+ // _pictureHeight = null;
+ // _startPosX = null;
+ // _startPosY = null;
+ //}
+
///
/// Установка границ поля
///
@@ -62,7 +116,7 @@ public class DrawningWarmlyLocomotive
if (_startPosX != null && _startPosY != null)
{
//проверка х
- if ((_startPosX.Value + _drawningLocomotiveWidth) > _pictureWidth)
+ if (_startPosX.Value + _drawningLocomotiveWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _drawningLocomotiveWidth;
}
@@ -72,7 +126,7 @@ public class DrawningWarmlyLocomotive
}
//проверка у
- if ((_startPosY.Value + _drawningLocomotiveHeight) > _pictureHeight)
+ if (_startPosY.Value + _drawningLocomotiveHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _drawningLocomotiveHeight;
}
@@ -99,7 +153,7 @@ public class DrawningWarmlyLocomotive
}
//проверка у
- if ((y + _drawningLocomotiveHeight) > _pictureHeight)
+ if (y + _drawningLocomotiveHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _drawningLocomotiveHeight;
}
@@ -113,7 +167,7 @@ public class DrawningWarmlyLocomotive
}
//проверка х
- if ((x + _drawningLocomotiveWidth) > _pictureWidth)
+ if (x + _drawningLocomotiveWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _drawningLocomotiveWidth;
}
@@ -133,7 +187,7 @@ public class DrawningWarmlyLocomotive
public bool MoveTransport(DirectionType direction)
{
- if (EntityWarmlyLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ if (EntityLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
@@ -141,30 +195,30 @@ public class DrawningWarmlyLocomotive
{
//влево
case DirectionType.Left:
- if (_startPosX.Value - EntityWarmlyLocomotive.Step > 0)
+ if (_startPosX.Value - EntityLocomotive.Step > 0)
{
- _startPosX -= (int)EntityWarmlyLocomotive.Step;
+ _startPosX -= (int)EntityLocomotive.Step;
}
return true;
//вверх
case DirectionType.Up:
- if (_startPosY.Value - EntityWarmlyLocomotive.Step > 0)
+ if (_startPosY.Value - EntityLocomotive.Step > 0)
{
- _startPosY -= (int)EntityWarmlyLocomotive.Step;
+ _startPosY -= (int)EntityLocomotive.Step;
}
return true;
// вправо
case DirectionType.Right:
- if (_startPosX.Value + EntityWarmlyLocomotive.Step + _drawningLocomotiveWidth < _pictureWidth)
+ if (_startPosX.Value + EntityLocomotive.Step + _drawningLocomotiveWidth < _pictureWidth)
{
- _startPosX += (int)EntityWarmlyLocomotive.Step;
+ _startPosX += (int)EntityLocomotive.Step;
}
return true;
//вниз
case DirectionType.Down:
- if (_startPosY.Value + EntityWarmlyLocomotive.Step + _drawningLocomotiveHeight < _pictureHeight)
+ if (_startPosY.Value + EntityLocomotive.Step + _drawningLocomotiveHeight < _pictureHeight)
{
- _startPosY += (int)EntityWarmlyLocomotive.Step;
+ _startPosY += (int)EntityLocomotive.Step;
}
return true;
default:
@@ -175,24 +229,25 @@ public class DrawningWarmlyLocomotive
/// Прорисовка объекта
///
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
- if (EntityWarmlyLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ if (EntityLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
- Brush additionalBrush = new SolidBrush(EntityWarmlyLocomotive.AdditionalColor);
+
+ //Brush additionalBrush = new SolidBrush(EntityWarmlyLocomotive.AdditionalColor);
//труба
- if (EntityWarmlyLocomotive.Tube)
- {
- g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value, 20, 30);
- g.FillRectangle(additionalBrush, _startPosX.Value + 40, _startPosY.Value, 20, 40);
- }
+ //if (EntityWarmlyLocomotive.Tube)
+ //{
+ // g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value, 20, 30);
+ // g.FillRectangle(additionalBrush, _startPosX.Value + 40, _startPosY.Value, 20, 40);
+ //}
//локомотив
- Brush br = new SolidBrush(EntityWarmlyLocomotive.BodyColor);
+ Brush br = new SolidBrush(EntityLocomotive.BodyColor);
Brush blBr = new SolidBrush(Color.Black);
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 60, 140, 20);
g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 60, 140, 20);
@@ -200,11 +255,13 @@ public class DrawningWarmlyLocomotive
Point point2 = new Point(_startPosX.Value + 20, _startPosY.Value + 30);
Point point3 = new Point(_startPosX.Value + 140, _startPosY.Value + 30);
Point point4 = new Point(_startPosX.Value + 140, _startPosY.Value + 60);
- Point[] body ={point1, point2, point3, point4};
+ Point[] body = { point1, point2, point3, point4 };
g.DrawPolygon(pen, body);
g.FillPolygon(br, body);
g.DrawRectangle(pen, _startPosX.Value + 140, _startPosY.Value + 40, 10, 40);
g.FillRectangle(br, _startPosX.Value + 140, _startPosY.Value + 40, 10, 40);
+
+ //колеса
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 80, 20, 20);
g.FillEllipse(blBr, _startPosX.Value, _startPosY.Value + 80, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 80, 20, 20);
@@ -215,11 +272,11 @@ public class DrawningWarmlyLocomotive
g.FillEllipse(blBr, _startPosX.Value + 120, _startPosY.Value + 80, 20, 20);
// отсек для топлива
- if (EntityWarmlyLocomotive.FuelTank)
- {
- g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 40, 50, 40);
- g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 40, 50, 40);
- }
+ //if (EntityWarmlyLocomotive.FuelTank)
+ //{
+ // g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 40, 50, 40);
+ // g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 40, 50, 40);
+ //}
}
}
\ No newline at end of file
diff --git a/WarmlyLocomotive/Drawnings/DrawningWarmlyLocomotive.cs b/WarmlyLocomotive/Drawnings/DrawningWarmlyLocomotive.cs
new file mode 100644
index 0000000..e8fbfdb
--- /dev/null
+++ b/WarmlyLocomotive/Drawnings/DrawningWarmlyLocomotive.cs
@@ -0,0 +1,44 @@
+using WarmlyLocomotive.Entities;
+
+namespace WarmlyLocomotive.Drawnings;
+///
+/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
+///
+public class DrawningWarmlyLocomotive : DrawningLocomotive
+{
+ ///
+ /// Класс-сущность
+ ///
+ public DrawningWarmlyLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool tube, bool fuelTank) : base(150, 100)
+ {
+ EntityLocomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor, additionalColor, tube, fuelTank);
+ }
+
+
+ public override void DrawTransport(Graphics g)
+ {
+ if (EntityLocomotive == null || EntityLocomotive is not EntityWarmlyLocomotive warmlyLocomotive || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black);
+ Brush additionalBrush = new SolidBrush(warmlyLocomotive.AdditionalColor);
+
+ //труба
+ if (warmlyLocomotive.Tube)
+ {
+ g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value, 20, 30);
+ g.FillRectangle(additionalBrush, _startPosX.Value + 40, _startPosY.Value, 20, 40);
+ }
+
+
+ // отсек для топлива
+ if (warmlyLocomotive.FuelTank)
+ {
+ g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 40, 50, 40);
+ g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 40, 50, 40);
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/WarmlyLocomotive/Entities/EntityLocomotive.cs b/WarmlyLocomotive/Entities/EntityLocomotive.cs
new file mode 100644
index 0000000..1f65251
--- /dev/null
+++ b/WarmlyLocomotive/Entities/EntityLocomotive.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WarmlyLocomotive.Entities;
+///
+/// Базовый класс сущности
+///
+public class 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 Tube { get; private set; }
+
+ //public bool FuelTank { get; private set; }
+
+ public double Step => Speed * 100 / Weight;
+
+ ///
+ /// Конструктор, заменяющий init
+ ///
+ /// скорость
+ /// вес
+ /// цвет
+ public EntityLocomotive(int speed, double weight, Color bodyColor)
+ {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodyColor;
+ //AdditionalColor = additionalColor;
+ //Tube = tube;
+ //FuelTank = fuelTank;
+ }
+
+}
diff --git a/WarmlyLocomotive/Entities/EntityWarmlyLocomotive.cs b/WarmlyLocomotive/Entities/EntityWarmlyLocomotive.cs
new file mode 100644
index 0000000..9f87d42
--- /dev/null
+++ b/WarmlyLocomotive/Entities/EntityWarmlyLocomotive.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WarmlyLocomotive.Entities;
+public class EntityWarmlyLocomotive : EntityLocomotive
+{
+ public Color AdditionalColor { get; private set; }
+ public bool Tube;
+ public bool FuelTank;
+
+ public EntityWarmlyLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool tube, bool fuelTank) : base(speed, weight, bodyColor)
+ {
+ AdditionalColor = additionalColor;
+ Tube = tube;
+ FuelTank = fuelTank;
+ }
+}
+
diff --git a/WarmlyLocomotive/EntityWarmlyLocomotive.cs b/WarmlyLocomotive/EntityWarmlyLocomotive.cs
deleted file mode 100644
index 479b5d2..0000000
--- a/WarmlyLocomotive/EntityWarmlyLocomotive.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.NetworkInformation;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace WarmlyLocomotive;
-
-public class EntityWarmlyLocomotive
-{
- 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 Tube { get; private set; }
-
- public bool FuelTank { get; private set; }
-
- public double Step => Speed * 100 / Weight;
-
-
- public void Init(int speed, double weight, Color bodyColor, Color
-additionalColor, bool tube, bool fuelTank)
- {
- Speed = speed;
- Weight = weight;
- BodyColor = bodyColor;
- AdditionalColor = additionalColor;
- Tube = tube;
- FuelTank = fuelTank;
- }
-
-}
diff --git a/WarmlyLocomotive/FormWarmlyLocomotive.cs b/WarmlyLocomotive/FormWarmlyLocomotive.cs
index 943d472..ba05c40 100644
--- a/WarmlyLocomotive/FormWarmlyLocomotive.cs
+++ b/WarmlyLocomotive/FormWarmlyLocomotive.cs
@@ -7,6 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using WarmlyLocomotive.Drawnings;
namespace WarmlyLocomotive
{