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..8af7606 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 7b57a03..5ab4d02 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/DrawingObjects/BaseDrawingAntiAirCraftGun.cs @@ -9,7 +9,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; @@ -21,7 +21,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) @@ -30,20 +30,18 @@ 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; } } /// @@ -70,20 +68,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.Down => _startPosY + EntityAntiAirСraftGun.Step < _pictureHeight - 60, + DirectionType.Right =>_startPosX + AntiAirСraftGun.Step + _zenitWidth < _pictureWidth, + //вниз + DirectionType.Down => _startPosY + AntiAirСraftGun.Step + _zenitHeight < _pictureHeight, _ => false, }; } @@ -93,7 +91,7 @@ namespace AntiAircraftGun.DrawingObjects /// Направление public void MoveTransport(DirectionType direction) { - if (!CanMove(direction) || EntityAntiAirСraftGun == null) + if (!CanMove(direction) || AntiAirСraftGun == null) { return; } @@ -101,19 +99,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; } } @@ -123,8 +121,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/FormAntiAirCraftGun.Designer.cs b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.Designer.cs index 642efb3..847b92d 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.Designer.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.Designer.cs @@ -120,7 +120,7 @@ this.comboBoxStrategy.Name = "comboBoxStrategy"; this.comboBoxStrategy.Size = new System.Drawing.Size(170, 23); this.comboBoxStrategy.TabIndex = 6; - this.comboBoxStrategy.SelectedIndexChanged += new System.EventHandler(this.comboBoxStrategy_SelectedIndexChanged); + // // CreateAntiAirCraftGun // diff --git a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs index 620a4a4..2321e34 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs @@ -5,7 +5,7 @@ namespace AntiAircraftGun { public partial class FormAntiAirCraftGun : Form { - private BaseDrawingAntiAirCraftGun _drawing; + private BaseDrawingAntiAirCraftGun _drawingAntiAirCraftGun; private AbstractStrategy? _abstractStrategy; public FormAntiAirCraftGun() @@ -15,7 +15,7 @@ namespace AntiAircraftGun private void ButtonMove_Click(object sender, EventArgs e) { - if (_drawing == null) + if (_drawingAntiAirCraftGun == null) { return; } @@ -23,36 +23,36 @@ namespace AntiAircraftGun switch (name) { case "buttonUp": - _drawing.MoveTransport(DirectionType.Up); + _drawingAntiAirCraftGun.MoveTransport(DirectionType.Up); break; case "buttonDown": - _drawing.MoveTransport(DirectionType.Down); + _drawingAntiAirCraftGun.MoveTransport(DirectionType.Down); break; case "buttonLeft": - _drawing.MoveTransport(DirectionType.Left); + _drawingAntiAirCraftGun.MoveTransport(DirectionType.Left); break; case "buttonRight": - _drawing.MoveTransport(DirectionType.Right); + _drawingAntiAirCraftGun.MoveTransport(DirectionType.Right); break; } Draw(); } private void Draw() { - if (_drawing == null) + if (_drawingAntiAirCraftGun == null) { return; } Bitmap bmp = new Bitmap(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); Graphics gr = Graphics.FromImage(bmp); - _drawing.DrawTransport(gr); + _drawingAntiAirCraftGun.DrawTransport(gr); pictureBoxAntiAircraftGun.Image = bmp; } private void CreateAdvancedAintiAirCraftGun_Click(object sender, EventArgs e) { Random random = new Random(); - _drawing = new AdvancedDrawingAntAirCraftGun( + _drawingAntiAirCraftGun = new AdvancedDrawingAntiAirCraftGun( random.Next(100, 300), // random.Next(1000, 3000), // Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), // @@ -64,14 +64,14 @@ namespace AntiAircraftGun pictureBoxAntiAircraftGun.Height ); - _drawing.SetPosition(random.Next(10, 100), random.Next(10, 100)); + _drawingAntiAirCraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } private void CreateAntiAirCraftGun_Click(object sender, EventArgs e) { Random random = new Random(); - _drawing = new BaseDrawingAntiAirCraftGun( + _drawingAntiAirCraftGun = new BaseDrawingAntiAirCraftGun( random.Next(100, 300), // random.Next(1000, 3000), // Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), // @@ -80,13 +80,13 @@ namespace AntiAircraftGun pictureBoxAntiAircraftGun.Height ); - _drawing.SetPosition(random.Next(10, 100), random.Next(10, 100)); + _drawingAntiAirCraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } private void ButtonStep_Click(object sender, EventArgs e) { - if (_drawing == null) + if (_drawingAntiAirCraftGun == null) { return; } @@ -104,7 +104,7 @@ namespace AntiAircraftGun return; } _abstractStrategy.SetData(new - DrawingObjectAntiAirCraftGun(_drawing), pictureBoxAntiAircraftGun.Width, + DrawingObjectAntiAirCraftGun(_drawingAntiAirCraftGun), pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); comboBoxStrategy.Enabled = false; } @@ -121,10 +121,5 @@ namespace AntiAircraftGun } } - - private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e) - { - - } } } \ No newline at end of file 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..c3658b5 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/DrawingObjectAntiAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/DrawingObjectAntiAirCraftGun.cs @@ -18,7 +18,7 @@ namespace AntiAircraftGun.MovementStrategy { get { - if (_drawningCar == null || _drawningCar.EntityAntiAirСraftGun == + if (_drawningCar == null || _drawningCar.AntiAirСraftGun == null) { return null; @@ -27,7 +27,7 @@ namespace AntiAircraftGun.MovementStrategy _drawningCar.GetPosY, _drawningCar.GetWidth, _drawningCar.GetHeight); } } - public int GetStep => (int)(_drawningCar?.EntityAntiAirСraftGun?.Step ?? 0); + public int GetStep => (int)(_drawningCar?.AntiAirСraftGun?.Step ?? 0); public bool CheckCanMove(DirectionType direction) => _drawningCar?.CanMove(direction) ?? false; public void MoveObject(DirectionType direction) =>