From 52f9190f2fad132eb3b766ef4ac7d274c332df40 Mon Sep 17 00:00:00 2001 From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com> Date: Fri, 4 Nov 2022 13:34:29 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5?= =?UTF-8?q?=D0=B9=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Boats/Boats/DrawingBoat.cs | 10 +++++++- Boats/Boats/DrawingObjectBoat.cs | 34 ++++++++++++++++++++++++++ Boats/Boats/IDrawingObject.cs | 42 ++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 Boats/Boats/DrawingObjectBoat.cs create mode 100644 Boats/Boats/IDrawingObject.cs diff --git a/Boats/Boats/DrawingBoat.cs b/Boats/Boats/DrawingBoat.cs index fb44500..e9b3975 100644 --- a/Boats/Boats/DrawingBoat.cs +++ b/Boats/Boats/DrawingBoat.cs @@ -154,7 +154,7 @@ namespace Boats g.DrawEllipse(Pens.Black, _startPosX + _boatWidth / 8, _startPosY + _boatHeight / 8, _boatWidth / 2, _boatHeight - _boatHeight / 4); } - /// + /// /// Смена границ формы отрисовки /// /// Ширина картинки @@ -178,5 +178,13 @@ namespace Boats _startPosY = _pictureHeight.Value - _boatHeight; } } + /// + /// Получение текущей позиции объекта + /// + /// + public (float Left, float Top, float Right, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosY, _startPosX + _boatWidth, _startPosY + _boatHeight); + } } } diff --git a/Boats/Boats/DrawingObjectBoat.cs b/Boats/Boats/DrawingObjectBoat.cs new file mode 100644 index 0000000..5ca71f6 --- /dev/null +++ b/Boats/Boats/DrawingObjectBoat.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boats +{ + internal class DrawingObjectBoat : IDrawingObject + { + private DrawingBoat _boat = null; + public DrawingObjectBoat(DrawingBoat boat) + { + _boat = boat; + } + public float Step => _boat?.Boat?.Step ?? 0; + public (float Left, float Top, float Right, float Bottom) GetCurrentPosition() + { + return _boat?.GetCurrentPosition() ?? default; + } + public void MoveObject(Direction direction) + { + _boat?.MoveTransport(direction); + } + public void SetObject(int x, int y, int width, int height) + { + _boat.SetPosition(x, y, width, height); + } + public void DrawingObject(Graphics g) + { + _boat.DrawTransport(g); + } + } +} diff --git a/Boats/Boats/IDrawingObject.cs b/Boats/Boats/IDrawingObject.cs new file mode 100644 index 0000000..8ba69e3 --- /dev/null +++ b/Boats/Boats/IDrawingObject.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boats +{ + /// + /// Интерфейс для работы с объектом, прорисовываемым на форме + /// + internal interface IDrawingObject + { + /// + /// Шаг перемещения объекта + /// + public float Step { get; } + /// + /// Установка позиции объекта + /// + /// Координата X + /// Координата Y + /// Ширина полотна + /// Высота полотна + void SetObject(int x, int y, int width, int height); + /// + /// Изменение направления пермещения объекта + /// + /// Направление + void MoveObject(Direction direction); + /// + /// Отрисовка объекта + /// + /// + void DrawingObject(Graphics g); + /// + /// Получение текущей позиции объекта + /// + /// + (float Left, float Top, float Right, float Bottom) GetCurrentPosition(); + } +}