Добавление родителей и ввод конструкторов
This commit is contained in:
parent
228712e3ce
commit
2ebca2eedd
@ -1,302 +0,0 @@
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Excavator;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningExcavator
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityExcavator? EntityExcavator { 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 _drawningExcavatorWidth = 145;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки экскаватора
|
||||
/// </summary>
|
||||
private readonly int _drawningExcavatorHeight = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="supports">Признак наличия обвеса</param>
|
||||
/// <param name="bucket">Признак наличия антикрыла</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor,bool supports, bool bucket)
|
||||
{
|
||||
EntityExcavator = new EntityExcavator();
|
||||
EntityExcavator.Init(speed, weight, bodyColor, additionalColor, supports, bucket);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
if (width > _drawningExcavatorWidth && height > _drawningExcavatorHeight)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX != null && _startPosY != null)
|
||||
{
|
||||
if (_startPosX.Value + _drawningExcavatorWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawningExcavatorWidth;
|
||||
}
|
||||
if (_startPosY.Value + _drawningExcavatorHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawningExcavatorHeight;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
if (_drawningExcavatorWidth + _startPosX > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawningExcavatorWidth;
|
||||
}
|
||||
if (_drawningExcavatorHeight + _startPosY > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawningExcavatorHeight;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityExcavator == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityExcavator.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityExcavator.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityExcavator.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityExcavator.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _drawningExcavatorWidth + EntityExcavator.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityExcavator.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _drawningExcavatorHeight + EntityExcavator.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityExcavator.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityExcavator == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityExcavator.AdditionalColor);
|
||||
|
||||
// Ковш
|
||||
if(EntityExcavator.Bucket)
|
||||
{
|
||||
|
||||
Point[] pointBucket1 =
|
||||
{
|
||||
new Point(_startPosX.Value + 90, _startPosY.Value + 50),
|
||||
new Point(_startPosX.Value + 90, _startPosY.Value),
|
||||
new Point(_startPosX.Value + 135, _startPosY.Value),
|
||||
new Point(_startPosX.Value + 135, _startPosY.Value + 30),
|
||||
new Point(_startPosX.Value + 125, _startPosY.Value + 30),
|
||||
new Point(_startPosX.Value + 125, _startPosY.Value + 10),
|
||||
new Point(_startPosX.Value + 105, _startPosY.Value + 10),
|
||||
new Point(_startPosX.Value + 105, _startPosY.Value + 45),
|
||||
new Point(_startPosX.Value + 100, _startPosY.Value + 50),
|
||||
new Point(_startPosX.Value + 90, _startPosY.Value + 50),
|
||||
};
|
||||
g.FillPolygon(additionalBrush, pointBucket1);
|
||||
g.DrawPolygon(pen, pointBucket1);
|
||||
|
||||
Point[] pointBucket2 =
|
||||
{
|
||||
new Point(_startPosX.Value + 125, _startPosY.Value + 30),
|
||||
new Point(_startPosX.Value + 135, _startPosY.Value+ 30),
|
||||
new Point(_startPosX.Value + 145, _startPosY.Value + 40),
|
||||
new Point(_startPosX.Value + 145, _startPosY.Value + 60),
|
||||
new Point(_startPosX.Value + 140, _startPosY.Value + 70),
|
||||
new Point(_startPosX.Value + 120, _startPosY.Value + 70),
|
||||
new Point(_startPosX.Value + 125, _startPosY.Value + 60),
|
||||
new Point(_startPosX.Value + 125, _startPosY.Value + 30),
|
||||
};
|
||||
Brush br1 = new SolidBrush(Color.FromArgb(100, 100, 100));
|
||||
g.FillPolygon(br1, pointBucket2);
|
||||
g.DrawPolygon(pen, pointBucket2);
|
||||
}
|
||||
|
||||
// Гусеницы
|
||||
Brush brGrey = new SolidBrush(Color.FromArgb(100, 100, 100));
|
||||
Brush br = new SolidBrush(EntityExcavator.BodyColor);
|
||||
|
||||
g.FillEllipse(brGrey, _startPosX.Value + 30, _startPosY.Value + 75, 25, 25);
|
||||
g.FillEllipse(brGrey, _startPosX.Value + 75, _startPosY.Value + 75, 25, 25);
|
||||
g.FillRectangle(brGrey, _startPosX.Value + 40, _startPosY.Value + 75, 50, 25);
|
||||
|
||||
Rectangle rect1 = new Rectangle(_startPosX.Value + 30, _startPosY.Value + 75, 25, 25);
|
||||
g.DrawArc(pen, rect1, 90, 180);
|
||||
Rectangle rect2 = new Rectangle(_startPosX.Value + 75, _startPosY.Value + 75, 25, 25);
|
||||
g.DrawArc(pen, rect2, 270, 180);
|
||||
g.DrawLine(pen, _startPosX.Value + 40, _startPosY.Value + 100, _startPosX.Value + 90, _startPosY.Value + 100);
|
||||
|
||||
|
||||
g.FillEllipse(br, _startPosX.Value + 33, _startPosY.Value + 78, 18, 18);
|
||||
g.FillEllipse(br, _startPosX.Value + 78, _startPosY.Value + 78, 18, 18);
|
||||
g.FillEllipse(br, _startPosX.Value + 51, _startPosY.Value + 89, 7, 7);
|
||||
g.FillEllipse(br, _startPosX.Value + 61, _startPosY.Value + 89, 7, 7);
|
||||
g.FillEllipse(br, _startPosX.Value + 71, _startPosY.Value + 89, 7, 7);
|
||||
g.FillEllipse(br, _startPosX.Value + 57, _startPosY.Value + 81, 4, 4);
|
||||
g.FillEllipse(br, _startPosX.Value + 69, _startPosY.Value + 81, 4, 4);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value + 33, _startPosY.Value + 78, 18, 18);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 78, _startPosY.Value + 78, 18, 18);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 51, _startPosY.Value + 89, 7, 7);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 61, _startPosY.Value + 89, 7, 7);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 71, _startPosY.Value + 89, 7, 7);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 57, _startPosY.Value + 81, 4, 4);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 69, _startPosY.Value + 81, 4, 4);
|
||||
|
||||
// Корпус
|
||||
Point[] pointBody1 =
|
||||
{
|
||||
new Point(_startPosX.Value + 30, _startPosY.Value + 75),
|
||||
new Point(_startPosX.Value + 30, _startPosY.Value + 50),
|
||||
new Point(_startPosX.Value + 70, _startPosY.Value + 50),
|
||||
new Point(_startPosX.Value + 70, _startPosY.Value + 20),
|
||||
new Point(_startPosX.Value + 100, _startPosY.Value + 20),
|
||||
new Point(_startPosX.Value + 100, _startPosY.Value + 75),
|
||||
new Point(_startPosX.Value + 30, _startPosY.Value + 75),
|
||||
};
|
||||
g.FillPolygon(br, pointBody1);
|
||||
g.DrawPolygon(pen, pointBody1);
|
||||
g.FillRectangle(br, _startPosX.Value + 40, _startPosY.Value + 25, 10, 25);
|
||||
g.FillRectangle(br, _startPosX.Value + 40, _startPosY.Value + 25, 10, 25);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 25, 10, 25);
|
||||
|
||||
// Окно
|
||||
Brush brLBlue = new SolidBrush(Color.LightBlue);
|
||||
|
||||
g.FillRectangle(brLBlue, _startPosX.Value + 72, _startPosY.Value + 22, 26, 26);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 72, _startPosY.Value + 22, 26, 26);
|
||||
|
||||
// Опоры
|
||||
if (EntityExcavator.Supports)
|
||||
{
|
||||
Point[] pointSupport1 =
|
||||
{
|
||||
new Point(_startPosX.Value + 10, _startPosY.Value + 100),
|
||||
new Point(_startPosX.Value + 20, _startPosY.Value + 100),
|
||||
new Point(_startPosX.Value + 50, _startPosY.Value + 70),
|
||||
new Point(_startPosX.Value + 50, _startPosY.Value + 60),
|
||||
new Point(_startPosX.Value + 30, _startPosY.Value + 60),
|
||||
new Point(_startPosX.Value + 10, _startPosY.Value + 100),
|
||||
};
|
||||
g.FillPolygon(additionalBrush, pointSupport1);
|
||||
g.DrawPolygon(pen, pointSupport1);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value + 95, 30, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 95, 30, 5);
|
||||
|
||||
Point[] pointSupport2 =
|
||||
{
|
||||
new Point(_startPosX.Value + 120, _startPosY.Value + 100),
|
||||
new Point(_startPosX.Value + 110, _startPosY.Value + 100),
|
||||
new Point(_startPosX.Value + 80, _startPosY.Value + 70),
|
||||
new Point(_startPosX.Value + 80, _startPosY.Value + 60),
|
||||
new Point(_startPosX.Value + 100, _startPosY.Value + 60),
|
||||
new Point(_startPosX.Value + 120, _startPosY.Value + 100),
|
||||
};
|
||||
g.FillPolygon(additionalBrush, pointSupport2);
|
||||
g.DrawPolygon(pen, pointSupport2);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 100, _startPosY.Value + 95, 30, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 95, 30, 5);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
110
Excavator/Excavator/Drawnings/DrawningExcavator.cs
Normal file
110
Excavator/Excavator/Drawnings/DrawningExcavator.cs
Normal file
@ -0,0 +1,110 @@
|
||||
using System.Net.Sockets;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Excavator.Drawnings;
|
||||
using Excavator.Entities;
|
||||
|
||||
namespace Excavator.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningExcavator : DrawningSimpleExcavator
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="supports">Признак наличия обвеса</param>
|
||||
/// <param name="bucket">Признак наличия антикрыла</param>
|
||||
public DrawningExcavator(int speed, double weight, Color bodyColor, Color additionalColor,bool supports, bool bucket) : base(145, 100)
|
||||
{
|
||||
EntitySimpleExcavator = new EntityExcavator(speed, weight, bodyColor, additionalColor, supports, bucket);
|
||||
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntitySimpleExcavator == null || EntitySimpleExcavator is not EntityExcavator excavator || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(excavator.AdditionalColor);
|
||||
|
||||
// Ковш
|
||||
if (excavator.Bucket)
|
||||
{
|
||||
|
||||
Point[] pointBucket1 =
|
||||
{
|
||||
new Point(_startPosX.Value + 90, _startPosY.Value + 50),
|
||||
new Point(_startPosX.Value + 90, _startPosY.Value),
|
||||
new Point(_startPosX.Value + 135, _startPosY.Value),
|
||||
new Point(_startPosX.Value + 135, _startPosY.Value + 30),
|
||||
new Point(_startPosX.Value + 125, _startPosY.Value + 30),
|
||||
new Point(_startPosX.Value + 125, _startPosY.Value + 10),
|
||||
new Point(_startPosX.Value + 105, _startPosY.Value + 10),
|
||||
new Point(_startPosX.Value + 105, _startPosY.Value + 45),
|
||||
new Point(_startPosX.Value + 100, _startPosY.Value + 50),
|
||||
new Point(_startPosX.Value + 90, _startPosY.Value + 50),
|
||||
};
|
||||
g.FillPolygon(additionalBrush, pointBucket1);
|
||||
g.DrawPolygon(pen, pointBucket1);
|
||||
|
||||
Point[] pointBucket2 =
|
||||
{
|
||||
new Point(_startPosX.Value + 125, _startPosY.Value + 30),
|
||||
new Point(_startPosX.Value + 135, _startPosY.Value+ 30),
|
||||
new Point(_startPosX.Value + 145, _startPosY.Value + 40),
|
||||
new Point(_startPosX.Value + 145, _startPosY.Value + 60),
|
||||
new Point(_startPosX.Value + 140, _startPosY.Value + 70),
|
||||
new Point(_startPosX.Value + 120, _startPosY.Value + 70),
|
||||
new Point(_startPosX.Value + 125, _startPosY.Value + 60),
|
||||
new Point(_startPosX.Value + 125, _startPosY.Value + 30),
|
||||
};
|
||||
Brush br1 = new SolidBrush(Color.FromArgb(100, 100, 100));
|
||||
g.FillPolygon(br1, pointBucket2);
|
||||
g.DrawPolygon(pen, pointBucket2);
|
||||
}
|
||||
// Опоры
|
||||
if (excavator.Supports)
|
||||
{
|
||||
Point[] pointSupport1 =
|
||||
{
|
||||
new Point(_startPosX.Value + 10, _startPosY.Value + 100),
|
||||
new Point(_startPosX.Value + 20, _startPosY.Value + 100),
|
||||
new Point(_startPosX.Value + 50, _startPosY.Value + 70),
|
||||
new Point(_startPosX.Value + 50, _startPosY.Value + 60),
|
||||
new Point(_startPosX.Value + 30, _startPosY.Value + 60),
|
||||
new Point(_startPosX.Value + 10, _startPosY.Value + 100),
|
||||
};
|
||||
g.FillPolygon(additionalBrush, pointSupport1);
|
||||
g.DrawPolygon(pen, pointSupport1);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value + 95, 30, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 95, 30, 5);
|
||||
|
||||
Point[] pointSupport2 =
|
||||
{
|
||||
new Point(_startPosX.Value + 120, _startPosY.Value + 100),
|
||||
new Point(_startPosX.Value + 110, _startPosY.Value + 100),
|
||||
new Point(_startPosX.Value + 80, _startPosY.Value + 70),
|
||||
new Point(_startPosX.Value + 80, _startPosY.Value + 60),
|
||||
new Point(_startPosX.Value + 100, _startPosY.Value + 60),
|
||||
new Point(_startPosX.Value + 120, _startPosY.Value + 100),
|
||||
};
|
||||
g.FillPolygon(additionalBrush, pointSupport2);
|
||||
g.DrawPolygon(pen, pointSupport2);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 100, _startPosY.Value + 95, 30, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 95, 30, 5);
|
||||
}
|
||||
_startPosY += 20;
|
||||
_startPosX += 30;
|
||||
base.DrawTransport(g);
|
||||
_startPosY -= 20;
|
||||
_startPosX -= 30;
|
||||
}
|
||||
}
|
264
Excavator/Excavator/Drawnings/DrawningSimpleExcavator.cs
Normal file
264
Excavator/Excavator/Drawnings/DrawningSimpleExcavator.cs
Normal file
@ -0,0 +1,264 @@
|
||||
using Excavator.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Excavator.Drawnings;
|
||||
|
||||
public class DrawningSimpleExcavator
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntitySimpleExcavator? EntitySimpleExcavator { 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 _drawningExcavatorWidth = 70;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки экскаватора
|
||||
/// </summary>
|
||||
private readonly int _drawningExcavatorHeight = 80;
|
||||
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningSimpleExcavator()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningSimpleExcavator(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntitySimpleExcavator = new EntitySimpleExcavator(speed, weight, bodyColor);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningExcavatorWidth">Ширина прорисовки экскаватора</param>
|
||||
/// <param name="drawningExcavatorHeight">Высота прорисовки экскаватора</param>
|
||||
public DrawningSimpleExcavator(int drawningExcavatorWidth, int drawningExcavatorHeight) : this()
|
||||
{
|
||||
_drawningExcavatorWidth = drawningExcavatorWidth;
|
||||
_drawningExcavatorHeight = drawningExcavatorHeight;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
if (width > _drawningExcavatorWidth && height > _drawningExcavatorHeight)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX != null && _startPosY != null)
|
||||
{
|
||||
if (_startPosX.Value + _drawningExcavatorWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawningExcavatorWidth;
|
||||
}
|
||||
if (_startPosY.Value + _drawningExcavatorHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawningExcavatorHeight;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
if (_drawningExcavatorWidth + _startPosX > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawningExcavatorWidth;
|
||||
}
|
||||
if (_drawningExcavatorHeight + _startPosY > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawningExcavatorHeight;
|
||||
}
|
||||
if (_startPosX < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
if (_startPosY < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntitySimpleExcavator == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntitySimpleExcavator.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntitySimpleExcavator.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntitySimpleExcavator.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntitySimpleExcavator.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _drawningExcavatorWidth + EntitySimpleExcavator.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntitySimpleExcavator.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _drawningExcavatorHeight + EntitySimpleExcavator.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntitySimpleExcavator.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntitySimpleExcavator == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
|
||||
|
||||
// Гусеницы
|
||||
Brush brGrey = new SolidBrush(Color.FromArgb(100, 100, 100));
|
||||
Brush br = new SolidBrush(EntitySimpleExcavator.BodyColor);
|
||||
|
||||
g.FillEllipse(brGrey, _startPosX.Value, _startPosY.Value + 55, 25, 25);
|
||||
g.FillEllipse(brGrey, _startPosX.Value + 45, _startPosY.Value + 55, 25, 25);
|
||||
g.FillRectangle(brGrey, _startPosX.Value + 10, _startPosY.Value + 55, 50, 25);
|
||||
|
||||
Rectangle rect1 = new Rectangle(_startPosX.Value, _startPosY.Value + 55, 25, 25);
|
||||
g.DrawArc(pen, rect1, 90, 180);
|
||||
Rectangle rect2 = new Rectangle(_startPosX.Value + 45, _startPosY.Value + 55, 25, 25);
|
||||
g.DrawArc(pen, rect2, 270, 180);
|
||||
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 80, _startPosX.Value + 60, _startPosY.Value + 80);
|
||||
|
||||
|
||||
g.FillEllipse(br, _startPosX.Value + 3, _startPosY.Value + 58, 18, 18);
|
||||
g.FillEllipse(br, _startPosX.Value + 48, _startPosY.Value + 58, 18, 18);
|
||||
g.FillEllipse(br, _startPosX.Value + 21, _startPosY.Value + 69, 7, 7);
|
||||
g.FillEllipse(br, _startPosX.Value + 31, _startPosY.Value + 69, 7, 7);
|
||||
g.FillEllipse(br, _startPosX.Value + 41, _startPosY.Value + 69, 7, 7);
|
||||
g.FillEllipse(br, _startPosX.Value + 27, _startPosY.Value + 61, 4, 4);
|
||||
g.FillEllipse(br, _startPosX.Value + 39, _startPosY.Value + 61, 4, 4);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value + 3, _startPosY.Value + 58, 18, 18);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 48, _startPosY.Value + 58, 18, 18);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 21, _startPosY.Value + 69, 7, 7);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 31, _startPosY.Value + 69, 7, 7);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 41, _startPosY.Value + 69, 7, 7);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 27, _startPosY.Value + 61, 4, 4);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 39, _startPosY.Value + 61, 4, 4);
|
||||
|
||||
// Корпус
|
||||
Point[] pointBody1 =
|
||||
{
|
||||
new Point(_startPosX.Value, _startPosY.Value + 55),
|
||||
new Point(_startPosX.Value, _startPosY.Value + 30),
|
||||
new Point(_startPosX.Value + 40, _startPosY.Value + 30),
|
||||
new Point(_startPosX.Value + 40, _startPosY.Value),
|
||||
new Point(_startPosX.Value + 70, _startPosY.Value),
|
||||
new Point(_startPosX.Value + 70, _startPosY.Value + 55),
|
||||
new Point(_startPosX.Value, _startPosY.Value + 55),
|
||||
};
|
||||
g.FillPolygon(br, pointBody1);
|
||||
g.DrawPolygon(pen, pointBody1);
|
||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 5, 10, 25);
|
||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 5, 10, 25);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 5, 10, 25);
|
||||
|
||||
// Окно
|
||||
Brush brLBlue = new SolidBrush(Color.LightBlue);
|
||||
|
||||
g.FillRectangle(brLBlue, _startPosX.Value + 42, _startPosY.Value + 2, 26, 26);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 42, _startPosY.Value + 2, 26, 26);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,24 +1,10 @@
|
||||
namespace Excavator;
|
||||
namespace Excavator.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Экскаватор"
|
||||
/// </summary>
|
||||
public class EntityExcavator
|
||||
public class EntityExcavator : EntitySimpleExcavator
|
||||
{
|
||||
/// <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>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
@ -36,16 +22,17 @@ public class EntityExcavator
|
||||
public bool Bucket { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения экскаватора
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool supports, bool bucket)
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="supports">Опоры</param>
|
||||
/// <param name="bucket">Ковш</param>
|
||||
public EntityExcavator(int speed, double weight, Color bodyColor, Color additionalColor, bool supports, bool bucket) : base(speed, weight, bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
|
||||
AdditionalColor = additionalColor;
|
||||
Supports = supports;
|
||||
Bucket = bucket;
|
47
Excavator/Excavator/Entities/EntitySimpleExcavator.cs
Normal file
47
Excavator/Excavator/Entities/EntitySimpleExcavator.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Excavator.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Экскаватор"
|
||||
/// </summary>
|
||||
public class EntitySimpleExcavator
|
||||
{
|
||||
/// <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 double Step => Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
public EntitySimpleExcavator(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
26
Excavator/Excavator/FormExcavator.Designer.cs
generated
26
Excavator/Excavator/FormExcavator.Designer.cs
generated
@ -34,6 +34,7 @@
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonCreateSimpleExcavator = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxExcavator).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -51,9 +52,9 @@
|
||||
buttonCreateExcavator.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateExcavator.Location = new Point(12, 562);
|
||||
buttonCreateExcavator.Name = "buttonCreateExcavator";
|
||||
buttonCreateExcavator.Size = new Size(75, 23);
|
||||
buttonCreateExcavator.Size = new Size(217, 23);
|
||||
buttonCreateExcavator.TabIndex = 1;
|
||||
buttonCreateExcavator.Text = "Создать";
|
||||
buttonCreateExcavator.Text = "Создать экскаватор с обвесами";
|
||||
buttonCreateExcavator.UseVisualStyleBackColor = true;
|
||||
buttonCreateExcavator.Click += ButtonCreateExcavator_Click;
|
||||
//
|
||||
@ -62,7 +63,7 @@
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonLeft.Location = new Point(740, 535);
|
||||
buttonLeft.Location = new Point(749, 535);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(50, 50);
|
||||
buttonLeft.TabIndex = 2;
|
||||
@ -74,7 +75,7 @@
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonUp.Location = new Point(796, 479);
|
||||
buttonUp.Location = new Point(805, 479);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(50, 50);
|
||||
buttonUp.TabIndex = 3;
|
||||
@ -86,7 +87,7 @@
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDown.Location = new Point(796, 535);
|
||||
buttonDown.Location = new Point(805, 535);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(50, 50);
|
||||
buttonDown.TabIndex = 4;
|
||||
@ -98,18 +99,30 @@
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonRight.Location = new Point(852, 535);
|
||||
buttonRight.Location = new Point(861, 535);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(50, 50);
|
||||
buttonRight.TabIndex = 5;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateSimpleExcavator
|
||||
//
|
||||
buttonCreateSimpleExcavator.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateSimpleExcavator.Location = new Point(235, 562);
|
||||
buttonCreateSimpleExcavator.Name = "buttonCreateSimpleExcavator";
|
||||
buttonCreateSimpleExcavator.Size = new Size(217, 23);
|
||||
buttonCreateSimpleExcavator.TabIndex = 6;
|
||||
buttonCreateSimpleExcavator.Text = "Создать экскаватор ";
|
||||
buttonCreateSimpleExcavator.UseVisualStyleBackColor = true;
|
||||
buttonCreateSimpleExcavator.Click += ButtonCreateSimpleExcavator_Click;
|
||||
//
|
||||
// FormExcavator
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(923, 597);
|
||||
Controls.Add(buttonCreateSimpleExcavator);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
@ -130,5 +143,6 @@
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonCreateSimpleExcavator;
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
namespace Excavator;
|
||||
using Excavator.Drawnings;
|
||||
|
||||
namespace Excavator;
|
||||
|
||||
/// <summary>
|
||||
/// Форма работы с объектом "Экскаватор"
|
||||
@ -8,7 +10,7 @@ public partial class FormExcavator : Form
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningExcavator? _drawningExcavator;
|
||||
private DrawningSimpleExcavator? _drawningSimpleExcavator;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
@ -23,33 +25,66 @@ public partial class FormExcavator : Form
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningExcavator == null)
|
||||
if (_drawningSimpleExcavator == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap bmp = new(pictureBoxExcavator.Width, pictureBoxExcavator.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningExcavator.DrawTransport(gr);
|
||||
_drawningSimpleExcavator.DrawTransport(gr);
|
||||
pictureBoxExcavator.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// Создание объекта
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningSimpleExcavator):
|
||||
_drawningSimpleExcavator = new DrawningSimpleExcavator(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||
break;
|
||||
case nameof(DrawningExcavator):
|
||||
_drawningSimpleExcavator = new DrawningExcavator(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(1, 2)), Convert.ToBoolean(random.Next(1, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
_drawningSimpleExcavator.SetPictureSize(pictureBoxExcavator.Width, pictureBoxExcavator.Height);
|
||||
_drawningSimpleExcavator.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
//_strategy = null;
|
||||
//comboBoxStrategy.Enabled = true;
|
||||
Draw();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать экскаватор с обвесами"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateExcavator_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningExcavator = new DrawningExcavator();
|
||||
_drawningExcavator.Init(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
_drawningExcavator.SetPictureSize(pictureBoxExcavator.Width, pictureBoxExcavator.Height);
|
||||
_drawningExcavator.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
CreateObject(nameof(DrawningExcavator));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать экскаватор"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateSimpleExcavator_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateObject(nameof(DrawningSimpleExcavator));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -59,7 +94,7 @@ public partial class FormExcavator : Form
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningExcavator == null)
|
||||
if (_drawningSimpleExcavator == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -69,16 +104,16 @@ public partial class FormExcavator : Form
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningExcavator.MoveTransport(DirectionType.Up);
|
||||
result = _drawningSimpleExcavator.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningExcavator.MoveTransport(DirectionType.Down);
|
||||
result = _drawningSimpleExcavator.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningExcavator.MoveTransport(DirectionType.Left);
|
||||
result = _drawningSimpleExcavator.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningExcavator.MoveTransport(DirectionType.Right);
|
||||
result = _drawningSimpleExcavator.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user