From d3178c25818e2d65c99e5ec9b8025f66ebb61462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=B9=D0=B4=D0=B0=D1=80?= Date: Tue, 4 Oct 2022 00:53:40 +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 --- Battleship/Battleship/DrawningBattleship.cs | 8 ++++ .../Battleship/DrawningObjectBattleship.cs | 40 +++++++++++++++++ Battleship/Battleship/IDrawningObject.cs | 43 +++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 Battleship/Battleship/DrawningObjectBattleship.cs create mode 100644 Battleship/Battleship/IDrawningObject.cs diff --git a/Battleship/Battleship/DrawningBattleship.cs b/Battleship/Battleship/DrawningBattleship.cs index 5db407d..6bccbbd 100644 --- a/Battleship/Battleship/DrawningBattleship.cs +++ b/Battleship/Battleship/DrawningBattleship.cs @@ -203,5 +203,13 @@ namespace Battleship _startPosY = _pictureHeight.Value - _battleshipHeight; } } + /// + /// Получение текущей позиции объекта + /// + /// + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosX + _battleshipWidth, _startPosY, _startPosY + _battleshipHeight); + } } } diff --git a/Battleship/Battleship/DrawningObjectBattleship.cs b/Battleship/Battleship/DrawningObjectBattleship.cs new file mode 100644 index 0000000..57938c6 --- /dev/null +++ b/Battleship/Battleship/DrawningObjectBattleship.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Battleship +{ + internal class DrawningObjectBattleship : IDrawningObject + { + private DrawningBattleship _battleship = null; + + public DrawningObjectBattleship(DrawningBattleship battleship) + { + _battleship = battleship; + } + + public float Step => _battleship?.Battleship?.Step ?? 0; + + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return _battleship?.GetCurrentPosition() ?? default; + } + + public void MoveObject(Direction direction) + { + _battleship?.MoveTransport(direction); + } + + public void SetObject(int x, int y, int width, int height) + { + _battleship.SetPosition(x, y, width, height); + } + + void IDrawningObject.DrawningObject(Graphics g) + { + // TODO + } + } +} diff --git a/Battleship/Battleship/IDrawningObject.cs b/Battleship/Battleship/IDrawningObject.cs new file mode 100644 index 0000000..8749a76 --- /dev/null +++ b/Battleship/Battleship/IDrawningObject.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Battleship +{ + /// + /// Интерфейс для работы с объектом, прорисовываемым на форме + /// + internal interface IDrawningObject + { + /// + /// Шаг перемещения объекта + /// + public float Step { get; } + /// + /// Установка позиции объекта + /// + /// Координата X + /// Координата Y + /// Ширина полотна + /// Высота полотна + 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(); + } +}