using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tank { public class DrawningTank { public EntityTank? EntityTank { get; private set; } /// /// Ширина окна /// private int? _pictureWidth; /// /// Высота окна /// private int? _pictureHeight; /// /// Левая координата прорисовки автомобиля /// private int? _startPosX; /// /// Верхняя кооридната прорисовки автомобиля /// private int? _startPosY; /// /// Ширина прорисовки автомобиля /// private readonly int _drawningCarWidth = 110; /// /// Высота прорисовки автомобиля /// private readonly int _drawningCarHeight = 60; /// /// Инициализация свойств /// /// Скорость /// Вес /// Основной цвет /// Дополнительный цвет /// Признак наличия обвеса /// Признак наличия антикрыла /// Признак наличия гоночной полосы public void Init(int speed, double weight, Color bodyColor, Color additionalColor) { EntityTank = new EntityTank(); EntityTank.Init(speed, weight, bodyColor, additionalColor); _pictureWidth = null; _pictureHeight = null; _startPosX = null; _startPosY = null; } /// /// Установка границ поля /// /// Ширина поля /// Высота поля /// true - границы заданы, false - проверка не пройдена, нельзя // разместить объект в этих размерах public bool SetPictureSize(int width, int height) { // TODO проверка, что объект "влезает" в размеры поля // если влезает, сохраняем границы и корректируем позицию объекта, //если она была уже установлена _pictureWidth = width; _pictureHeight = height; return true; } /// /// Установка позиции /// /// Координата X /// Координата Y public void SetPosition(int x, int y) { if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) { return; } // TODO если при установке объекта в эти координаты, он будет // "выходить" за границы формы // то надо изменить координаты, чтобы он оставался в этих границах _startPosX = x; _startPosY = y; } /// /// Изменение направления перемещения /// /// Направление /// true - перемещене выполнено, false - перемещение //невозможно public bool MoveTransport(DirectionType direction) { if (EntityTank == null || !_startPosX.HasValue || !_startPosY.HasValue) { return false; } switch (direction) { //влево case DirectionType.Left: if (_startPosX.Value - EntityTank.Step > 0) { _startPosX -= (int)EntityTank.Step; } return true; //вверх case DirectionType.Up: if (_startPosY.Value - EntityTank.Step > 0) { _startPosY -= (int)EntityTank.Step; } return true; // вправо case DirectionType.Right: if (_startPosX.Value + EntityTank.Step < 900) { _startPosX += (int)EntityTank.Step; } return true; //вниз case DirectionType.Down: if (_startPosY.Value + EntityTank.Step < 500) { _startPosY += (int)EntityTank.Step; } //TODO прописать логику сдвига в вниз return true; default: return false; } } /// /// Прорисовка объекта /// /// public void DrawTransport(Graphics g) { if (EntityTank == null || !_startPosX.HasValue || !_startPosY.HasValue) { return; } Pen pen = new(Color.Black); Brush additionalBrush = new SolidBrush(EntityTank.AdditionalColor); Brush brGreen = new SolidBrush(Color.Green); g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value, 130, 70); g.DrawEllipse(pen, _startPosX.Value + 60, _startPosY.Value + 20, 30, 30); g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 20, _startPosX.Value + 140, _startPosY.Value + 20); g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 50, _startPosX.Value + 140, _startPosY.Value + 50); /*g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value, 40, 40);*/ g.FillRectangle(brGreen, _startPosX.Value + 11, _startPosY.Value + 1, 129, 19); g.FillRectangle(brGreen, _startPosX.Value + 11, _startPosY.Value + 51, 129, 19); g.FillRectangle(additionalBrush, _startPosX.Value + 11, _startPosY.Value + 21, 29, 29); g.FillRectangle(additionalBrush, _startPosX.Value + 111, _startPosY.Value + 21, 29, 29); g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 20, 70, 30); g.FillRectangle(brGreen, _startPosX.Value + 41, _startPosY.Value + 21, 69, 29); g.FillEllipse(additionalBrush, _startPosX.Value + 60, _startPosY.Value + 20, 30, 30); g.DrawEllipse(pen, _startPosX.Value + 60, _startPosY.Value + 20, 30, 30); g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 30, 100, 10); g.FillRectangle(brGreen, _startPosX.Value + 91, _startPosY.Value + 31, 99, 9); /*g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value, 40, 40); g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value + 45, 15, 15);*/ } } }