2023-10-05 21:52:23 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-10-06 21:35:14 +04:00
|
|
|
|
using RoadTrain.Entities;
|
2023-10-05 21:52:23 +04:00
|
|
|
|
|
2023-10-06 21:35:14 +04:00
|
|
|
|
namespace RoadTrain.DrawningObjects
|
2023-10-05 21:52:23 +04:00
|
|
|
|
{
|
|
|
|
|
public class DrawningRoadTrain
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Класс-сущность
|
|
|
|
|
/// </summary>
|
2023-10-06 21:35:14 +04:00
|
|
|
|
public EntityRoadTrain? EntityRoadTrain { get; protected set; }
|
2023-10-05 21:52:23 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина окна
|
|
|
|
|
/// </summary>
|
2023-10-06 21:35:14 +04:00
|
|
|
|
protected int _pictureWidth;
|
2023-10-05 21:52:23 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота окна
|
|
|
|
|
/// </summary>
|
2023-10-06 21:35:14 +04:00
|
|
|
|
protected int _pictureHeight;
|
2023-10-05 21:52:23 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Левая координата прорисовки автомобиля
|
|
|
|
|
/// </summary>
|
2023-10-06 21:35:14 +04:00
|
|
|
|
protected int _startPosX;
|
2023-10-05 21:52:23 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Верхняя кооридната прорисовки автомобиля
|
|
|
|
|
/// </summary>
|
2023-10-06 21:35:14 +04:00
|
|
|
|
protected int _startPosY;
|
2023-10-05 21:52:23 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина прорисовки автомобиля
|
|
|
|
|
/// </summary>
|
2023-10-06 21:35:14 +04:00
|
|
|
|
protected readonly int _trainWidth = 70;
|
2023-10-05 21:52:23 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота прорисовки автомобиля
|
|
|
|
|
/// </summary>
|
2023-10-06 21:35:14 +04:00
|
|
|
|
protected readonly int _trainHeight = 30;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Координата X объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int GetPosX => _startPosX;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Координата Y объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int GetPosY => _startPosY;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int GetWidth => _trainWidth;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int GetHeight => _trainHeight;
|
2023-10-05 21:52:23 +04:00
|
|
|
|
/// <summary>
|
2023-10-06 21:35:14 +04:00
|
|
|
|
/// Проверка, что объект может переместится по указанному направлению
|
2023-10-05 21:52:23 +04:00
|
|
|
|
/// </summary>
|
2023-10-06 21:35:14 +04:00
|
|
|
|
/// <param name="direction">Направление</param>
|
|
|
|
|
/// <returns>true - можно переместится по указанному направлению</returns>
|
|
|
|
|
public bool CanMove(DirectionType direction)
|
|
|
|
|
{
|
|
|
|
|
if (EntityRoadTrain == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return direction switch
|
|
|
|
|
{
|
|
|
|
|
//влево
|
|
|
|
|
DirectionType.Left => _startPosX - EntityRoadTrain.Step > 0,
|
|
|
|
|
//вверх
|
|
|
|
|
DirectionType.Up => _startPosY - EntityRoadTrain.Step > 0,
|
|
|
|
|
// вправо
|
|
|
|
|
DirectionType.Right => _startPosX + EntityRoadTrain.Step + _trainWidth < _pictureWidth,
|
|
|
|
|
//вниз
|
|
|
|
|
DirectionType.Down => _startPosY + EntityRoadTrain.Step + _trainHeight < _pictureHeight
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Инициализация свойств
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="speed">Скорость</param>
|
|
|
|
|
/// <param name="weight">Вес</param>
|
|
|
|
|
/// <param name="bodyColor">Цвет кузова</param>
|
|
|
|
|
/// <param name="width">Ширина картинки</param>
|
|
|
|
|
/// <param name="height">Высота картинки</param>
|
|
|
|
|
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
|
|
|
|
public DrawningRoadTrain(int speed, double weight, Color bodyColor, int width, int height)
|
2023-10-05 21:52:23 +04:00
|
|
|
|
{
|
2023-10-06 21:35:14 +04:00
|
|
|
|
if (width < _trainWidth) { return; }
|
|
|
|
|
if (height < _trainHeight) { return; }
|
|
|
|
|
_pictureWidth = width;
|
2023-10-05 21:52:23 +04:00
|
|
|
|
_pictureHeight = height;
|
2023-10-06 21:35:14 +04:00
|
|
|
|
EntityRoadTrain = new EntityRoadTrain(speed, weight, bodyColor);
|
2023-10-05 21:52:23 +04:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Установка позиции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="x">Координата X</param>
|
|
|
|
|
/// <param name="y">Координата Y</param>
|
|
|
|
|
public void SetPosition(int x, int y)
|
|
|
|
|
{
|
|
|
|
|
if (x < 0) { x = 0; }
|
|
|
|
|
if (y < 0) { y = 0; }
|
|
|
|
|
if (x > 200) { x = 200; }
|
|
|
|
|
if (y > 200) { y = 200; }
|
|
|
|
|
_startPosX = x;
|
|
|
|
|
_startPosY = y;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Изменение направления перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="direction">Направление</param>
|
|
|
|
|
public void MoveTransport(DirectionType direction)
|
|
|
|
|
{
|
2023-10-06 21:35:14 +04:00
|
|
|
|
if (!CanMove(direction) || EntityRoadTrain == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (direction)
|
2023-10-05 21:52:23 +04:00
|
|
|
|
{
|
2023-10-06 21:35:14 +04:00
|
|
|
|
//влево
|
|
|
|
|
case DirectionType.Left:
|
|
|
|
|
_startPosX -= (int)EntityRoadTrain.Step;
|
|
|
|
|
break;
|
|
|
|
|
//вверх
|
|
|
|
|
case DirectionType.Up:
|
|
|
|
|
_startPosY -= (int)EntityRoadTrain.Step;
|
|
|
|
|
break;
|
|
|
|
|
// вправо
|
|
|
|
|
case DirectionType.Right:
|
|
|
|
|
_startPosX += (int)EntityRoadTrain.Step;
|
|
|
|
|
break;
|
|
|
|
|
//вниз
|
|
|
|
|
case DirectionType.Down:
|
|
|
|
|
_startPosY += (int)EntityRoadTrain.Step;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-10-05 21:52:23 +04:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Прорисовка объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="g"></param>
|
2023-10-06 21:35:14 +04:00
|
|
|
|
public virtual void DrawTransport(Graphics g)
|
2023-10-05 21:52:23 +04:00
|
|
|
|
{
|
|
|
|
|
if (EntityRoadTrain == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Brush br = new SolidBrush(EntityRoadTrain.BodyColor);
|
2023-10-06 21:35:14 +04:00
|
|
|
|
Pen pen = new(Color.Black);
|
|
|
|
|
g.DrawLine(pen, _startPosX + 20, _startPosY + 20, _startPosX + 70, _startPosY + 20);
|
2023-10-05 21:52:23 +04:00
|
|
|
|
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 20, 10, 10);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX + 30, _startPosY + 20, 10, 10);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX + 60, _startPosY + 20, 10, 10);
|
|
|
|
|
g.DrawRectangle(pen, _startPosX + 60, _startPosY, 10, 20);
|
|
|
|
|
|
|
|
|
|
g.FillEllipse(br, _startPosX + 20, _startPosY + 20, 10, 10);
|
|
|
|
|
g.FillEllipse(br, _startPosX + 30, _startPosY + 20, 10, 10);
|
|
|
|
|
g.FillEllipse(br, _startPosX + 60, _startPosY + 20, 10, 10);
|
|
|
|
|
g.FillRectangle(br, _startPosX + 60, _startPosY, 10, 20);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-06 21:35:14 +04:00
|
|
|
|
}
|