From 19122ab5594747fd8c5eed1d7d861b5c9cc2bdf7 Mon Sep 17 00:00:00 2001 From: xom9kxom9k Date: Sun, 11 Feb 2024 12:37:25 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Seaplane/DrawingSeaplane.cs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Seaplane/DrawingSeaplane.cs b/Seaplane/DrawingSeaplane.cs index 336d5c2..7af95ab 100644 --- a/Seaplane/DrawingSeaplane.cs +++ b/Seaplane/DrawingSeaplane.cs @@ -51,6 +51,12 @@ public class DrawingSeaplane _startPosX = null; _startPosY = null; } + /// + /// Установка границ поля + /// + /// + /// + /// public bool SetPictureSize(int width, int height) { // TODO проверка, что объект "влезает" в размеры поля @@ -86,12 +92,14 @@ public class DrawingSeaplane /// public void SetPosition(int x, int y) { + + // TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы + // то надо изменить координаты, чтобы он оставался в этих границах if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) { return; } - // TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы - // то надо изменить координаты, чтобы он оставался в этих границах + if (x + _drawningPlaneWidth > _pictureWidth) { _startPosX = _pictureWidth - _drawningPlaneWidth; @@ -121,7 +129,7 @@ public class DrawingSeaplane /// /// Изменение направления перемещения /// - /// + /// Направление /// public bool MoveTransport(DirectionType direction) { @@ -131,34 +139,30 @@ public class DrawingSeaplane } 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; + case DirectionType.Up: //вверх + if (_startPosY - EntitySeaplane.Step > 0) + { + _startPosY -= (int)EntitySeaplane.Step; + } + return true; default: return false; }