From 4bc51728fefbc5d03d5ad896c27ec4a85f1b7f7a Mon Sep 17 00:00:00 2001 From: YourDax Date: Sun, 15 Oct 2023 20:14:11 +0400 Subject: [PATCH] Fixed --- .../AntiAirCraftGun/DrawingAntiAirCraftGun.cs | 6 +- .../AntiAirCraftGun/FormAntiAirCraftGun.cs | 57 ++++--------------- 2 files changed, 14 insertions(+), 49 deletions(-) diff --git a/AntiAirCraftGun/AntiAirCraftGun/DrawingAntiAirCraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/DrawingAntiAirCraftGun.cs index e4de4a3..dc404a8 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/DrawingAntiAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/DrawingAntiAirCraftGun.cs @@ -72,7 +72,7 @@ namespace AntiAircraftGun if (AntiAircraftGun == null) return; _startPosX = x; _startPosY = y; - if (x + _zenitWidth >= _pictureWidth || y + _zenitHeight>= _pictureHeight) + if (x < 0 || y < 0 ||x + _zenitWidth >= _pictureWidth || y + _zenitHeight>= _pictureHeight) { _startPosX = 1; _startPosY = 1; @@ -106,14 +106,14 @@ namespace AntiAircraftGun break; // вправо case DirectionType.Right: - if (_startPosX + AntiAircraftGun.Step < _pictureWidth-110) + if (_startPosX + AntiAircraftGun.Step + _zenitWidth < _pictureWidth) { _startPosX += (int)AntiAircraftGun.Step; } break; //вниз case DirectionType.Down: - if (_startPosY + AntiAircraftGun.Step < _pictureHeight-60) + if (_startPosY + AntiAircraftGun.Step + _zenitHeight < _pictureHeight) { _startPosY += (int)AntiAircraftGun.Step; } diff --git a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs index c8b7f39..c5c8fea 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGun.cs @@ -5,63 +5,28 @@ namespace AntiAircraftGun /// /// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà /// - private DrawingAntiAirCraftGun? _drawing; + private DrawingAntiAirCraftGun? _drawingAntiAirCraftGun; public FormAntiAirCraftGun() { InitializeComponent(); } - private void Move_Click(object sender, EventArgs e) - { - if (_drawing == null) - { - return; - } - string name = ((Button)sender)?.Name ?? string.Empty; - switch (name) - { - case "buttonUp": - _drawing.MoveTransport(DirectionType.Up); - break; - case "buttonDown": - _drawing.MoveTransport(DirectionType.Down); - break; - case "buttonLeft": - _drawing.MoveTransport(DirectionType.Left); - break; - case "buttonRight": - _drawing.MoveTransport(DirectionType.Right); - break; - } - Draw(); - } - - - - - - private void pictureBoxZenit_Click(object sender, EventArgs e) - { - - } /// /// Ìåòîä ïðîðèñîâêè ìàøèíû /// private void Draw() { - if (_drawing == null) + if (_drawingAntiAirCraftGun == null) { return; } Bitmap bmp = new(pictureBoxAntiAircraftGun.Width,pictureBoxAntiAircraftGun.Height); Graphics gr = Graphics.FromImage(bmp); - _drawing.DrawTransport(gr); + _drawingAntiAirCraftGun.DrawTransport(gr); pictureBoxAntiAircraftGun.Image = bmp; } - - private void ButtonMove_Click(object sender, EventArgs e) { - if (_drawing == null) + if (_drawingAntiAirCraftGun == null) { return; } @@ -69,16 +34,16 @@ 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(); @@ -86,8 +51,8 @@ namespace AntiAircraftGun private void buttonCreate_Click(object sender, EventArgs e) { Random random = new(); - _drawing = new DrawingAntiAirCraftGun(); - _drawing.Init(random.Next(100, 300),//cêîðîñòü + _drawingAntiAirCraftGun = new DrawingAntiAirCraftGun(); + _drawingAntiAirCraftGun.Init(random.Next(100, 300),//cêîðîñòü random.Next(1000, 3000), //âåñ Color.FromArgb(random.Next(0, 256), random.Next(0, 256),//îñíîâíîé öâåò random.Next(0, 256)), @@ -99,7 +64,7 @@ namespace AntiAircraftGun Convert.ToBoolean(random.Next(2)), // Radar pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); - _drawing.SetPosition(random.Next(10, 100), + _drawingAntiAirCraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100));