From b7a3f41598d0353487a69613d25b60954a67e23a Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Mon, 25 Sep 2023 23:29:14 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B2=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B5=20=D0=BE=D1=82?= =?UTF-8?q?=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=BE=D0=B3=D0=BE=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectStormtrooper/DrawingPlane.cs | 62 ++++++++++++++----- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/ProjectStormtrooper/ProjectStormtrooper/DrawingPlane.cs b/ProjectStormtrooper/ProjectStormtrooper/DrawingPlane.cs index a37f4e1..7186346 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/DrawingPlane.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/DrawingPlane.cs @@ -40,6 +40,22 @@ namespace ProjectStormtrooper /// protected readonly int _planeHeight = 110; /// + /// Координата X объекта + /// + public int GetPosX => _startPosX; + /// + /// Координата Y объекта + /// + public int GetPosY => _startPosY; + /// + /// Ширина объекта + /// + public int GetWidth => _planeWidth; + /// + /// Высота объекта + /// + public int GetHeight => _planeHeight; + /// /// Конструктор /// /// Скорость @@ -81,6 +97,30 @@ namespace ProjectStormtrooper EntityPlane = new EntityPlane(speed, weight, bodyColor); } /// + /// Проверка, что объект может переместится по указанному направлению + /// + /// Направление + /// true - можно переместится по указанному направлению + public bool CanMove(DirectionType direction) + { + if (EntityPlane == null) + { + return false; + } + return direction switch + { + //вверх + DirectionType.Up => _startPosY - EntityPlane.Step > 0, + //вниз + DirectionType.Down => _startPosY + _planeHeight + EntityPlane.Step < _pictureHeight, + //влево + DirectionType.Left => _startPosX - EntityPlane.Step > 0, + //вправо + DirectionType.Right => _startPosX + _planeWidth + EntityPlane.Step < _pictureWidth, + _ => false, + }; + } + /// /// Установка позиции /// /// Координата X @@ -113,7 +153,7 @@ namespace ProjectStormtrooper /// Направление перемещения public void MoveTransport(DirectionType direction) { - if (EntityPlane == null) + if (!CanMove(direction) || EntityPlane == null) { return; } @@ -121,31 +161,19 @@ namespace ProjectStormtrooper { // Вверх case DirectionType.Up: - if (_startPosY - EntityPlane.Step >= 0) - { - _startPosY -= (int)EntityPlane.Step; - } + _startPosY -= (int)EntityPlane.Step; break; // Вниз case DirectionType.Down: - if (_startPosY + _planeHeight + EntityPlane.Step <= _pictureHeight) - { - _startPosY += (int)EntityPlane.Step; - } + _startPosY += (int)EntityPlane.Step; break; // Влево case DirectionType.Left: - if (_startPosX - EntityPlane.Step >= 0) - { - _startPosX -= (int)EntityPlane.Step; - } + _startPosX -= (int)EntityPlane.Step; break; // Вправо case DirectionType.Right: - if (_startPosX + _planeWidth + EntityPlane.Step <= _pictureWidth) - { - _startPosX += (int)EntityPlane.Step; - } + _startPosX += (int)EntityPlane.Step; break; } }