From 4c46170f09575b985e6d2cb37ee4b374ed0d71bb Mon Sep 17 00:00:00 2001 From: YourDax Date: Sun, 15 Oct 2023 20:49:57 +0400 Subject: [PATCH] Fixed --- ...n.cs => AdvancedDrawingAntiAirCraftGun.cs} | 12 ++--- .../BaseDrawingAntiAirCraftGun.cs | 45 +++++++++---------- .../Enitites/EntityAdvancedAntiAircraftGun.cs | 4 +- .../AntiAirCraftGun/FormAntiAirCraftGun.cs | 2 +- .../MovementStrategy/BorderDirection.cs | 16 ------- .../DrawingObjectAntiAirCraftGun.cs | 16 +++---- 6 files changed, 39 insertions(+), 56 deletions(-) rename AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/{AdvancedDrawingAntAirCraftGun.cs => AdvancedDrawingAntiAirCraftGun.cs} (71%) delete mode 100644 AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/BorderDirection.cs diff --git a/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/AdvancedDrawingAntAirCraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/AdvancedDrawingAntiAirCraftGun.cs similarity index 71% rename from AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/AdvancedDrawingAntAirCraftGun.cs rename to AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/AdvancedDrawingAntiAirCraftGun.cs index e3eda87..8d28d7e 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/AdvancedDrawingAntAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/AdvancedDrawingAntiAirCraftGun.cs @@ -9,26 +9,26 @@ using static System.Windows.Forms.AxHost; namespace AntiAircraftGun.DrawingObjects { - public class AdvancedDrawingAntAirCraftGun : BaseDrawingAntiAirCraftGun + public class AdvancedDrawingAntiAirCraftGun : BaseDrawingAntiAirCraftGun { private Point[] points = new Point[4]; - public AdvancedDrawingAntAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor, Color dopColor, bool rocket,bool radar, int width, int height) : + public AdvancedDrawingAntiAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor, Color dopColor, bool rocket,bool radar, int width, int height) : base(speed, weight, bodyColor, additionalColor, width, height) { - EntityAntiAirСraftGun = new EntityAdvancedAntiAircraftGun(speed, weight, bodyColor, additionalColor, dopColor, rocket,radar); + AntiAirСraftGun = new EntityAdvancedAntiAirCraftGun(speed, weight, bodyColor, additionalColor, dopColor, rocket,radar); } public override void DrawTransport(Graphics g) { - if (EntityAntiAirСraftGun is not EntityAdvancedAntiAircraftGun advancedGun) + if (AntiAirСraftGun is not EntityAdvancedAntiAirCraftGun advancedGun) { return; } Pen pen = new Pen(Color.Black); - Brush bodyBrush = new SolidBrush(EntityAntiAirСraftGun.BodyColor); - Brush additionalBrush = new SolidBrush(EntityAntiAirСraftGun.AdditionalColor); + Brush bodyBrush = new SolidBrush(AntiAirСraftGun.BodyColor); + Brush additionalBrush = new SolidBrush(AntiAirСraftGun.AdditionalColor); base.DrawTransport(g); Brush dopBrush = new SolidBrush(advancedGun.DopColor); Pen dopPen = new Pen(advancedGun.DopColor); diff --git a/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs index 450f4f5..f4ba407 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs @@ -10,7 +10,7 @@ namespace AntiAircraftGun.DrawingObjects { public class BaseDrawingAntiAirCraftGun { - public EntityAntiAirCraftGun? EntityAntiAirСraftGun { get; protected set; } + public EntityAntiAirCraftGun? AntiAirСraftGun { get; protected set; } private readonly int _pictureWidth; private readonly int _pictureHeight; protected int _startPosX; @@ -22,7 +22,7 @@ namespace AntiAircraftGun.DrawingObjects { _pictureWidth = width; _pictureHeight = height; - EntityAntiAirСraftGun = new EntityAntiAirCraftGun(speed, weight, bodyColor, additionalColor); + AntiAirСraftGun = new EntityAntiAirCraftGun(speed, weight, bodyColor, additionalColor); } protected BaseDrawingAntiAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor, int width, int height, int carWidth, int carHeight) @@ -31,21 +31,20 @@ namespace AntiAircraftGun.DrawingObjects _pictureHeight = height; _zenitWidth = carWidth; _zenitHeight = carHeight; - EntityAntiAirСraftGun = new EntityAntiAirCraftGun(speed, weight, bodyColor, additionalColor); + AntiAirСraftGun = new EntityAntiAirCraftGun(speed, weight, bodyColor, additionalColor); } public void SetPosition(int x, int y) { - if (x < 0 || y < 0) + if (AntiAirСraftGun == null) return; + _startPosX = x; + _startPosY = y; + if (x < 0 || y < 0 || x + _zenitWidth >= _pictureWidth || y + _zenitHeight >= _pictureHeight) { - _startPosX = 10; - _startPosY = 10; - } - else - { - _startPosX = x; - _startPosY = y; + _startPosX = 1; + _startPosY = 1; } + } /// /// Координата X объекта @@ -71,20 +70,20 @@ namespace AntiAircraftGun.DrawingObjects /// true - можно переместится по указанному направлению public bool CanMove(DirectionType direction) { - if (EntityAntiAirСraftGun == null) + if (AntiAirСraftGun == null) { return false; } return direction switch { //влево - DirectionType.Left => _startPosX - EntityAntiAirСraftGun.Step > 0, + DirectionType.Left => _startPosX - AntiAirСraftGun.Step > 0, //вверх - DirectionType.Up => _startPosY - EntityAntiAirСraftGun.Step > 0, + DirectionType.Up => _startPosY - AntiAirСraftGun.Step > 0, // вправо - DirectionType.Right =>_startPosX + EntityAntiAirСraftGun.Step < _pictureWidth - 110, + DirectionType.Right =>_startPosX + AntiAirСraftGun.Step < _pictureWidth - 110, //вниз - DirectionType.Down => _startPosY + EntityAntiAirСraftGun.Step < _pictureHeight - 60, + DirectionType.Down => _startPosY + AntiAirСraftGun.Step < _pictureHeight - 60, _ => false, }; } @@ -94,7 +93,7 @@ namespace AntiAircraftGun.DrawingObjects /// Направление public void MoveTransport(DirectionType direction) { - if (!CanMove(direction) || EntityAntiAirСraftGun == null) + if (!CanMove(direction) || AntiAirСraftGun == null) { return; } @@ -102,19 +101,19 @@ namespace AntiAircraftGun.DrawingObjects { //влево case DirectionType.Left: - _startPosX -= (int)EntityAntiAirСraftGun.Step; + _startPosX -= (int)AntiAirСraftGun.Step; break; //вверх case DirectionType.Up: - _startPosY -= (int)EntityAntiAirСraftGun.Step; + _startPosY -= (int)AntiAirСraftGun.Step; break; // вправо case DirectionType.Right: - _startPosX += (int)EntityAntiAirСraftGun.Step; + _startPosX += (int)AntiAirСraftGun.Step; break; //вниз case DirectionType.Down: - _startPosY += (int)EntityAntiAirСraftGun.Step; + _startPosY += (int)AntiAirСraftGun.Step; break; } } @@ -124,8 +123,8 @@ namespace AntiAircraftGun.DrawingObjects Pen pen = Pens.Black; - Brush bodyBrush = new SolidBrush(EntityAntiAirСraftGun.BodyColor); - Brush additionalBrush = new SolidBrush(EntityAntiAirСraftGun.AdditionalColor); + Brush bodyBrush = new SolidBrush(AntiAirСraftGun.BodyColor); + Brush additionalBrush = new SolidBrush(AntiAirСraftGun.AdditionalColor); g.FillEllipse(additionalBrush, _startPosX, _startPosY + 40, 110, 10); g.DrawEllipse(pen, _startPosX, _startPosY + 40, 110, 10); diff --git a/AntiAirCraftGun/AntiAirCraftGun/Enitites/EntityAdvancedAntiAircraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/Enitites/EntityAdvancedAntiAircraftGun.cs index 2ad1df9..31daa0d 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/Enitites/EntityAdvancedAntiAircraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/Enitites/EntityAdvancedAntiAircraftGun.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace AntiAircraftGun.Enitites { - public class EntityAdvancedAntiAircraftGun : EntityAntiAirCraftGun + public class EntityAdvancedAntiAirCraftGun : EntityAntiAirCraftGun { public Color DopColor { get; private set; } @@ -17,7 +17,7 @@ namespace AntiAircraftGun.Enitites - public EntityAdvancedAntiAircraftGun(int speed, double weight, Color bodyColor, Color additionalColor,Color dopColor, bool rocket, bool radar) + public EntityAdvancedAntiAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor,Color dopColor, bool rocket, bool radar) : base(speed, weight, bodyColor, additionalColor) { DopColor = dopColor; diff --git a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs index 84c9976..7fe4cfe 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs @@ -65,7 +65,7 @@ namespace AntiAircraftGun bodyColor = dialog.Color; if (dialog.ShowDialog() == DialogResult.OK) dopColor = dialog.Color; - _drawing = new AdvancedDrawingAntAirCraftGun( + _drawing = new AdvancedDrawingAntiAirCraftGun( random.Next(100, 300), // random.Next(1000, 3000), // bodyColor, additionalColor, dopColor, diff --git a/AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/BorderDirection.cs b/AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/BorderDirection.cs deleted file mode 100644 index f55fd9c..0000000 --- a/AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/BorderDirection.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AntiAircraftGun.MovementStrategy -{ - public enum BorderDirection - { - Left, - Right, - Top, - Bottom - } -} diff --git a/AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/DrawingObjectAntiAirCraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/DrawingObjectAntiAirCraftGun.cs index 88886e3..6a4948c 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/DrawingObjectAntiAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/DrawingObjectAntiAirCraftGun.cs @@ -9,28 +9,28 @@ namespace AntiAircraftGun.MovementStrategy { public class DrawingObjectAntiAirCraftGun : IMoveableObject { - private readonly BaseDrawingAntiAirCraftGun? _drawningCar = null; + private readonly BaseDrawingAntiAirCraftGun? _drawningAntiAirCraftGun = null; public DrawingObjectAntiAirCraftGun(BaseDrawingAntiAirCraftGun drawningCar) { - _drawningCar = drawningCar; + _drawningAntiAirCraftGun = drawningCar; } public ObjectParameters? GetObjectPosition { get { - if (_drawningCar == null || _drawningCar.EntityAntiAirСraftGun == + if (_drawningAntiAirCraftGun == null || _drawningAntiAirCraftGun.AntiAirСraftGun == null) { return null; } - return new ObjectParameters(_drawningCar.GetPosX, - _drawningCar.GetPosY, _drawningCar.GetWidth, _drawningCar.GetHeight); + return new ObjectParameters(_drawningAntiAirCraftGun.GetPosX, + _drawningAntiAirCraftGun.GetPosY, _drawningAntiAirCraftGun.GetWidth, _drawningAntiAirCraftGun.GetHeight); } } - public int GetStep => (int)(_drawningCar?.EntityAntiAirСraftGun?.Step ?? 0); + public int GetStep => (int)(_drawningAntiAirCraftGun?.AntiAirСraftGun?.Step ?? 0); public bool CheckCanMove(DirectionType direction) => - _drawningCar?.CanMove(direction) ?? false; + _drawningAntiAirCraftGun?.CanMove(direction) ?? false; public void MoveObject(DirectionType direction) => - _drawningCar?.MoveTransport(direction); + _drawningAntiAirCraftGun?.MoveTransport(direction); } }