From 2a48e6436c99b074df4fe891c176a7457a1c78f4 Mon Sep 17 00:00:00 2001 From: Marselchi Date: Mon, 25 Sep 2023 14:04:52 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=B0=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Liner/Drawing/DrawingLiner.cs | 23 ++++++++++++++++++++ Liner/MovingStrategies/DrawingObjectLiner.cs | 1 + 2 files changed, 24 insertions(+) diff --git a/Liner/Drawing/DrawingLiner.cs b/Liner/Drawing/DrawingLiner.cs index 04a9047..6a11ae7 100644 --- a/Liner/Drawing/DrawingLiner.cs +++ b/Liner/Drawing/DrawingLiner.cs @@ -151,6 +151,29 @@ namespace Liner.Drawing }; } /// + /// Проверка, что объект может переместится по указанному направлению + /// + /// Направление + /// true - можно переместится по указанному направлению + public bool CanMove(DirectionType direction) + { + if (EntityLiner == null) + { + return false; + } + return direction switch + { + //влево + DirectionType.Left => _startPosX - EntityLiner.Step > 0, + //вверх + DirectionType.Up => _startPosY - EntityLiner.Step > 0, + //вправо + DirectionType.Right => _startPosX + EntityLiner.Step + _linerWidth < _pictureWidth, + //вниз + DirectionType.Down => _startPosY + EntityLiner.Step + _linerHeight < _pictureHeight + }; + } + /// /// Изменение направления перемещения /// /// Направление diff --git a/Liner/MovingStrategies/DrawingObjectLiner.cs b/Liner/MovingStrategies/DrawingObjectLiner.cs index 0afe82d..aa00f5c 100644 --- a/Liner/MovingStrategies/DrawingObjectLiner.cs +++ b/Liner/MovingStrategies/DrawingObjectLiner.cs @@ -35,4 +35,5 @@ namespace Liner.MovingStrategies public void MoveObject(DirectionType direction) => _drawingLiner?.MoveTransport(direction); } + }