From 12ba5a0148ba7f9a64e3b0043bab32b54fd906e3 Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 22:08:25 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20IMoveableObject,=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B5=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20=D0=B2=20DrawningAirPlan?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirPlane.cs | 71 ++++++++++++++++++++++++- AirBomber/AirBomber/EntityAirPlane.cs | 1 + AirBomber/AirBomber/IMoveableObject.cs | 12 +++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 AirBomber/AirBomber/IMoveableObject.cs diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index f746d98..c9af062 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -215,6 +215,75 @@ namespace AirBomber } ); } - + /// + /// Координата X объекта + /// + public int GetPosX => _startPosX; + /// + /// Координата Y объекта + /// + public int GetPosY => _startPosY; + /// + /// Ширина объекта + /// + public int GetWidth => _airPlaneWidth; + /// + /// Высота объекта + /// + public int GetHeight => _airPlaneHeight; + /// + /// Проверка, что объект может переместится по указанному направлению + /// + /// Направление + /// true - можно переместится по указанному направлению + public bool CanMove(DirectionType direction) + { + if (EntityAirPlane == null) + { + return false; + } + return direction switch + { + //влево + DirectionType.Left => _startPosX - EntityAirPlane.Step > 0, + //вверх + DirectionType.Up => _startPosY - EntityAirPlane.Step > 0, + // вправо + DirectionType.Right => false,// TODO: Продумать логику + //вниз + DirectionType.Down => false,// TODO: Продумать логику + _ => false, + }; + } + /// + /// Изменение направления перемещения + /// + /// Направление + public void MovePlane(DirectionType direction) + { + if (!CanMove(direction) || EntityAirPlane == null) + { + return; + } + switch (direction) + { + //влево + case DirectionType.Left: + _startPosX -= (int)EntityAirPlane.Step; + break; + //вверх + case DirectionType.Up: + _startPosY -= (int)EntityAirPlane.Step; + break; + // вправо + case DirectionType.Right: + _startPosX += (int)EntityAirPlane.Step; + break; + //вниз + case DirectionType.Down: + _startPosY += (int)EntityAirPlane.Step; + break; + } + } } } diff --git a/AirBomber/AirBomber/EntityAirPlane.cs b/AirBomber/AirBomber/EntityAirPlane.cs index d0f206c..8934f22 100644 --- a/AirBomber/AirBomber/EntityAirPlane.cs +++ b/AirBomber/AirBomber/EntityAirPlane.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using AirBomber; namespace AirBomber { diff --git a/AirBomber/AirBomber/IMoveableObject.cs b/AirBomber/AirBomber/IMoveableObject.cs new file mode 100644 index 0000000..9cc5cfd --- /dev/null +++ b/AirBomber/AirBomber/IMoveableObject.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal interface IMoveableObject + { + } +}