namespace Seaplane; /// /// Класс отвечающий за прорисовку и перемещение объекта - сущности /// public class DrawingSeaplane { /// /// Класс - сущность /// public EntitySeaplane? EntitySeaplane { get; set; } /// /// Ширина окна /// private int? _pictureWidth; /// /// Высота окна /// private int? _pictureHeight; /// /// Левая координата прорисовки гидросамолета /// private int? _startPosX; /// /// Верхняя координата прорисовки гидросамолета /// private int? _startPosY; /// /// Ширина прорисовки гидросамолета /// private readonly int _drawningPlaneWidth = 0; /// /// Высота прорисовки гидросамолета /// private readonly int _drawningPlaneHeight = 0; /// /// Инициализация полей объекта-класса гидросамолета /// /// Скорость /// Вес /// Основной цвет /// Дополнительный цвет /// Наличие обвеса /// Наличие поплавков /// Наличие надувной лодки public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine) { EntitySeaplane = new EntitySeaplane(); EntitySeaplane.Init(speed, weight, bodyColor, additionalColor, bodyKit, wing, sportLine); _pictureWidth = null; _pictureHeight = null; _startPosX = null; _startPosY = null; } public bool SetPictureSize(int width, int height) { // TODO проверка, что объект "влезает" в размеры поля // если влезает, сохраняем границы и корректируем позицию объекта,если она была уже установлена if (width < _drawningPlaneWidth || height < _drawningPlaneHeight) return false; _pictureWidth = width; _pictureHeight = height; if (_startPosX != null || _startPosY != null) { if (_startPosX + _drawningPlaneWidth > _pictureWidth) { _startPosX = _startPosX - (_startPosX + _drawningPlaneWidth - _pictureWidth); } else if (_startPosX < 0) _startPosX = 0; if (_startPosY + _drawningPlaneHeight > _pictureHeight) { _startPosY = _startPosY - (_startPosY + _drawningPlaneHeight - _pictureHeight); } else if (_startPosY < 0) _startPosY = 0; } return true; } /// /// Установка позиций /// /// /// public void SetPosition(int x, int y) { if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) { return; } // TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы // то надо изменить координаты, чтобы он оставался в этих границах if (x + _drawningPlaneWidth > _pictureWidth) { _startPosX = x - (x + _drawningPlaneWidth - _pictureWidth); } else if (x < 0) _startPosX = 0; else _startPosX = x; if (y + _drawningPlaneHeight > _pictureHeight) { _startPosY = y - (y + _drawningPlaneHeight - _pictureHeight); } else if (y < 0) _startPosY = 0; else _startPosY = y; } /// /// Изменение направления перемещения /// /// /// public bool MoveTransport(DirectionType direction) { if (EntitySeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue) { return false; } switch (direction) { //влево case DirectionType.Left: if (_startPosX.Value - EntitySeaplane.Step > 0) { _startPosX -= (int)EntitySeaplane.Step; } return true; //вверх case DirectionType.Up: if (_startPosY.Value - EntitySeaplane.Step > 0) { _startPosY -= (int)EntitySeaplane.Step; } return true; // вправо case DirectionType.Right: if (_startPosX.Value + _drawningPlaneWidth + EntitySeaplane.Step < _pictureWidth) { _startPosX += (int)EntitySeaplane.Step; } return true; //вниз case DirectionType.Down: if (_startPosY.Value + _drawningPlaneHeight + EntitySeaplane.Step < _pictureHeight) { _startPosY += (int)EntitySeaplane.Step; } return true; default: return false; } } public void DrawTransport(Graphics g) { if (EntitySeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue) { return; } } }