267 lines
9.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace ProjectByldozerHard;
public class DrawningByldozer
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntityByldozer? EntityByldozer { get; private set; }
private DrawingRink? Rink;
/// <summary>
/// Ширина окна
/// </summary>
private int? _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
private int? _pictureHeight;
/// <summary>
/// Левая координата прорисовки экскаватора
/// </summary>
private int? _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки экскаватора
/// </summary>
private int? _startPosY;
/// <summary>
/// Ширина прорисовки экскаватора
/// </summary>
private int _drawningByldozerWidth;
/// <summary>
/// Высота прорисовки экскаватора
/// </summary>
private int _drawningByldozerHeight;
/// <summary>
/// инициализация свойств
/// </summary>
/// <param name="speed"></param>
/// <param name="weight"></param>
/// <param name="bodyColor"></param>
/// <param name="additionalColor"></param>
/// <param name="dump"></param>
/// <param name="bakingpowder"></param>
/// <param name="pipe"></param>
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool dump, bool bakingpowder, bool pipe, /*int numberOfRink*/ int width, int height)
{
if (weight < _pictureWidth || height < _pictureHeight)
{
return false;
}
_drawningByldozerWidth = 150;
_drawningByldozerHeight = 80;
_pictureWidth = width;
_pictureHeight = height;
EntityByldozer = new EntityByldozer();
EntityByldozer.Init(speed, weight, bodyColor, additionalColor, dump, bakingpowder, pipe);
Rink = new DrawingRink();
//Rink.KatNum(numberOfRink);
return true;
}
/// <summary>
/// Установка границ поля
/// </summary>
/// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param>
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
/// <summary>
/// Установка позиции
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
if (x < 0)
{
x = 0;
}
else if (x > _pictureWidth.Value - _drawningByldozerWidth)
{
x = (_pictureWidth.Value - _drawningByldozerWidth);
}
if (y < 0)
{
y = 0;
}
else if (y > _pictureHeight.Value - _drawningByldozerWidth)
{
y = _pictureHeight.Value - _drawningByldozerHeight;
}
_startPosX = x;
_startPosY = y;
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - перемещение выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction)
{
if (EntityByldozer == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX.Value - EntityByldozer.Step > 0)
{
_startPosX -= (int)EntityByldozer.Step;
}
return true;
//вверх
case DirectionType.Up:
if (_startPosY.Value - EntityByldozer.Step > 0)
{
_startPosY -= (int)EntityByldozer.Step;
}
return true;
// вправо
case DirectionType.Right:
if (_startPosX.Value + _drawningByldozerWidth + EntityByldozer.Step < _pictureWidth)
{
_startPosX += (int)EntityByldozer.Step;
}
return true;
//вниз
case DirectionType.Down:
if (_startPosY.Value + _drawningByldozerHeight + EntityByldozer.Step < _pictureHeight)
{
_startPosY += (int)EntityByldozer.Step;
}
return true;
default:
return false;
}
}
///<summary>
/// Прорисовка объекта
/// </summary>
/// <param name = "g" ></ param >
public void DrawTransport(Graphics g)
{
if (EntityByldozer == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityByldozer.AdditionalColor);
Brush bodybrush = new SolidBrush(EntityByldozer.BodyColor);
//границы бульдозера и колес
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 20, 100, 30);
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value, 30, 20);
g.DrawArc(pen, _startPosX.Value + 30, _startPosY.Value + 45, 30, 40, 130, 100);
g.DrawArc(pen, _startPosX.Value + 103, _startPosY.Value + 50, 30, 40, 258, 140);
g.DrawLine(pen, _startPosX.Value + 35, _startPosY.Value + 80, _startPosX.Value + 130, _startPosY.Value + 80);
//g.DrawEllipse(pen, _startPosX.Value + 60, _startPosY.Value + 67, 10, 10);
//g.DrawEllipse(pen, _startPosX.Value + 78, _startPosY.Value + 67, 10, 10);
//g.DrawEllipse(pen, _startPosX.Value + 95, _startPosY.Value + 67, 10, 10);
//g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 53, 7, 7);
//g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 53, 7, 7);
//g.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 55, 20, 20);
//g.DrawEllipse(pen, _startPosX.Value + 110, _startPosY.Value + 55, 20, 20);
//заливка кабины и гусениц
Brush br = new SolidBrush(Color.Black);
g.FillRectangle(bodybrush, _startPosX.Value + 30, _startPosY.Value + 20, 100, 30);
g.FillRectangle(bodybrush, _startPosX.Value + 100, _startPosY.Value, 30, 20);
//g.FillEllipse(br, _startPosX.Value + 35, _startPosY.Value + 55, 20, 20);
//g.FillEllipse(br, _startPosX.Value + 110, _startPosY.Value + 55, 20, 20);
//g.FillEllipse(br, _startPosX.Value + 60, _startPosY.Value + 67, 10, 10);
//g.FillEllipse(br, _startPosX.Value + 78, _startPosY.Value + 67, 10, 10);
//g.FillEllipse(br, _startPosX.Value + 95, _startPosY.Value + 67, 10, 10);
//g.FillEllipse(br, _startPosX.Value + 70, _startPosY.Value + 53, 7, 7);
//g.FillEllipse(br, _startPosX.Value + 90, _startPosY.Value + 53, 7, 7);
Rink.DrawRinks(g, _startPosX.Value + 5, _startPosY.Value + 10);
//окно
Brush blfara = new SolidBrush(Color.Blue);
g.FillRectangle(blfara, _startPosX.Value + 110, _startPosY.Value + 5, 10, 25);
///труба
if (EntityByldozer.Pipe)
{
g.DrawRectangle(pen, _startPosX.Value + 60, _startPosY.Value, 5, 20);
g.FillRectangle(bodybrush, _startPosX.Value + 60, _startPosY.Value, 5, 20);
}
// отвал
if (EntityByldozer.Dump)
{
Point point1 = new Point(_startPosX.Value + 30, _startPosY.Value + 35);
Point point2 = new Point(_startPosX.Value + 25, _startPosY.Value + 35);
Point point4 = new Point(_startPosX.Value + 25, _startPosY.Value + 23);
Point point5 = new Point(_startPosX.Value + 20, _startPosY.Value + 23);
Point point6 = new Point(_startPosX.Value + 15, _startPosY.Value + 60);
Point point7 = new Point(_startPosX.Value + 2, _startPosY.Value + 80);
Point point8 = new Point(_startPosX.Value + 25, _startPosY.Value + 80);
Point point9 = new Point(_startPosX.Value + 25, _startPosY.Value + 46);
Point point10 = new Point(_startPosX.Value + 30, _startPosY.Value + 46);
Point[] Dump = { point1, point2, point4, point5, point6, point7, point8, point9, point10 };
g.FillPolygon(additionalBrush, Dump);
}
if (EntityByldozer.Bakingpowder)
{
Point point1 = new Point(_startPosX.Value + 131, _startPosY.Value + 25);
Point point2 = new Point(_startPosX.Value + 150, _startPosY.Value + 25);
Point point4 = new Point(_startPosX.Value + 150, _startPosY.Value + 35);
Point point5 = new Point(_startPosX.Value + 147, _startPosY.Value + 35);
Point point6 = new Point(_startPosX.Value + 147, _startPosY.Value + 60);
Point point7 = new Point(_startPosX.Value + 144, _startPosY.Value + 60);
Point point8 = new Point(_startPosX.Value + 145, _startPosY.Value + 80);
Point point9 = new Point(_startPosX.Value + 137, _startPosY.Value + 60);
Point point10 = new Point(_startPosX.Value + 134, _startPosY.Value + 60);
Point point11 = new Point(_startPosX.Value + 134, _startPosY.Value + 35);
Point point12 = new Point(_startPosX.Value + 131, _startPosY.Value + 35);
Point[] Bakingpowder = { point1, point2, point4, point5, point6, point7, point8, point9, point10, point11, point12 };
g.FillPolygon(additionalBrush, Bakingpowder);
}
}
}