using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Hydroplane { public class DrawningHydroplane { /// /// Класс-сущность /// public EntityHydroplane? EntityHydroplane { get; private set; } /// /// Ширина окна /// private int _pictureWidth; /// /// Высота окна /// private int _pictureHeight; /// /// Левая координата прорисовки автомобиля /// private int _startPosX; /// /// Верхняя кооридната прорисовки автомобиля /// private int _startPosY; /// /// Ширина прорисовки автомобиля /// private readonly int _planeWidth = 175; /// /// Высота прорисовки автомобиля /// private readonly int _planeHeight = 100; /// /// Инициализация свойств /// /// Скорость /// Вес /// Цвет кузова /// Дополнительный цвет /// Признак наличия обвеса /// Признак наличия антикрыла /// Ширина картинки /// Высота картинки /// true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool boat, bool bobber, int width, int height) { // TODO: Продумать проверки _pictureWidth = width; _pictureHeight = height; EntityHydroplane = new EntityHydroplane(); EntityHydroplane.Init(speed, weight, bodyColor, additionalColor, boat, bobber); return true; } /// /// Установка позиции /// /// Координата X /// Координата Y public void SetPosition(int x, int y) { // TODO: Изменение x, y _startPosX = x; _startPosY = y; } /// /// Изменение направления перемещения /// /// Направление public void MoveTransport(DirectionType direction) { if (EntityHydroplane == null) { return; } switch (direction) { //влево case DirectionType.Left: if (_startPosX - EntityHydroplane.Step > 0) { _startPosX -= (int)EntityHydroplane.Step; } break; //вверх case DirectionType.Up: if (_startPosY - EntityHydroplane.Step > 0) { _startPosY -= (int)EntityHydroplane.Step; } break; // вправо case DirectionType.Right: if (_startPosX + EntityHydroplane.Step + _planeWidth < _pictureWidth) { _startPosX += (int)EntityHydroplane.Step; } break; //вниз case DirectionType.Down: if (_startPosY + EntityHydroplane.Step + _planeHeight < _pictureHeight) { _startPosY += (int)EntityHydroplane.Step; } break; } } /// /// Прорисовка объекта /// /// public void DrawTransport(Graphics g) { if (EntityHydroplane == null) { return; } Pen pen = new(Color.Black); Brush additionalBrush = new SolidBrush(EntityHydroplane.AdditionalColor); /* // обвесы if (EntityHydroplane.BodyKit) { g.DrawEllipse(pen, _startPosX + 90, _startPosY, 20, 20); g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 20, 20); g.DrawRectangle(pen, _startPosX + 90, _startPosY + 10, 20, 40); g.DrawRectangle(pen, _startPosX + 90, _startPosY, 15, 15); g.DrawRectangle(pen, _startPosX + 90, _startPosY + 45, 15, 15); g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY, 20, 20); g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 40, 20, 20); g.FillRectangle(additionalBrush, _startPosX + 90, _startPosY + 10, 20, 40); g.FillRectangle(additionalBrush, _startPosX + 90, _startPosY + 1, 15, 15); g.FillRectangle(additionalBrush, _startPosX + 90, _startPosY + 45, 15, 15); g.DrawEllipse(pen, _startPosX, _startPosY, 20, 20); g.DrawEllipse(pen, _startPosX, _startPosY + 40, 20, 20); g.DrawRectangle(pen, _startPosX, _startPosY + 10, 20, 40); g.DrawRectangle(pen, _startPosX + 5, _startPosY, 14, 15); g.DrawRectangle(pen, _startPosX + 5, _startPosY + 45, 14, 15); g.FillEllipse(additionalBrush, _startPosX, _startPosY, 20, 20); g.FillEllipse(additionalBrush, _startPosX, _startPosY + 40, 20, 20); g.FillRectangle(additionalBrush, _startPosX + 1, _startPosY + 10, 25, 40); g.FillRectangle(additionalBrush, _startPosX + 5, _startPosY + 1, 15, 15); g.FillRectangle(additionalBrush, _startPosX + 5, _startPosY + 45, 15, 15); g.DrawRectangle(pen, _startPosX + 35, _startPosY, 39, 15); g.DrawRectangle(pen, _startPosX + 35, _startPosY + 45, 39, 15); g.FillRectangle(additionalBrush, _startPosX + 35, _startPosY + 1, 40, 15); g.FillRectangle(additionalBrush, _startPosX + 35, _startPosY + 45, 40, 15); } //границы автомобиля g.DrawEllipse(pen, _startPosX + 10, _startPosY + 5, 20, 20); g.DrawEllipse(pen, _startPosX + 10, _startPosY + 35, 20, 20); g.DrawEllipse(pen, _startPosX + 80, _startPosY + 5, 20, 20); g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 20, 20); g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30); g.DrawRectangle(pen, _startPosX + 90, _startPosY + 15, 10, 30); g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52); //задние фары Brush brRed = new SolidBrush(Color.Red); g.FillEllipse(brRed, _startPosX + 10, _startPosY + 5, 20, 20); g.FillEllipse(brRed, _startPosX + 10, _startPosY + 35, 20, 20); //передние фары Brush brYellow = new SolidBrush(Color.Yellow); g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20, 20); g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20, 20); //кузов Brush br = new SolidBrush(EntityHydroplane.BodyColor); g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30); g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30); g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50); //стекла Brush brBlue = new SolidBrush(Color.LightBlue); g.FillRectangle(brBlue, _startPosX + 70, _startPosY + 10, 5, 40); g.FillRectangle(brBlue, _startPosX + 30, _startPosY + 10, 5, 40); g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 8, 35, 2); g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 51, 35, 2); //выделяем рамкой крышу g.DrawRectangle(pen, _startPosX + 35, _startPosY + 10, 35, 40); g.DrawRectangle(pen, _startPosX + 75, _startPosY + 15, 25, 30); g.DrawRectangle(pen, _startPosX + 10, _startPosY + 15, 15, 30); // спортивная линия if (EntityHydroplane.SportLine) { g.FillRectangle(additionalBrush, _startPosX + 75, _startPosY + 23, 25, 15); g.FillRectangle(additionalBrush, _startPosX + 35, _startPosY + 23, 35, 15); g.FillRectangle(additionalBrush, _startPosX + 10, _startPosY + 23, 20, 15); } // крыло if (EntityHydroplane.Wing) { g.FillRectangle(additionalBrush, _startPosX, _startPosY + 5, 10, 50); g.DrawRectangle(pen, _startPosX, _startPosY + 5, 10, 50); } */ //основа g.DrawRectangle(pen, _startPosX + 5, _startPosY + 25, 125, 30); //хвост g.DrawLine(pen, _startPosX + 5, _startPosY + 25, _startPosX + 5, _startPosY); g.DrawLine(pen, _startPosX + 55, _startPosY + 25, _startPosX + 5, _startPosY); //нос g.DrawLine(pen, _startPosX + 130, _startPosY + 25, _startPosX + 160, _startPosY + 40); g.DrawLine(pen, _startPosX + 130, _startPosY + 55, _startPosX + 160, _startPosY + 40); g.DrawLine(pen, _startPosX + 130, _startPosY + 40, _startPosX + 160, _startPosY + 40); //иллюминаторы g.DrawEllipse(pen, _startPosX + 40, _startPosY + 30, 10, 10); g.DrawEllipse(pen, _startPosX + 60, _startPosY + 30, 10, 10); g.DrawEllipse(pen, _startPosX + 80, _startPosY + 30, 10, 10); //крыло сбоку g.DrawEllipse(pen, _startPosX + 35, _startPosY + 43, 80, 7); //ножки снизу g.DrawLine(pen, _startPosX + 65, _startPosY + 55, _startPosX + 65, _startPosY + 70); g.DrawLine(pen, _startPosX + 70, _startPosY + 55, _startPosX + 70, _startPosY + 70); g.DrawLine(pen, _startPosX + 125, _startPosY + 55, _startPosX + 125, _startPosY + 70); g.DrawLine(pen, _startPosX + 130, _startPosY + 55, _startPosX + 130, _startPosY + 70); //лодка или колеса if (EntityHydroplane.Boat) { g.DrawRectangle(pen, _startPosX + 55, _startPosY + 70, 100, 10); g.DrawLine(pen, _startPosX + 155, _startPosY + 70, _startPosX + 175, _startPosY + 70); g.DrawLine(pen, _startPosX + 175, _startPosY + 70, _startPosX + 155, _startPosY + 80); } else { g.DrawEllipse(pen, _startPosX + 60, _startPosY + 70, 15, 15); g.DrawEllipse(pen, _startPosX + 120, _startPosY + 70, 15, 15); } //поплавок if (EntityHydroplane.Bobber) { g.DrawEllipse(pen, _startPosX, _startPosY + 21, 32, 8); } } } }