From 987cd86208620f5fd0672297ba9753d3249503d2 Mon Sep 17 00:00:00 2001 From: ivans Date: Wed, 13 Mar 2024 14:11:20 +0400 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=BA=D0=BE=D0=BD=D1=87=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=9B=D0=B0=D0=B1=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/EntityBasicSeaplane.cs | 2 +- .../Entities/EntitySeaplane.cs | 5 +-- .../ProjectSeaplane/FormSeaplane.cs | 30 ++++++------- .../MovementStrategy/IMoveableObject.cs | 4 +- .../MovementStrategy/MoveToBorder.cs | 42 ++++++++++++++++++- .../MovementStrategy/MoveableSeaplane.cs | 15 ++----- 6 files changed, 63 insertions(+), 35 deletions(-) diff --git a/ProjectSeaplane/ProjectSeaplane/Entities/EntityBasicSeaplane.cs b/ProjectSeaplane/ProjectSeaplane/Entities/EntityBasicSeaplane.cs index 3a4326b..ac8659e 100644 --- a/ProjectSeaplane/ProjectSeaplane/Entities/EntityBasicSeaplane.cs +++ b/ProjectSeaplane/ProjectSeaplane/Entities/EntityBasicSeaplane.cs @@ -26,7 +26,7 @@ public class EntityBasicSeaplane /// Скорость /// Вес /// Основной цвет - Random random = new(); + public EntityBasicSeaplane(int speed, double weight, Color bodyColor) { Speed = speed; diff --git a/ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs b/ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs index 5b02c47..45d0ba0 100644 --- a/ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs +++ b/ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs @@ -25,14 +25,13 @@ public class EntitySeaplane : EntityBasicSeaplane /// Дополнительный цвет /// Тип "шасси" /// При - Random random = new(); - public EntitySeaplane(int speed, double weight, Color bodyColor, Color additionalColor, bool landingGear, bool radar) : base(0, 0, Color.Brown) + + public EntitySeaplane(int speed, double weight, Color bodyColor, Color additionalColor, bool landingGear, bool radar) : base(speed, weight, bodyColor) { AdditionalColor = additionalColor; LandingGear = landingGear; Radar = radar; - } } diff --git a/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs index f803de0..485c1b8 100644 --- a/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs +++ b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs @@ -19,7 +19,7 @@ namespace ProjectSeaplane /// /// Поле-объект для прорисовки объекта /// - private DrawingBasicSeaplane? _drawingBasicSeaplane; + private DrawingBasicSeaplane? _drawingSeaplane; /// /// Стратегия перемещения /// @@ -29,14 +29,14 @@ namespace ProjectSeaplane /// private void Draw() { - if (_drawingBasicSeaplane == null) + if (_drawingSeaplane == null) { return; } Bitmap bmp = new(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); Graphics gr = Graphics.FromImage(bmp); - _drawingBasicSeaplane.DrawTransport(gr); + _drawingSeaplane.DrawTransport(gr); pictureBoxSeaplane.Image = bmp; } /// @@ -51,20 +51,20 @@ namespace ProjectSeaplane switch (type) { case nameof(DrawingBasicSeaplane): - _drawingBasicSeaplane = new DrawingBasicSeaplane(random.Next(100, 300), random.Next(1000, 3000), + _drawingSeaplane = new DrawingBasicSeaplane(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); break; case nameof(DrawingSeaplane): - _drawingBasicSeaplane = new DrawingSeaplane(random.Next(100, 300), random.Next(1000, 3000), + _drawingSeaplane = new DrawingSeaplane(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Convert.ToBoolean(random.Next(1, 2)), Convert.ToBoolean(random.Next(1, 2))); + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; default: return; } - _drawingBasicSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); - _drawingBasicSeaplane.SetPosition(random.Next(10, 100), random.Next(10, 100)); + _drawingSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); + _drawingSeaplane.SetPosition(random.Next(10, 100), random.Next(10, 100)); _strategy = null; comboBoxStrategy.Enabled = true; Draw(); @@ -94,7 +94,7 @@ namespace ProjectSeaplane /// private void ButtonMove_Click(object sender, EventArgs e) { - if (_drawingBasicSeaplane == null) + if (_drawingSeaplane == null) { return; } @@ -104,16 +104,16 @@ namespace ProjectSeaplane switch (name) { case "buttonUp": - result = _drawingBasicSeaplane.MoveTransport(DirectionType.Up); + result = _drawingSeaplane.MoveTransport(DirectionType.Up); break; case "buttonDown": - result = _drawingBasicSeaplane.MoveTransport(DirectionType.Down); + result = _drawingSeaplane.MoveTransport(DirectionType.Down); break; case "buttonLeft": - result = _drawingBasicSeaplane.MoveTransport(DirectionType.Left); + result = _drawingSeaplane.MoveTransport(DirectionType.Left); break; case "buttonRight": - result = _drawingBasicSeaplane.MoveTransport(DirectionType.Right); + result = _drawingSeaplane.MoveTransport(DirectionType.Right); break; } @@ -129,7 +129,7 @@ namespace ProjectSeaplane /// private void buttonStrategyStep_Click(object sender, EventArgs e) { - if (_drawingBasicSeaplane == null) + if (_drawingSeaplane == null) { return; } @@ -146,7 +146,7 @@ namespace ProjectSeaplane { return; } - _strategy.SetData(new MoveableSeaplane(_drawingBasicSeaplane), pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); + _strategy.SetData(new MoveableSeaplane(_drawingSeaplane), pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); } if (_strategy == null) diff --git a/ProjectSeaplane/ProjectSeaplane/MovementStrategy/IMoveableObject.cs b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/IMoveableObject.cs index d3351a9..a90216a 100644 --- a/ProjectSeaplane/ProjectSeaplane/MovementStrategy/IMoveableObject.cs +++ b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/IMoveableObject.cs @@ -1,6 +1,4 @@ - - -namespace ProjectSeaplane.MovementStrategy; +namespace ProjectSeaplane.MovementStrategy; /// /// Интерфейс для работы с перемещаемым объектом diff --git a/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveToBorder.cs b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveToBorder.cs index c93abbd..1ed6789 100644 --- a/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveToBorder.cs +++ b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveToBorder.cs @@ -4,11 +4,49 @@ public class MoveToBorder : AbstractStrategy { protected override bool IsTargetDestinaion() { - throw new NotImplementedException(); + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return false; + } + return objParams.RightBorder <= FieldWidth && + objParams.RightBorder + GetStep() >= FieldWidth && + objParams.DownBorder <= FieldHeight && + objParams.DownBorder + GetStep() >= FieldHeight; } protected override void MoveToTarget() { - throw new NotImplementedException(); + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return; + } + int diffX = objParams.RightBorder - FieldWidth; + if (Math.Abs(diffX) > GetStep()) + { + + if (diffX > 0) + { + MoveLeft(); + } + if (diffX < 0) + { + MoveRight(); + } + } + int diffY = objParams.DownBorder - FieldWidth; + if (Math.Abs(diffY) > GetStep()) + { + + if (diffX > 0) + { + MoveUp(); + } + if (diffY < 0) + { + MoveDown(); + } + } } } diff --git a/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveableSeaplane.cs b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveableSeaplane.cs index 746172a..260cf7b 100644 --- a/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveableSeaplane.cs +++ b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveableSeaplane.cs @@ -12,24 +12,17 @@ public class MoveableSeaplane : IMoveableObject /// /// Поле-объект класса Seaplane или его наследника /// - private readonly DrawingSeaplane? _seaplane = null; + private readonly DrawingBasicSeaplane? _seaplane = null; /// /// Конструктор /// /// Объект класса Seaplane - public MoveableSeaplane(DrawingSeaplane seaplane) + public MoveableSeaplane(DrawingBasicSeaplane Seaplane) { - _seaplane = seaplane; + _seaplane = Seaplane; } - /// - /// АВТОКОРРЕКЦИЯ - /// - /// - public MoveableSeaplane(DrawingBasicSeaplane drawingBasicSeaplane) - { - } - + public ObjectParameters? GetObjectPosition { get