using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; using System.Threading.Tasks; using PIbd_21_Potapov_N.S._Catamaran_Base; namespace PIbd_21_Potapov_N.S._Catamaran_Base { /// /// Класс, отвечающий за прорисовку и перемещение объекта-сущности /// internal class DrawingCatamaran { /// /// Класс-сущность /// public EntityCatamaran Catamaran { protected set; get; } /// /// Левая координата отрисовки катамарана /// private float _startPosX; /// /// Верхняя кооридната отрисовки катамарана /// private float _startPosY; /// /// Ширина окна отрисовки /// private int? _pictureWidth = null; /// /// Высота окна отрисовки /// private int? _pictureHeight = null; /// /// Ширина отрисовки катамарана /// private readonly int _catamaranWidth = 100; /// /// Высота отрисовки катамарана /// private readonly int _catamaranHeight = 40; /// /// Инициализация свойств /// /// Скорость /// Вес катамарана /// Цвет корпуса public void Init(int speed, float weight, Color bodyColor) { Catamaran = new EntityCatamaran(); Catamaran.Init(speed, weight, bodyColor); } /// /// Установка позиции катамарана /// /// Координата X /// Координата Y /// Ширина картинки /// Высота картинки public void SetPosition(int x, int y, int width, int height) { // TODO проверки _startPosX = x; _startPosY = y; _pictureWidth = width; _pictureHeight = height; } /// /// Изменение направления перемещения /// /// Направление public void MoveTransport(Direction direction) { if (!_pictureWidth.HasValue || !_pictureHeight.HasValue) { return; } switch (direction) { // вправо case Direction.Right: if (_startPosX + _catamaranWidth + Catamaran.Step < _pictureWidth) { _startPosX += Catamaran.Step; } break; //влево case Direction.Left: if (_startPosX - Catamaran.Step > 0) { _startPosX -= Catamaran.Step; } break; //вверх case Direction.Up: if (_startPosY - Catamaran.Step > 0) { _startPosY -= Catamaran.Step; } break; //вниз case Direction.Down: if (_startPosY + _catamaranHeight + Catamaran.Step < _pictureHeight) { _startPosY += Catamaran.Step; } break; } } /// /// Отрисовка катамарана /// /// public void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) { return; } SolidBrush brush = new SolidBrush(Catamaran.BodyColor); PointF[] bodyPoints = new PointF[5]; bodyPoints[0] = new PointF(_startPosX, _startPosY); bodyPoints[1] = new PointF(_startPosX + _catamaranWidth - _catamaranWidth / 4, _startPosY); bodyPoints[2] = new PointF(_startPosX + _catamaranWidth, _startPosY + _catamaranHeight / 2); bodyPoints[3] = new PointF(_startPosX + _catamaranWidth - _catamaranWidth / 4, _startPosY + _catamaranHeight); bodyPoints[4] = new PointF(_startPosX, _startPosY + _catamaranHeight); // Отрисовка корпуса катамарана g.FillPolygon(brush, bodyPoints); g.DrawPolygon(Pens.Black, bodyPoints); // Отрисовка головы катамарана g.FillEllipse(Brushes.White, _startPosX + _catamaranWidth / 8, _startPosY + _catamaranHeight / 8, _catamaranWidth / 2, _catamaranHeight - _catamaranHeight / 4); g.DrawEllipse(Pens.Black, _startPosX + _catamaranWidth / 8, _startPosY + _catamaranHeight / 8, _catamaranWidth / 2, _catamaranHeight - _catamaranHeight / 4); } } }