Добавление родителей и ввод конструкторов
This commit is contained in:
parent
83216e0433
commit
534f994111
@ -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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HoistingCrane", "HoistingCrane\HoistingCrane.csproj", "{915BDF62-D64D-4AB9-BA2D-8E228E803B7F}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HoistingCrane", "HoistingCrane\HoistingCrane.csproj", "{915BDF62-D64D-4AB9-BA2D-8E228E803B7F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace HoistingCrane;
|
||||
namespace HoistingCrane.Drawning;
|
||||
|
||||
public enum DirectionType : byte //Создали не класс(class), а перечисление (enum)
|
||||
{
|
@ -0,0 +1,96 @@
|
||||
using HoistingCrane.Entities;
|
||||
|
||||
namespace HoistingCrane.Drawning;
|
||||
|
||||
//В данном классе мы будем думать над полем игры, размерами персонажа, размерами объектов и т.д.
|
||||
public class DrawningHoistingCrane : DrawningTrackedVehicle
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс - сущность
|
||||
/// </summary>
|
||||
public EntityHoistingCrane? EntityHoistingCrane { get; private set; }
|
||||
|
||||
/// <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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
291
HoistingCrane/HoistingCrane/Drawning/DrawningTrackedVehicle.cs
Normal file
291
HoistingCrane/HoistingCrane/Drawning/DrawningTrackedVehicle.cs
Normal file
@ -0,0 +1,291 @@
|
||||
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;
|
||||
|
||||
|
||||
|
||||
/// <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)
|
||||
{
|
||||
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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,278 +0,0 @@
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
46
HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs
Normal file
46
HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs
Normal file
@ -0,0 +1,46 @@
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
52
HoistingCrane/HoistingCrane/Entities/EntityTrackedVehicle.cs
Normal file
52
HoistingCrane/HoistingCrane/Entities/EntityTrackedVehicle.cs
Normal file
@ -0,0 +1,52 @@
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -25,11 +25,12 @@ namespace HoistingCrane
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxHoistingCrane = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonCreateHoistingCrane = new Button();
|
||||
ButtonLeft = new Button();
|
||||
ButtonRight = new Button();
|
||||
ButtonUp = new Button();
|
||||
ButtonDown = new Button();
|
||||
buttonCreateTrackedVehicle = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxHoistingCrane).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -42,23 +43,23 @@ namespace HoistingCrane
|
||||
pictureBoxHoistingCrane.TabIndex = 0;
|
||||
pictureBoxHoistingCrane.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
// buttonCreateHoistingCrane
|
||||
//
|
||||
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;
|
||||
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;
|
||||
//
|
||||
// ButtonLeft
|
||||
//
|
||||
ButtonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
ButtonLeft.BackgroundImage = Properties.Resources.left_arrow;
|
||||
ButtonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ButtonLeft.Location = new Point(118, 404);
|
||||
ButtonLeft.Location = new Point(642, 475);
|
||||
ButtonLeft.Name = "ButtonLeft";
|
||||
ButtonLeft.Size = new Size(40, 40);
|
||||
ButtonLeft.TabIndex = 2;
|
||||
@ -70,7 +71,7 @@ namespace HoistingCrane
|
||||
ButtonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
ButtonRight.BackgroundImage = Properties.Resources.right_arrow;
|
||||
ButtonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ButtonRight.Location = new Point(207, 404);
|
||||
ButtonRight.Location = new Point(734, 475);
|
||||
ButtonRight.Name = "ButtonRight";
|
||||
ButtonRight.Size = new Size(40, 40);
|
||||
ButtonRight.TabIndex = 3;
|
||||
@ -82,7 +83,7 @@ namespace HoistingCrane
|
||||
ButtonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
ButtonUp.BackgroundImage = Properties.Resources.up_arrow;
|
||||
ButtonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ButtonUp.Location = new Point(164, 367);
|
||||
ButtonUp.Location = new Point(688, 429);
|
||||
ButtonUp.Name = "ButtonUp";
|
||||
ButtonUp.Size = new Size(40, 40);
|
||||
ButtonUp.TabIndex = 4;
|
||||
@ -94,23 +95,35 @@ 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(164, 440);
|
||||
ButtonDown.Location = new Point(688, 475);
|
||||
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;
|
||||
//
|
||||
// FormHoistingCrane
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(818, 515);
|
||||
Controls.Add(buttonCreateTrackedVehicle);
|
||||
Controls.Add(ButtonDown);
|
||||
Controls.Add(ButtonUp);
|
||||
Controls.Add(ButtonRight);
|
||||
Controls.Add(ButtonLeft);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(buttonCreateHoistingCrane);
|
||||
Controls.Add(pictureBoxHoistingCrane);
|
||||
Name = "FormHoistingCrane";
|
||||
Text = "Подъемный кран";
|
||||
@ -121,10 +134,11 @@ namespace HoistingCrane
|
||||
// #endregion
|
||||
|
||||
private PictureBox pictureBoxHoistingCrane;
|
||||
private Button buttonCreate;
|
||||
private Button buttonCreateHoistingCrane;
|
||||
private Button ButtonLeft;
|
||||
private Button ButtonRight;
|
||||
private Button ButtonUp;
|
||||
private Button ButtonDown;
|
||||
private Button buttonCreateTrackedVehicle;
|
||||
}
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
namespace HoistingCrane
|
||||
using HoistingCrane.Drawning;
|
||||
|
||||
namespace HoistingCrane
|
||||
{
|
||||
public partial class FormHoistingCrane : Form
|
||||
{
|
||||
|
||||
private DrawningHoistingCrane? _drawningHoistingCrane;
|
||||
private DrawningTrackedVehicle? _drawning;
|
||||
|
||||
public FormHoistingCrane()
|
||||
{
|
||||
@ -14,47 +16,78 @@
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningHoistingCrane?.DrawTransport(gr);
|
||||
_drawning?.DrawTransport(gr);
|
||||
pictureBoxHoistingCrane.Image = bmp;
|
||||
}
|
||||
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
|
||||
/// <summary>
|
||||
/// Создать подъемный кран
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateHoistingCrane_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)
|
||||
{
|
||||
|
||||
Random rand = new();
|
||||
_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();
|
||||
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));
|
||||
Draw();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningHoistingCrane == null) { return; }
|
||||
if (_drawning == null) { return; }
|
||||
String name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
switch (name)
|
||||
{
|
||||
case "ButtonUp":
|
||||
result = _drawningHoistingCrane.MoveTransport(DirectionType.Up);
|
||||
result = _drawning.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "ButtonDown":
|
||||
result = _drawningHoistingCrane.MoveTransport(DirectionType.Down);
|
||||
result = _drawning.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "ButtonRight":
|
||||
result = _drawningHoistingCrane.MoveTransport(DirectionType.Right);
|
||||
result = _drawning.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
case "ButtonLeft":
|
||||
result = _drawningHoistingCrane.MoveTransport(DirectionType.Left);
|
||||
result = _drawning.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
|
Loading…
Reference in New Issue
Block a user