Compare commits
No commits in common. "b32311652faafed3046b455fa0d6946c9024d23c" and "83216e0433e603298e0b2d6283a9b19869f2fae7" have entirely different histories.
b32311652f
...
83216e0433
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.7.34221.43
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HoistingCrane", "HoistingCrane\HoistingCrane.csproj", "{915BDF62-D64D-4AB9-BA2D-8E228E803B7F}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HoistingCrane", "HoistingCrane\HoistingCrane.csproj", "{915BDF62-D64D-4AB9-BA2D-8E228E803B7F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -1,14 +1,10 @@
|
||||
namespace HoistingCrane.Drawning;
|
||||
namespace HoistingCrane;
|
||||
|
||||
public enum DirectionType //Создали не класс(class), а перечисление (enum)
|
||||
public enum DirectionType : byte //Создали не класс(class), а перечисление (enum)
|
||||
{
|
||||
//Перечислим основные траектории движния нашего автомобиля. Сразу же зададим значения.
|
||||
/// <summary>
|
||||
/// Неизвестное направление
|
||||
/// </summary>
|
||||
Unknow = -1,
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// Вверх1
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
@ -1,84 +0,0 @@
|
||||
using HoistingCrane.Entities;
|
||||
using System.Configuration;
|
||||
|
||||
namespace HoistingCrane.Drawning;
|
||||
|
||||
//В данном классе мы будем думать над полем игры, размерами персонажа, размерами объектов и т.д.
|
||||
public class DrawningHoistingCrane : DrawningTrackedVehicle
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawingCarWidth = 115;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawingCarHeight = 63;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// конструктор класса отрисовки крана
|
||||
/// </summary>
|
||||
/// <param name="AdditionalColor">Дополнительный цвет</param>
|
||||
/// <param name="Counterweight">Противовес</param>
|
||||
/// <param name="Platform">Платформа</param>
|
||||
public DrawningHoistingCrane(int speed, int weight, Color bodyColor, Color additionalColor, bool counterweight, bool platform) : base(115, 63)
|
||||
{
|
||||
EntityTrackedVehicle = new EntityHoistingCrane(speed, weight, bodyColor, additionalColor, counterweight, platform);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Метод отрисовки объекта
|
||||
/// </summary>
|
||||
/// <param name="gr"></param>
|
||||
public override void DrawTransport(Graphics gr)
|
||||
{
|
||||
if (EntityTrackedVehicle == null || EntityTrackedVehicle is not EntityHoistingCrane EntityHoistingCrane || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
base.DrawTransport(gr);
|
||||
Brush b = new SolidBrush(EntityHoistingCrane.AdditionalColor);
|
||||
Pen pen = new Pen(EntityHoistingCrane.AdditionalColor);
|
||||
Pen penBase = new Pen(EntityHoistingCrane.BodyColor);
|
||||
if (EntityHoistingCrane.Counterweight)
|
||||
{
|
||||
//противовес
|
||||
|
||||
gr.DrawRectangle(pen, _startPosX.Value + 69, _startPosY.Value + 3, 10, 10);
|
||||
gr.DrawLine(pen, _startPosX.Value + 68, _startPosY.Value + 3, _startPosX.Value + 78, _startPosY.Value + 12);
|
||||
gr.DrawLine(pen, _startPosX.Value + 68, _startPosY.Value + 7, _startPosX.Value + 78, _startPosY.Value + 3);
|
||||
}
|
||||
|
||||
if (EntityHoistingCrane.Platform) {
|
||||
//Наличие спусковой платформы
|
||||
|
||||
gr.FillRectangle(b, _startPosX.Value + 101, _startPosY.Value + 40, 15, 5);
|
||||
gr.FillRectangle(b, _startPosX.Value + 116, _startPosY.Value + 35, 4, 5);
|
||||
gr.FillRectangle(b, _startPosX.Value + 97, _startPosY.Value + 35, 4, 5);
|
||||
}
|
||||
|
||||
|
||||
//Отрисовка крана, на котором держится платформа и противовес
|
||||
gr.FillRectangle(b, _startPosX.Value + 65, _startPosY.Value, 5, 26);
|
||||
gr.FillRectangle(b, _startPosX.Value + 65, _startPosY.Value, 50, 4);
|
||||
gr.DrawLine(penBase, _startPosX.Value + 115, _startPosY.Value + 4, _startPosX.Value + 108, _startPosY.Value + 40);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,263 +0,0 @@
|
||||
using HoistingCrane.Entities;
|
||||
|
||||
namespace HoistingCrane.Drawning
|
||||
{
|
||||
//В данном классе мы будем думать над полем игры, размерами персонажа, размерами объектов и т.д.
|
||||
public class DrawningTrackedVehicle
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Класс - сущность
|
||||
/// </summary>
|
||||
public EntityTrackedVehicle? EntityTrackedVehicle { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Стартовая позиция по х
|
||||
/// </summary>
|
||||
protected int? _startPosX;
|
||||
/// <summary>
|
||||
/// Стартовая позиция по у
|
||||
/// </summary>
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawingCarWidth = 83;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawingCarHeight = 63;
|
||||
|
||||
public int? GetPosX => _startPosX;
|
||||
public int? GetPosY => _startPosY;
|
||||
public int GetWidth => _drawingCarWidth;
|
||||
public int GetHeight => _drawingCarHeight;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор класса, который принимает параметры автомобиля(скорость, вес и цвет) и создает объект класса с данными параметрами
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет</param>
|
||||
public DrawningTrackedVehicle(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityTrackedVehicle = new EntityTrackedVehicle(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор, при вызове которого можем менять границы транспорта
|
||||
/// </summary>
|
||||
/// <param name="_drawingCarWidth">Ширина прорисовки автомобиля</param>
|
||||
/// <param name="_drawingCarHeight">Высота прорисовки автомобиля</param>
|
||||
protected DrawningTrackedVehicle(int _drawingCarWidth, int _drawingCarHeight) : this()
|
||||
{
|
||||
this._drawingCarWidth = _drawingCarWidth;
|
||||
this._drawingCarHeight = _drawingCarHeight;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Приватный конструктор, который делает значения границ окна = null и стартовую позицию = null
|
||||
/// </summary>
|
||||
private DrawningTrackedVehicle()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Метод отрисовки игрового поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns></returns>
|
||||
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена ✔
|
||||
|
||||
if (_drawingCarHeight > height || _drawingCarWidth > width)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_pictureHeight = height;
|
||||
_pictureWidth = width;
|
||||
|
||||
if (_startPosX.HasValue && _startPosX.Value + _drawingCarWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawingCarWidth;
|
||||
}
|
||||
|
||||
if (_startPosY.HasValue && _startPosY.Value + _drawingCarHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawingCarHeight;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установим позицию игрока
|
||||
/// </summary>
|
||||
/// <param name="x">Координата по Х</param>
|
||||
/// <param name="y">Координата по У</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
//Если размеры были заданы, то присваиваем х и у, иначе выходим из метода
|
||||
|
||||
if (x < 0)
|
||||
x = -x;
|
||||
if (y < 0)
|
||||
y = -y;
|
||||
if (x + _drawingCarWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawingCarWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
}
|
||||
if (y + _drawingCarHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawingCarHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение машины
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
public bool MoveTransport(DirectionType direction) //Подключили модив\фикатор virtual для переопределения в дочернем классе
|
||||
{
|
||||
if (EntityTrackedVehicle == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityTrackedVehicle.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityTrackedVehicle.Step;
|
||||
}
|
||||
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityTrackedVehicle.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityTrackedVehicle.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
//вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + EntityTrackedVehicle.Step + _drawingCarWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityTrackedVehicle.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + EntityTrackedVehicle.Step + _drawingCarHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityTrackedVehicle.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
default: return false;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Метод отрисовки объекта
|
||||
/// </summary>
|
||||
/// <param name="gr"></param>
|
||||
public virtual void DrawTransport(Graphics gr)
|
||||
{
|
||||
if (EntityTrackedVehicle == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new Pen(Color.Black);
|
||||
|
||||
|
||||
//границы
|
||||
gr.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 25, 75, 20);
|
||||
gr.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 25, 25);
|
||||
gr.DrawRectangle(pen, _startPosX.Value + 4, _startPosY.Value + 4, 17, 17);
|
||||
gr.DrawRectangle(pen, _startPosX.Value + 52, _startPosY.Value + 7, 6, 18);
|
||||
gr.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 45, 20, 20);
|
||||
gr.DrawEllipse(pen, _startPosX.Value + 63, _startPosY.Value + 45, 20, 20);
|
||||
gr.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 45, 68, 20);
|
||||
gr.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 46, 18, 18);
|
||||
gr.DrawEllipse(pen, _startPosX.Value + 62, _startPosY.Value + 46, 18, 18);
|
||||
gr.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 53, 10, 10);
|
||||
gr.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 53, 10, 10);
|
||||
gr.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 53, 10, 10);
|
||||
gr.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 45, 4, 6);
|
||||
gr.DrawRectangle(pen, _startPosX.Value + 45, _startPosY.Value + 45, 4, 6);
|
||||
|
||||
//корпус
|
||||
Brush br = new SolidBrush(EntityTrackedVehicle.BodyColor);
|
||||
gr.FillRectangle(br, _startPosX.Value, _startPosY.Value + 25, 75, 25);
|
||||
gr.FillRectangle(br, _startPosX.Value, _startPosY.Value, 25, 25);
|
||||
|
||||
|
||||
//окно
|
||||
Brush brq = new SolidBrush(Color.AliceBlue);
|
||||
gr.FillRectangle(brq, _startPosX.Value + 4, _startPosY.Value + 4, 17, 17);
|
||||
|
||||
|
||||
//выхлопная труба
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
gr.FillRectangle(brBlack, _startPosX.Value + 52, _startPosY.Value + 7, 6, 18);
|
||||
|
||||
|
||||
//гусеница
|
||||
Brush brDarkGray = new SolidBrush(Color.DarkGray);
|
||||
gr.FillEllipse(brDarkGray, _startPosX.Value - 5, _startPosY.Value + 45, 20, 20);
|
||||
gr.FillEllipse(brDarkGray, _startPosX.Value + 63, _startPosY.Value + 45, 20, 20);
|
||||
gr.FillRectangle(brDarkGray, _startPosX.Value + 5, _startPosY.Value + 45, 68, 20);
|
||||
|
||||
gr.FillEllipse(brq, _startPosX.Value - 1, _startPosY.Value + 46, 18, 18);
|
||||
gr.FillEllipse(brq, _startPosX.Value + 62, _startPosY.Value + 46, 18, 18);
|
||||
gr.FillEllipse(brq, _startPosX.Value + 20, _startPosY.Value + 53, 10, 10);
|
||||
gr.FillEllipse(brq, _startPosX.Value + 35, _startPosY.Value + 53, 10, 10);
|
||||
gr.FillEllipse(brq, _startPosX.Value + 50, _startPosY.Value + 53, 10, 10);
|
||||
gr.FillRectangle(brq, _startPosX.Value + 30, _startPosY.Value + 45, 4, 6);
|
||||
gr.FillRectangle(brq, _startPosX.Value + 45, _startPosY.Value + 45, 4, 6);
|
||||
}
|
||||
}
|
||||
}
|
278
HoistingCrane/HoistingCrane/DrawningHoistingCrane.cs
Normal file
278
HoistingCrane/HoistingCrane/DrawningHoistingCrane.cs
Normal file
@ -0,0 +1,278 @@
|
||||
|
||||
namespace HoistingCrane;
|
||||
|
||||
//В данном классе мы будем думать над полем игры, размерами персонажа, размерами объектов и т.д.
|
||||
public class DrawningHoistingCrane
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс - сущность
|
||||
/// </summary>
|
||||
public EntityHoistingCrane? EntityHoistingCrane { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Стартовая позиция по х
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
/// <summary>
|
||||
/// Стартовая позиция по у
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawingCarWidth = 115;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawingCarHeight = 63;
|
||||
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool counterweight, bool platform)
|
||||
{
|
||||
EntityHoistingCrane = new EntityHoistingCrane();
|
||||
EntityHoistingCrane.Init(speed, weight, bodyColor, additionalColor, counterweight, platform);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Метод отрисовки игрового поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns></returns>
|
||||
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена ✔
|
||||
|
||||
if (_drawingCarHeight > height || _drawingCarWidth > width)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_pictureHeight = height;
|
||||
_pictureWidth = width;
|
||||
|
||||
if(_startPosX.HasValue && (_startPosX.Value + _drawingCarWidth > _pictureWidth))
|
||||
{
|
||||
_startPosX =_pictureWidth - _drawingCarWidth;
|
||||
}
|
||||
|
||||
if(_startPosY.HasValue && (_startPosY.Value + _drawingCarHeight > _pictureHeight))
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawingCarHeight;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Установим позицию игрока
|
||||
/// </summary>
|
||||
/// <param name="x">Координата по Х</param>
|
||||
/// <param name="y">Координата по У</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
//Если размеры были заданы, то присваиваем х и у, иначе выходим из метода
|
||||
|
||||
if (x < 0)
|
||||
x = -x;
|
||||
if (y < 0)
|
||||
y = -y;
|
||||
if(x + _drawingCarWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawingCarWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
}
|
||||
if (y + _drawingCarHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawingCarHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение машины
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityHoistingCrane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityHoistingCrane.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityHoistingCrane.Step;
|
||||
}
|
||||
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityHoistingCrane.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityHoistingCrane.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
//вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + EntityHoistingCrane.Step + _drawingCarWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityHoistingCrane.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + EntityHoistingCrane.Step + _drawingCarHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityHoistingCrane.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
default: return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Метод отрисовки объекта
|
||||
/// </summary>
|
||||
/// <param name="gr"></param>
|
||||
public void DrawTransport(Graphics gr)
|
||||
{
|
||||
if (EntityHoistingCrane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new Pen(Color.Black);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//границы
|
||||
gr.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 25, 75, 20);
|
||||
gr.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 25, 25);
|
||||
gr.DrawRectangle(pen, _startPosX.Value + 4, _startPosY.Value + 4, 17, 17);
|
||||
gr.DrawRectangle(pen, _startPosX.Value + 52, _startPosY.Value + 7, 6, 18);
|
||||
gr.DrawEllipse(pen, _startPosX.Value - 5, _startPosY.Value + 45, 20, 20);
|
||||
gr.DrawEllipse(pen, _startPosX.Value + 63, _startPosY.Value + 45, 20, 20);
|
||||
gr.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 45, 68, 20);
|
||||
gr.DrawEllipse(pen, _startPosX.Value - 1, _startPosY.Value + 46, 18, 18);
|
||||
gr.DrawEllipse(pen, _startPosX.Value + 62, _startPosY.Value + 46, 18, 18);
|
||||
gr.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 53, 10, 10);
|
||||
gr.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 53, 10, 10);
|
||||
gr.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 53, 10, 10);
|
||||
gr.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 45, 4, 6);
|
||||
gr.DrawRectangle(pen, _startPosX.Value + 45, _startPosY.Value + 45, 4, 6);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//корпус
|
||||
Brush br = new SolidBrush(EntityHoistingCrane.BodyColor);
|
||||
gr.FillRectangle(br, _startPosX.Value, _startPosY.Value + 25, 75, 25);
|
||||
gr.FillRectangle(br, _startPosX.Value, _startPosY.Value, 25, 25);
|
||||
|
||||
//кран
|
||||
Brush bb = new SolidBrush(EntityHoistingCrane.BodyColor);
|
||||
gr.FillRectangle(bb, _startPosX.Value + 65, _startPosY.Value, 7, 25);
|
||||
gr.FillRectangle(br, _startPosX.Value + 62, _startPosY.Value + 2, 45, 5);
|
||||
gr.DrawLine(pen, _startPosX.Value + 105, _startPosY.Value + 2, _startPosX.Value + 107, _startPosY.Value + 40);
|
||||
|
||||
|
||||
//окно
|
||||
Brush brq = new SolidBrush(EntityHoistingCrane.AdditionalColor);
|
||||
gr.FillRectangle(brq, _startPosX.Value + 4, _startPosY.Value + 4, 17, 17);
|
||||
|
||||
|
||||
|
||||
//выхлопная труба
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
gr.FillRectangle(brBlack, _startPosX.Value + 52, _startPosY.Value + 7, 6, 18);
|
||||
|
||||
|
||||
//гусеница
|
||||
Brush brDarkGray = new SolidBrush(Color.DarkGray);
|
||||
gr.FillEllipse(brDarkGray, _startPosX.Value - 5, _startPosY.Value + 45, 20, 20);
|
||||
gr.FillEllipse(brDarkGray, _startPosX.Value + 63, _startPosY.Value + 45, 20, 20);
|
||||
gr.FillRectangle(brDarkGray, _startPosX.Value + 5, _startPosY.Value + 45, 68, 20);
|
||||
|
||||
|
||||
gr.FillEllipse(brq, _startPosX.Value - 1, _startPosY.Value + 46, 18, 18);
|
||||
gr.FillEllipse(brq, _startPosX.Value + 62, _startPosY.Value + 46, 18, 18);
|
||||
gr.FillEllipse(brq, _startPosX.Value + 20, _startPosY.Value + 53, 10, 10);
|
||||
gr.FillEllipse(brq, _startPosX.Value + 35, _startPosY.Value + 53, 10, 10);
|
||||
gr.FillEllipse(brq, _startPosX.Value + 50, _startPosY.Value + 53, 10, 10);
|
||||
gr.FillRectangle(brq, _startPosX.Value + 30, _startPosY.Value + 45, 4, 6);
|
||||
gr.FillRectangle(brq, _startPosX.Value + 45, _startPosY.Value + 45, 4, 6);
|
||||
|
||||
//противовес
|
||||
if (EntityHoistingCrane.Counterweight)
|
||||
{
|
||||
Brush b = new SolidBrush(EntityHoistingCrane.AdditionalColor);
|
||||
gr.FillRectangle(b, _startPosX.Value + 68, _startPosY.Value + 5, 10, 10);
|
||||
}
|
||||
|
||||
|
||||
//Наличие спусковой платформы
|
||||
if (EntityHoistingCrane.Platform)
|
||||
{
|
||||
Pen n = new Pen(EntityHoistingCrane.AdditionalColor);
|
||||
gr.DrawRectangle(pen, _startPosX.Value + 101, _startPosY.Value + 40, 15, 5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,41 +0,0 @@
|
||||
namespace HoistingCrane.Entities;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Êëàññ-ñóùíîñòü (Ïîäúåìíûé êðàí) Êëàññ íàñëåäíèê
|
||||
/// </summary>
|
||||
public class EntityHoistingCrane : EntityTrackedVehicle
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Äîïîëíèòåëüíûé öâåò îáúåêòà
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Íàëè÷èå ïðîòèâîâåñà
|
||||
/// </summary>
|
||||
public bool Counterweight { get; protected set; }
|
||||
/// <summary>
|
||||
/// Íàëè÷èå ïëàòôîðìû
|
||||
/// </summary>
|
||||
public bool Platform { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ìåòîä çàäà÷è ïàðàìåòðîâ
|
||||
/// </summary>
|
||||
/// <param name="AdditionalColor">Äîï. öâåò</param>
|
||||
/// <param name="Counterweight">Ãðóç äëÿ ðàâíîâåñèÿ</param>
|
||||
/// <param name="Platform">Ïëàòôîðìà íà âåðåâêå</param>
|
||||
|
||||
|
||||
// Äîïîëíÿåò íåäîñòîþùèå ýëåìåíòû èç ðîä. êëàññà
|
||||
public EntityHoistingCrane(int Speed, int Weight, Color BodyColor, Color AdditionalColor, bool Counterweight, bool Platform) : base(Speed, Weight, BodyColor)
|
||||
{
|
||||
this.AdditionalColor = AdditionalColor;
|
||||
this.Counterweight = Counterweight;
|
||||
this.Platform = Platform;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
namespace HoistingCrane.Entities
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность (Гусеничная машина) Родительский класс
|
||||
/// </summary>
|
||||
public class EntityTrackedVehicle
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость, которой обладает объект
|
||||
/// </summary>
|
||||
public int Speed { get; protected set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Вес, которым обладает объект
|
||||
/// </summary>
|
||||
public double Weight { get; protected set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Основной цвет объекта
|
||||
/// </summary>
|
||||
public Color BodyColor { get; protected set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Шаг движения
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <param name="Speed">Скорость</param>
|
||||
/// <param name="Weight">Вес</param>
|
||||
/// <param name="BodyColor">Основной цвет</param>
|
||||
|
||||
public EntityTrackedVehicle(int Speed, double Weight, Color BodyColor)
|
||||
{
|
||||
this.Speed = Speed;
|
||||
this.Weight = Weight;
|
||||
this.BodyColor = BodyColor;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
63
HoistingCrane/HoistingCrane/EntityHoistingCrane.cs
Normal file
63
HoistingCrane/HoistingCrane/EntityHoistingCrane.cs
Normal file
@ -0,0 +1,63 @@
|
||||
namespace HoistingCrane;
|
||||
|
||||
|
||||
|
||||
public class EntityHoistingCrane
|
||||
{
|
||||
/// <summary>
|
||||
/// Ñêîðîñòü, êîòîðîé îáëàäàåò îáúåêò
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Âåñ, êîòîðûì îáëàäàåò îáúåêò
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Îñíîâíîé öâåò îáúåêòà
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Äîïîëíèòåëüíûé öâåò îáúåêòà
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Íàëè÷èå ïðîòèâîâåñà
|
||||
/// </summary>
|
||||
public bool Counterweight { get; private set; }
|
||||
/// <summary>
|
||||
/// Íàëè÷èå ïëàòôîðìû
|
||||
/// </summary>
|
||||
public bool Platform{ get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Øàã äâèæåíèÿ
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Ìåòîä çàäà÷è ïàðàìåòðîâ
|
||||
/// </summary>
|
||||
/// <param name="Speed">Ñêîðîñòü</param>
|
||||
/// <param name="Weight">Âåñ</param>
|
||||
/// <param name="BodyColor">Îñíîâíîé öâåò</param>
|
||||
/// <param name="AdditionalColor">Äîï. öâåò</param>
|
||||
|
||||
|
||||
|
||||
|
||||
public void Init(int Speed, double Weight, Color BodyColor, Color AdditionalColor, bool Counterweight, bool Platform)
|
||||
{
|
||||
this.Speed = Speed;
|
||||
this.Weight = Weight;
|
||||
this.BodyColor = BodyColor;
|
||||
this.AdditionalColor = AdditionalColor;
|
||||
this.Counterweight = Counterweight;
|
||||
this.Platform = Platform;
|
||||
}
|
||||
|
||||
}
|
@ -9,6 +9,7 @@ namespace HoistingCrane
|
||||
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
@ -18,17 +19,17 @@ namespace HoistingCrane
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxHoistingCrane = new PictureBox();
|
||||
buttonCreateHoistingCrane = new Button();
|
||||
buttonCreate = new Button();
|
||||
ButtonLeft = new Button();
|
||||
ButtonRight = new Button();
|
||||
ButtonUp = new Button();
|
||||
ButtonDown = new Button();
|
||||
buttonCreateTrackedVehicle = new Button();
|
||||
comboStrategy = new ComboBox();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxHoistingCrane).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -41,23 +42,23 @@ namespace HoistingCrane
|
||||
pictureBoxHoistingCrane.TabIndex = 0;
|
||||
pictureBoxHoistingCrane.TabStop = false;
|
||||
//
|
||||
// buttonCreateHoistingCrane
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreateHoistingCrane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateHoistingCrane.Location = new Point(0, 492);
|
||||
buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane";
|
||||
buttonCreateHoistingCrane.Size = new Size(188, 23);
|
||||
buttonCreateHoistingCrane.TabIndex = 1;
|
||||
buttonCreateHoistingCrane.Text = "Создать подъемный кран";
|
||||
buttonCreateHoistingCrane.UseVisualStyleBackColor = true;
|
||||
buttonCreateHoistingCrane.Click += ButtonCreateHoistingCrane_Click;
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(0, 492);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(75, 23);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreate_Click;
|
||||
//
|
||||
// ButtonLeft
|
||||
//
|
||||
ButtonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
ButtonLeft.BackgroundImage = Properties.Resources.left_arrow;
|
||||
ButtonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ButtonLeft.Location = new Point(642, 475);
|
||||
ButtonLeft.Location = new Point(118, 404);
|
||||
ButtonLeft.Name = "ButtonLeft";
|
||||
ButtonLeft.Size = new Size(40, 40);
|
||||
ButtonLeft.TabIndex = 2;
|
||||
@ -69,7 +70,7 @@ namespace HoistingCrane
|
||||
ButtonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
ButtonRight.BackgroundImage = Properties.Resources.right_arrow;
|
||||
ButtonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ButtonRight.Location = new Point(734, 475);
|
||||
ButtonRight.Location = new Point(207, 404);
|
||||
ButtonRight.Name = "ButtonRight";
|
||||
ButtonRight.Size = new Size(40, 40);
|
||||
ButtonRight.TabIndex = 3;
|
||||
@ -81,7 +82,7 @@ namespace HoistingCrane
|
||||
ButtonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
ButtonUp.BackgroundImage = Properties.Resources.up_arrow;
|
||||
ButtonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ButtonUp.Location = new Point(688, 429);
|
||||
ButtonUp.Location = new Point(164, 367);
|
||||
ButtonUp.Name = "ButtonUp";
|
||||
ButtonUp.Size = new Size(40, 40);
|
||||
ButtonUp.TabIndex = 4;
|
||||
@ -93,57 +94,23 @@ namespace HoistingCrane
|
||||
ButtonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
ButtonDown.BackgroundImage = Properties.Resources.arrow_down_sign_to_navigate;
|
||||
ButtonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ButtonDown.Location = new Point(688, 475);
|
||||
ButtonDown.Location = new Point(164, 440);
|
||||
ButtonDown.Name = "ButtonDown";
|
||||
ButtonDown.Size = new Size(40, 40);
|
||||
ButtonDown.TabIndex = 5;
|
||||
ButtonDown.UseVisualStyleBackColor = true;
|
||||
ButtonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateTrackedVehicle
|
||||
//
|
||||
buttonCreateTrackedVehicle.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateTrackedVehicle.Location = new Point(203, 492);
|
||||
buttonCreateTrackedVehicle.Name = "buttonCreateTrackedVehicle";
|
||||
buttonCreateTrackedVehicle.Size = new Size(194, 23);
|
||||
buttonCreateTrackedVehicle.TabIndex = 6;
|
||||
buttonCreateTrackedVehicle.Text = "Создать гусеничную машину";
|
||||
buttonCreateTrackedVehicle.UseVisualStyleBackColor = true;
|
||||
buttonCreateTrackedVehicle.Click += buttonCreateTrackedVehicle_Click;
|
||||
//
|
||||
// comboStrategy
|
||||
//
|
||||
comboStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboStrategy.FormattingEnabled = true;
|
||||
comboStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
|
||||
comboStrategy.Location = new Point(697, 42);
|
||||
comboStrategy.Name = "comboStrategy";
|
||||
comboStrategy.Size = new Size(121, 23);
|
||||
comboStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStrategyStep
|
||||
//
|
||||
buttonStrategyStep.Location = new Point(743, 71);
|
||||
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||
buttonStrategyStep.Size = new Size(75, 23);
|
||||
buttonStrategyStep.TabIndex = 8;
|
||||
buttonStrategyStep.Text = "Шаг";
|
||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||
buttonStrategyStep.Click += ButtonStrategyStep_Click;
|
||||
//
|
||||
// FormHoistingCrane
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(818, 515);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboStrategy);
|
||||
Controls.Add(buttonCreateTrackedVehicle);
|
||||
Controls.Add(ButtonDown);
|
||||
Controls.Add(ButtonUp);
|
||||
Controls.Add(ButtonRight);
|
||||
Controls.Add(ButtonLeft);
|
||||
Controls.Add(buttonCreateHoistingCrane);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxHoistingCrane);
|
||||
Name = "FormHoistingCrane";
|
||||
Text = "Подъемный кран";
|
||||
@ -154,13 +121,10 @@ namespace HoistingCrane
|
||||
// #endregion
|
||||
|
||||
private PictureBox pictureBoxHoistingCrane;
|
||||
private Button buttonCreateHoistingCrane;
|
||||
private Button buttonCreate;
|
||||
private Button ButtonLeft;
|
||||
private Button ButtonRight;
|
||||
private Button ButtonUp;
|
||||
private Button ButtonDown;
|
||||
private Button buttonCreateTrackedVehicle;
|
||||
private ComboBox comboStrategy;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
||||
}
|
@ -1,94 +1,60 @@
|
||||
using HoistingCrane.Drawning;
|
||||
using HoistingCrane.MovementStrategy;
|
||||
|
||||
namespace HoistingCrane
|
||||
namespace HoistingCrane
|
||||
{
|
||||
public partial class FormHoistingCrane : Form
|
||||
{
|
||||
|
||||
private DrawningTrackedVehicle? _drawning;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
private DrawningHoistingCrane? _drawningHoistingCrane;
|
||||
|
||||
public FormHoistingCrane()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawning?.DrawTransport(gr);
|
||||
_drawningHoistingCrane?.DrawTransport(gr);
|
||||
pictureBoxHoistingCrane.Image = bmp;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Создать подъемный кран
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateHoistingCrane_Click(object sender, EventArgs e)
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateObject(nameof(DrawningHoistingCrane));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Создать бронебойную машину
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreateTrackedVehicle_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateObject(nameof(DrawningTrackedVehicle));
|
||||
}
|
||||
|
||||
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random rand = new();
|
||||
switch (type)
|
||||
{
|
||||
|
||||
case nameof(DrawningHoistingCrane):
|
||||
_drawning = new DrawningHoistingCrane(rand.Next(100, 300), rand.Next(1000, 3000), Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)),
|
||||
Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)), true, true);
|
||||
break;
|
||||
|
||||
case nameof(DrawningTrackedVehicle):
|
||||
_drawning = new DrawningTrackedVehicle(rand.Next(100, 300), rand.Next(1000, 3000), Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
|
||||
}
|
||||
_drawning.SetPictureSize(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
|
||||
_drawning.SetPosition(rand.Next(0, 100), rand.Next(0, 100));
|
||||
|
||||
comboStrategy.Enabled = true;
|
||||
_drawningHoistingCrane = new DrawningHoistingCrane();
|
||||
_drawningHoistingCrane.Init(
|
||||
rand.Next(100, 300),
|
||||
rand.Next(1000, 3000),
|
||||
Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)),
|
||||
Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)),
|
||||
Convert.ToBoolean(rand.Next(0,2)),
|
||||
Convert.ToBoolean(rand.Next(0,2))
|
||||
);
|
||||
_drawningHoistingCrane.SetPictureSize(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
|
||||
_drawningHoistingCrane.SetPosition(rand.Next(0, 100), rand.Next(0, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawning == null) { return; }
|
||||
if (_drawningHoistingCrane == null) { return; }
|
||||
String name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
switch (name)
|
||||
{
|
||||
case "ButtonUp":
|
||||
result = _drawning.MoveTransport(DirectionType.Up);
|
||||
result = _drawningHoistingCrane.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "ButtonDown":
|
||||
result = _drawning.MoveTransport(DirectionType.Down);
|
||||
result = _drawningHoistingCrane.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "ButtonRight":
|
||||
result = _drawning.MoveTransport(DirectionType.Right);
|
||||
result = _drawningHoistingCrane.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
case "ButtonLeft":
|
||||
result = _drawning.MoveTransport(DirectionType.Left);
|
||||
result = _drawningHoistingCrane.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
@ -99,42 +65,6 @@ namespace HoistingCrane
|
||||
|
||||
}
|
||||
|
||||
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawning == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new MoveableCar(_drawning), pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
|
||||
}
|
||||
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
comboStrategy.Enabled = false;
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_abstractStrategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,139 +0,0 @@
|
||||
namespace HoistingCrane.MovementStrategy
|
||||
{
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Перемещаемый объект
|
||||
/// </summary>
|
||||
private IMoveableObjects? _moveableObject;
|
||||
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина поля
|
||||
/// </summary>
|
||||
protected int FieldWidth { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Высота поля
|
||||
/// </summary>
|
||||
protected int FieldHeight { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public StrategyStatus GetStatus() { return _state; }
|
||||
|
||||
/// <summary>
|
||||
/// Установка данных
|
||||
/// </summary>
|
||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
public void SetData(IMoveableObjects moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = StrategyStatus.NotInit;
|
||||
return;
|
||||
}
|
||||
|
||||
_state = StrategyStatus.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsTargetDestination())
|
||||
{
|
||||
_state = StrategyStatus.Finish;
|
||||
return;
|
||||
}
|
||||
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveRight() => MoveTo(MovementDirection.Right);
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение вверх
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveUp() => MoveTo(MovementDirection.Up);
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение вниз
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveDown() => MoveTo(MovementDirection.Down);
|
||||
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
|
||||
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение к цели
|
||||
/// </summary>
|
||||
protected abstract void MoveToTarget();
|
||||
|
||||
/// <summary>
|
||||
/// Достигнута ли цель
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract bool IsTargetDestination();
|
||||
|
||||
/// <summary>
|
||||
/// Попытка перемещения в требуемом направлении
|
||||
/// </summary>
|
||||
/// <param name="movementDirection">Направление</param>
|
||||
/// <returns>Результат попытки (true - удалось, false - неудача)</returns>
|
||||
private bool MoveTo(MovementDirection movementDirection)
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
namespace HoistingCrane.MovementStrategy
|
||||
{
|
||||
public interface IMoveableObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение позиции объекта
|
||||
/// </summary>
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получение шага объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Попытка переместить объект в указанном направлении
|
||||
/// </summary>
|
||||
/// <param name="direction">направление</param>
|
||||
/// <returns></returns>
|
||||
bool TryMoveObject(MovementDirection direction);
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
namespace HoistingCrane.MovementStrategy
|
||||
{
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestination()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int diffX = objParams.RightBorder - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
|
||||
int diffY = objParams.DownBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
namespace HoistingCrane.MovementStrategy
|
||||
{
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestination()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
|
||||
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
using HoistingCrane.Drawning;
|
||||
|
||||
namespace HoistingCrane.MovementStrategy
|
||||
{
|
||||
public class MoveableCar : IMoveableObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект класса DrawningAirplane или его наследника
|
||||
/// </summary>
|
||||
private readonly DrawningTrackedVehicle? drawningTrackedVehicle = null;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="airplane">Объект класса DrawningAirplane</param>
|
||||
public MoveableCar(DrawningTrackedVehicle drawningTrackedVehicle)
|
||||
{
|
||||
this.drawningTrackedVehicle = drawningTrackedVehicle;
|
||||
}
|
||||
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (drawningTrackedVehicle == null || drawningTrackedVehicle.EntityTrackedVehicle == null || !drawningTrackedVehicle.GetPosX.HasValue || !drawningTrackedVehicle.GetPosY.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(drawningTrackedVehicle.GetPosX.Value, drawningTrackedVehicle.GetPosY.Value, drawningTrackedVehicle.GetWidth, drawningTrackedVehicle.GetHeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int GetStep => (int)(drawningTrackedVehicle?.EntityTrackedVehicle?.Step ?? 0);
|
||||
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if (drawningTrackedVehicle == null || drawningTrackedVehicle.EntityTrackedVehicle == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return drawningTrackedVehicle.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конвертация из MovementDirection в DirectionType
|
||||
/// </summary>
|
||||
/// <param name="direction">MovementDirection</param>
|
||||
/// <returns>DirectionType</returns>
|
||||
private static DirectionType GetDirectionType(MovementDirection direction)
|
||||
{
|
||||
return direction switch
|
||||
{
|
||||
MovementDirection.Left => DirectionType.Left,
|
||||
MovementDirection.Right => DirectionType.Right,
|
||||
MovementDirection.Up => DirectionType.Up,
|
||||
MovementDirection.Down => DirectionType.Down,
|
||||
_ => DirectionType.Unknow,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
namespace HoistingCrane.MovementStrategy
|
||||
{
|
||||
public enum MovementDirection
|
||||
{
|
||||
//Перечислим основные траектории движния нашего автомобиля. Сразу же зададим значения.
|
||||
/// <summary>
|
||||
/// Вверх1
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
namespace HoistingCrane.MovementStrategy
|
||||
{
|
||||
public class ObjectParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Начальная координата х
|
||||
/// </summary>
|
||||
private readonly int _x;
|
||||
|
||||
/// <summary>
|
||||
/// Начальная координата y
|
||||
/// </summary>
|
||||
private readonly int _y;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
private readonly int _width;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
private readonly int _height;
|
||||
|
||||
/// <summary>
|
||||
/// Левая граница
|
||||
/// </summary>
|
||||
public int LeftBorder => _x;
|
||||
|
||||
/// <summary>
|
||||
/// Правая граница
|
||||
/// </summary>
|
||||
public int RightBorder => _x + _width;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя граница
|
||||
/// </summary>
|
||||
public int TopBorder => _y;
|
||||
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
public int DownBorder => _y + _height;
|
||||
|
||||
/// <summary>
|
||||
/// Центральная координата по горизонтали
|
||||
/// </summary>
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
|
||||
/// <summary>
|
||||
/// Центральная координата по вертикали
|
||||
/// </summary>
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="_x">Координата по х</param>
|
||||
/// <param name="_y">Координата по у</param>
|
||||
/// <param name="_width">Ширина объекта</param>
|
||||
/// <param name="_height">Высота объекта</param>
|
||||
public ObjectParameters(int _x, int _y, int _width, int _height)
|
||||
{
|
||||
this._x = _x;
|
||||
this._y = _y;
|
||||
this._width = _width;
|
||||
this._height = _height;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
namespace HoistingCrane.MovementStrategy
|
||||
{
|
||||
public enum StrategyStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Всё готово к началу
|
||||
/// </summary>
|
||||
NotInit,
|
||||
|
||||
/// <summary>
|
||||
/// Выполняется
|
||||
/// </summary>
|
||||
InProgress,
|
||||
|
||||
/// <summary>
|
||||
/// Завершено
|
||||
/// </summary>
|
||||
Finish
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user