From 0991e912058cf18aa032f268dee952c8342ae00a Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 25 Sep 2022 19:41:17 +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 --- Locomotive/Locomotive/DrawningLocomotive.cs | 5 +++ .../Locomotive/DrawningObjectLocomotive.cs | 40 +++++++++++++++++++ Locomotive/Locomotive/IDrawningObject.cs | 22 ++++++++++ 3 files changed, 67 insertions(+) create mode 100644 Locomotive/Locomotive/DrawningObjectLocomotive.cs create mode 100644 Locomotive/Locomotive/IDrawningObject.cs diff --git a/Locomotive/Locomotive/DrawningLocomotive.cs b/Locomotive/Locomotive/DrawningLocomotive.cs index 1d24b24..d89816b 100644 --- a/Locomotive/Locomotive/DrawningLocomotive.cs +++ b/Locomotive/Locomotive/DrawningLocomotive.cs @@ -142,5 +142,10 @@ namespace Locomotive _startPosY = _pictureHeight.Value - _locomotiveHeight; } } + // Получение текущей позиции объекта + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosY, _startPosX + _locomotiveWidth, _startPosY + _locomotiveHeight); + } } } diff --git a/Locomotive/Locomotive/DrawningObjectLocomotive.cs b/Locomotive/Locomotive/DrawningObjectLocomotive.cs new file mode 100644 index 0000000..389e9c8 --- /dev/null +++ b/Locomotive/Locomotive/DrawningObjectLocomotive.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal class DrawningObjectLocomotive : IDrawningObject + { + private DrawningLocomotive _locomotive = null; + + public DrawningObjectLocomotive(DrawningLocomotive locomotive) + { + _locomotive = locomotive; + } + + public float Step => _locomotive?.Locomotive?.Step ?? 0; + + public void DrawningObject(Graphics g) + { + _locomotive?.DrawTransport(g); + } + + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return _locomotive?.GetCurrentPosition() ?? default; + } + + public void MoveObject(Direction direction) + { + _locomotive?.MoveTransport(direction); + } + + public void SetObject(int x, int y, int width, int height) + { + _locomotive?.SetPosition(x, y, width, height); + } + } +} diff --git a/Locomotive/Locomotive/IDrawningObject.cs b/Locomotive/Locomotive/IDrawningObject.cs new file mode 100644 index 0000000..ad04e9e --- /dev/null +++ b/Locomotive/Locomotive/IDrawningObject.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal interface IDrawningObject + { + /// Шаг перемещения объекта + public float Step { get; } + /// Установка позиции объекта + void SetObject(int x, int y, int width, int height); + /// Изменение направления перемещения объекта + void MoveObject(Direction direction); + /// Отрисовка объекта + void DrawningObject(Graphics g); + /// Получение текущей позиции объекта + (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); + } +}