базовый объект и его прорисовка
This commit is contained in:
parent
69df949971
commit
781604b4a5
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive;
|
||||
namespace WarmlyLocomotive.Drawnings;
|
||||
|
||||
public enum DirectionType
|
||||
{
|
@ -1,13 +1,15 @@
|
||||
namespace WarmlyLocomotive;
|
||||
using WarmlyLocomotive.Entities;
|
||||
|
||||
namespace WarmlyLocomotive.Drawnings;
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningWarmlyLocomotive
|
||||
public class DrawningLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityWarmlyLocomotive? EntityWarmlyLocomotive { get; private set; }
|
||||
public EntityLocomotive? EntityLocomotive { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
@ -17,36 +19,88 @@ public class DrawningWarmlyLocomotive
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// Левая координата прорисовки паровоза
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
protected int? _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// Верхняя кооридната прорисовки паровоза
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
protected int? _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// Ширина прорисовки паровоза
|
||||
/// </summary>
|
||||
private readonly int _drawningLocomotiveWidth = 150;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// Высота прорисовки паровоза
|
||||
/// </summary>
|
||||
private readonly int _drawningLocomotiveHeight = 100;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool tube, bool fuelTank)
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int? GetPosX => _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int? GetPosY => _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawningLocomotiveWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _drawningLocomotiveHeight;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningLocomotive()
|
||||
{
|
||||
EntityWarmlyLocomotive = new EntityWarmlyLocomotive();
|
||||
EntityWarmlyLocomotive.Init(speed, weight, bodyColor, additionalColor,
|
||||
tube, fuelTank);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningLocomotive(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningLocomotiveWidth">Ширина прорисовки паровоза</param>
|
||||
/// <param name="drawningLocomotiveHeight">Высота прорисовки паровоза</param>
|
||||
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;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
@ -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
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
|
||||
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);
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
44
WarmlyLocomotive/Drawnings/DrawningWarmlyLocomotive.cs
Normal file
44
WarmlyLocomotive/Drawnings/DrawningWarmlyLocomotive.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using WarmlyLocomotive.Entities;
|
||||
|
||||
namespace WarmlyLocomotive.Drawnings;
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningWarmlyLocomotive : DrawningLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
43
WarmlyLocomotive/Entities/EntityLocomotive.cs
Normal file
43
WarmlyLocomotive/Entities/EntityLocomotive.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive.Entities;
|
||||
/// <summary>
|
||||
/// Базовый класс сущности
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор, заменяющий init
|
||||
/// </summary>
|
||||
/// <param name="speed">скорость</param>
|
||||
/// <param name="weight">вес</param>
|
||||
/// <param name="bodyColor">цвет</param>
|
||||
public EntityLocomotive(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
//AdditionalColor = additionalColor;
|
||||
//Tube = tube;
|
||||
//FuelTank = fuelTank;
|
||||
}
|
||||
|
||||
}
|
21
WarmlyLocomotive/Entities/EntityWarmlyLocomotive.cs
Normal file
21
WarmlyLocomotive/Entities/EntityWarmlyLocomotive.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using WarmlyLocomotive.Drawnings;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user