156 lines
6.2 KiB
C#
156 lines
6.2 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace RoadTrain
|
||
{
|
||
public class DrawningRoadTrain
|
||
{
|
||
/// <summary>
|
||
/// Класс-сущность
|
||
/// </summary>
|
||
public EntityRoadTrain? EntityRoadTrain { 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 _trainWidth = 70;
|
||
/// <summary>
|
||
/// Высота прорисовки автомобиля
|
||
/// </summary>
|
||
private readonly int _trainHeight = 30;
|
||
/// <summary>
|
||
/// Инициализация свойств
|
||
/// </summary>
|
||
/// <param name="speed">Скорость</param>
|
||
/// <param name="weight">Вес</param>
|
||
/// <param name="bodyColor">Цвет кузова</param>
|
||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||
/// <param name="WaterContainer">Признак наличия контейнера для воды</param>
|
||
/// <param name="SweepingBrush">Признак наличия щетки</param>
|
||
/// <param name="width">Ширина картинки</param>
|
||
/// <param name="height">Высота картинки</param>
|
||
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
||
public bool Init(EntityRoadTrain entityRoadTrain, int width, int height)
|
||
{
|
||
if (width < _trainWidth) { return false; }
|
||
if (height < _trainHeight) { return false; }
|
||
_pictureWidth = width;
|
||
_pictureHeight = height;
|
||
EntityRoadTrain = entityRoadTrain;
|
||
|
||
return true;
|
||
}
|
||
/// <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)
|
||
{
|
||
if (EntityRoadTrain == null)
|
||
{
|
||
return;
|
||
}
|
||
switch (direction)
|
||
{
|
||
//влево
|
||
case DirectionType.Left:
|
||
if (_startPosX - EntityRoadTrain.Step > 0)
|
||
{
|
||
_startPosX -= (int)EntityRoadTrain.Step;
|
||
}
|
||
break;
|
||
//вверх
|
||
case DirectionType.Up:
|
||
if (_startPosY - EntityRoadTrain.Step > 0)
|
||
{
|
||
_startPosY -= (int)EntityRoadTrain.Step;
|
||
}
|
||
break;
|
||
// вправо
|
||
case DirectionType.Right:
|
||
if (_startPosX + EntityRoadTrain.Step + _trainWidth < _pictureWidth)
|
||
{
|
||
_startPosX += (int)EntityRoadTrain.Step;
|
||
}
|
||
break;
|
||
//вниз
|
||
case DirectionType.Down:
|
||
if (_startPosY + EntityRoadTrain.Step + _trainHeight < _pictureHeight)
|
||
{
|
||
_startPosY += (int)EntityRoadTrain.Step;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// Прорисовка объекта
|
||
/// </summary>
|
||
/// <param name="g"></param>
|
||
public void DrawTransport(Graphics g)
|
||
{
|
||
if (EntityRoadTrain == null)
|
||
{
|
||
return;
|
||
}
|
||
Pen pen = new(Color.Black);
|
||
Brush additionalBrush = new SolidBrush(EntityRoadTrain.AdditionalColor);
|
||
//Контейнер с водой
|
||
if (EntityRoadTrain.WaterContainer)
|
||
{
|
||
g.DrawEllipse(pen, _startPosX + 30, _startPosY, 10, 20);
|
||
g.FillEllipse(additionalBrush, _startPosX + 30, _startPosY, 10, 20);
|
||
|
||
}
|
||
if (EntityRoadTrain.SweepingBrush)
|
||
{
|
||
g.DrawLine(pen, _startPosX + 30, _startPosY + 10, _startPosX + 20, _startPosY + 10);
|
||
g.DrawLine(pen, _startPosX + 20, _startPosY + 10, _startPosX + 10, _startPosY + 30);
|
||
g.DrawLine(pen, _startPosX + 17, _startPosY + 30, _startPosX + 3, _startPosY + 30);
|
||
}
|
||
Brush br = new SolidBrush(EntityRoadTrain.BodyColor);
|
||
g.DrawLine(pen, _startPosX + 20, _startPosY + 20, _startPosX + 70, _startPosY + 20);
|
||
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);
|
||
}
|
||
}
|
||
}
|