From 0552a911e0bdd3fc24ee09ab9a7c8f445ca3722e Mon Sep 17 00:00:00 2001 From: "v.ignatkin" Date: Fri, 14 Feb 2025 17:50:02 +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=D1=80=D0=BE=D0=B4=D0=B8=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=B9=20=D0=B8=20=D0=B2=D0=B2=D0=BE=D0=B4=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D0=BE=D1=80=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Drawnings/DrawningBattleship.cs | 3 +- .../Battleship/Drawnings/DrawningShip.cs | 32 +++++++++++++++---- .../Battleship/Entities/EntityBattleship.cs | 2 +- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Battleship/Battleship/Drawnings/DrawningBattleship.cs b/Battleship/Battleship/Drawnings/DrawningBattleship.cs index deb60b5..e6e743c 100644 --- a/Battleship/Battleship/Drawnings/DrawningBattleship.cs +++ b/Battleship/Battleship/Drawnings/DrawningBattleship.cs @@ -26,6 +26,7 @@ public class DrawningBattleship : DrawningShip public override void DrawTransport(Graphics g) { + base.DrawTransport(g); if (EntityShip == null || EntityShip is not EntityBattleship battleShip || !_startPosX.HasValue || !_startPosY.HasValue) { return; @@ -111,7 +112,7 @@ public class DrawningBattleship : DrawningShip g.DrawRectangle(pen, x + 119, y + 24, 12, 2); } - base.DrawTransport(g); + } } diff --git a/Battleship/Battleship/Drawnings/DrawningShip.cs b/Battleship/Battleship/Drawnings/DrawningShip.cs index 0dc210e..7a3aa1b 100644 --- a/Battleship/Battleship/Drawnings/DrawningShip.cs +++ b/Battleship/Battleship/Drawnings/DrawningShip.cs @@ -32,7 +32,7 @@ namespace Battleship.Drawnings /// Ширина прорисовки корабля /// - private readonly int _drawningShipWidth = 130; + private readonly int _drawningShipWidth = 145; /// /// Высота прорисовки корабля /// @@ -80,9 +80,13 @@ namespace Battleship.Drawnings /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах public bool SetPictureSize(int width, int height) { - _pictureWidth = width; - _pictureHeight = height; - return true; + if (width >= _drawningShipWidth || height >= _drawningShipHeight) + { + _pictureWidth = width; + _pictureHeight = height; + return true; + } + return false; } /// /// Установка позиции @@ -91,10 +95,26 @@ namespace Battleship.Drawnings /// Координата Y public void SetPosition(int x, int y) { - if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) + if (x < 0) { - return; + x = 0; } + else if (x + _drawningShipWidth > _pictureWidth.Value) + { + x = _pictureWidth.Value - _drawningShipWidth; + } + + if (y < 0) + { + y = 0; + } + else if (y + _drawningShipHeight > _pictureHeight.Value) + { + y = _pictureHeight.Value - _drawningShipHeight; + } + + + _startPosX = x; _startPosY = y; } diff --git a/Battleship/Battleship/Entities/EntityBattleship.cs b/Battleship/Battleship/Entities/EntityBattleship.cs index 8ed0183..d7f0a08 100644 --- a/Battleship/Battleship/Entities/EntityBattleship.cs +++ b/Battleship/Battleship/Entities/EntityBattleship.cs @@ -42,7 +42,7 @@ /// Дополнительный цвет /// Признак наличия орудийной башни /// Признак наличия отсека под ракеты - ///Признак наличия отсека под ракеты + ///Признак наличия оружия public EntityBattleship(int speed, double weight, Color bodyColor, Color additionalColor, bool turret, bool rocketCompartment, bool weapon) : base(speed, weight, bodyColor) {