Compare commits

..

6 Commits

Author SHA1 Message Date
203daf9a16 Last fix 2023-10-15 23:02:57 +04:00
58872d7938 fix 2023-10-15 23:01:17 +04:00
6e4ffe95d8 Fix 2023-10-15 22:58:40 +04:00
e9ec3ff774 Fixed 2023-10-15 22:01:02 +04:00
4c46170f09 Fixed 2023-10-15 20:49:57 +04:00
d5b447bf0f Fixed 2023-10-15 20:34:13 +04:00
6 changed files with 55 additions and 72 deletions

View File

@ -9,26 +9,26 @@ using static System.Windows.Forms.AxHost;
namespace AntiAircraftGun.DrawingObjects namespace AntiAircraftGun.DrawingObjects
{ {
public class AdvancedDrawingAntAirCraftGun : BaseDrawingAntiAirCraftGun public class AdvancedDrawingAntiAirCraftGun : BaseDrawingAntiAirCraftGun
{ {
private Point[] points = new Point[4]; 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) 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) public override void DrawTransport(Graphics g)
{ {
if (EntityAntiAirСraftGun is not EntityAdvancedAntiAircraftGun advancedGun) if (AntiAirСraftGun is not EntityAdvancedAntiAirCraftGun advancedGun)
{ {
return; return;
} }
Pen pen = new Pen(Color.Black); Pen pen = new Pen(Color.Black);
Brush bodyBrush = new SolidBrush(EntityAntiAirСraftGun.BodyColor); Brush bodyBrush = new SolidBrush(AntiAirСraftGun.BodyColor);
Brush additionalBrush = new SolidBrush(EntityAntiAirСraftGun.AdditionalColor); Brush additionalBrush = new SolidBrush(AntiAirСraftGun.AdditionalColor);
base.DrawTransport(g); base.DrawTransport(g);
Brush dopBrush = new SolidBrush(advancedGun.DopColor); Brush dopBrush = new SolidBrush(advancedGun.DopColor);
Pen dopPen = new Pen(advancedGun.DopColor); Pen dopPen = new Pen(advancedGun.DopColor);

View File

@ -10,7 +10,7 @@ namespace AntiAircraftGun.DrawingObjects
{ {
public class BaseDrawingAntiAirCraftGun public class BaseDrawingAntiAirCraftGun
{ {
public EntityAntiAirCraftGun? EntityAntiAirСraftGun { get; protected set; } public EntityAntiAirCraftGun? AntiAirСraftGun { get; protected set; }
private readonly int _pictureWidth; private readonly int _pictureWidth;
private readonly int _pictureHeight; private readonly int _pictureHeight;
protected int _startPosX; protected int _startPosX;
@ -22,7 +22,7 @@ namespace AntiAircraftGun.DrawingObjects
{ {
_pictureWidth = width; _pictureWidth = width;
_pictureHeight = height; _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) 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; _pictureHeight = height;
_zenitWidth = carWidth; _zenitWidth = carWidth;
_zenitHeight = carHeight; _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) 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; _startPosX = 1;
_startPosY = 10; _startPosY = 1;
}
else
{
_startPosX = x;
_startPosY = y;
} }
} }
/// <summary> /// <summary>
/// Координата X объекта /// Координата X объекта
@ -71,20 +70,20 @@ namespace AntiAircraftGun.DrawingObjects
/// <returns>true - можно переместится по указанному направлению</returns> /// <returns>true - можно переместится по указанному направлению</returns>
public bool CanMove(DirectionType direction) public bool CanMove(DirectionType direction)
{ {
if (EntityAntiAirСraftGun == null) if (AntiAirСraftGun == null)
{ {
return false; return false;
} }
return direction switch 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 + _zenitWidth < _pictureWidth,
//вниз //вниз
DirectionType.Down => _startPosY + EntityAntiAirСraftGun.Step < _pictureHeight - 60, DirectionType.Down => _startPosY + AntiAirСraftGun.Step + _zenitHeight< _pictureHeight,
_ => false, _ => false,
}; };
} }
@ -94,7 +93,7 @@ namespace AntiAircraftGun.DrawingObjects
/// <param name="direction">Направление</param> /// <param name="direction">Направление</param>
public void MoveTransport(DirectionType direction) public void MoveTransport(DirectionType direction)
{ {
if (!CanMove(direction) || EntityAntiAirСraftGun == null) if (!CanMove(direction) || AntiAirСraftGun == null)
{ {
return; return;
} }
@ -102,19 +101,19 @@ namespace AntiAircraftGun.DrawingObjects
{ {
//влево //влево
case DirectionType.Left: case DirectionType.Left:
_startPosX -= (int)EntityAntiAirСraftGun.Step; _startPosX -= (int)AntiAirСraftGun.Step;
break; break;
//вверх //вверх
case DirectionType.Up: case DirectionType.Up:
_startPosY -= (int)EntityAntiAirСraftGun.Step; _startPosY -= (int)AntiAirСraftGun.Step;
break; break;
// вправо // вправо
case DirectionType.Right: case DirectionType.Right:
_startPosX += (int)EntityAntiAirСraftGun.Step; _startPosX += (int)AntiAirСraftGun.Step;
break; break;
//вниз //вниз
case DirectionType.Down: case DirectionType.Down:
_startPosY += (int)EntityAntiAirСraftGun.Step; _startPosY += (int)AntiAirСraftGun.Step;
break; break;
} }
} }
@ -124,8 +123,8 @@ namespace AntiAircraftGun.DrawingObjects
Pen pen = Pens.Black; Pen pen = Pens.Black;
Brush bodyBrush = new SolidBrush(EntityAntiAirСraftGun.BodyColor); Brush bodyBrush = new SolidBrush(AntiAirСraftGun.BodyColor);
Brush additionalBrush = new SolidBrush(EntityAntiAirСraftGun.AdditionalColor); Brush additionalBrush = new SolidBrush(AntiAirСraftGun.AdditionalColor);
g.FillEllipse(additionalBrush, _startPosX, _startPosY + 40, 110, 10); g.FillEllipse(additionalBrush, _startPosX, _startPosY + 40, 110, 10);
g.DrawEllipse(pen, _startPosX, _startPosY + 40, 110, 10); g.DrawEllipse(pen, _startPosX, _startPosY + 40, 110, 10);

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AntiAircraftGun.Enitites namespace AntiAircraftGun.Enitites
{ {
public class EntityAdvancedAntiAircraftGun : EntityAntiAirCraftGun public class EntityAdvancedAntiAirCraftGun : EntityAntiAirCraftGun
{ {
public Color DopColor { get; private set; } 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) : base(speed, weight, bodyColor, additionalColor)
{ {
DopColor = dopColor; DopColor = dopColor;

View File

@ -6,7 +6,7 @@ namespace AntiAircraftGun
{ {
public partial class FormAntiAirCraftGun : Form public partial class FormAntiAirCraftGun : Form
{ {
private BaseDrawingAntiAirCraftGun _drawing; private BaseDrawingAntiAirCraftGun _drawingAntiAirCraftGun;
private AbstractStrategy? _abstractStrategy; private AbstractStrategy? _abstractStrategy;
@ -20,7 +20,7 @@ namespace AntiAircraftGun
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
{ {
if (_drawing == null) if (_drawingAntiAirCraftGun == null)
{ {
return; return;
} }
@ -28,29 +28,29 @@ namespace AntiAircraftGun
switch (name) switch (name)
{ {
case "buttonUp": case "buttonUp":
_drawing.MoveTransport(DirectionType.Up); _drawingAntiAirCraftGun.MoveTransport(DirectionType.Up);
break; break;
case "buttonDown": case "buttonDown":
_drawing.MoveTransport(DirectionType.Down); _drawingAntiAirCraftGun.MoveTransport(DirectionType.Down);
break; break;
case "buttonLeft": case "buttonLeft":
_drawing.MoveTransport(DirectionType.Left); _drawingAntiAirCraftGun.MoveTransport(DirectionType.Left);
break; break;
case "buttonRight": case "buttonRight":
_drawing.MoveTransport(DirectionType.Right); _drawingAntiAirCraftGun.MoveTransport(DirectionType.Right);
break; break;
} }
Draw(); Draw();
} }
private void Draw() private void Draw()
{ {
if (_drawing == null) if (_drawingAntiAirCraftGun == null)
{ {
return; return;
} }
Bitmap bmp = new Bitmap(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); Bitmap bmp = new Bitmap(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
_drawing.DrawTransport(gr); _drawingAntiAirCraftGun.DrawTransport(gr);
pictureBoxAntiAircraftGun.Image = bmp; pictureBoxAntiAircraftGun.Image = bmp;
} }
@ -65,7 +65,7 @@ namespace AntiAircraftGun
bodyColor = dialog.Color; bodyColor = dialog.Color;
if (dialog.ShowDialog() == DialogResult.OK) if (dialog.ShowDialog() == DialogResult.OK)
dopColor = dialog.Color; dopColor = dialog.Color;
_drawing = new AdvancedDrawingAntAirCraftGun( _drawingAntiAirCraftGun = new AdvancedDrawingAntiAirCraftGun(
random.Next(100, 300), // Ńęîđîńňü random.Next(100, 300), // Ńęîđîńňü
random.Next(1000, 3000), // Âĺń random.Next(1000, 3000), // Âĺń
bodyColor, additionalColor, dopColor, bodyColor, additionalColor, dopColor,
@ -75,7 +75,7 @@ namespace AntiAircraftGun
pictureBoxAntiAircraftGun.Height pictureBoxAntiAircraftGun.Height
); );
_drawing.SetPosition(random.Next(10, 100), random.Next(10, 100)); _drawingAntiAirCraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw(); Draw();
} }
@ -89,7 +89,7 @@ namespace AntiAircraftGun
{ {
bodyColor = dialog.Color; bodyColor = dialog.Color;
} }
_drawing = new BaseDrawingAntiAirCraftGun( _drawingAntiAirCraftGun = new BaseDrawingAntiAirCraftGun(
random.Next(100, 300), // Ńęîđîńňü random.Next(100, 300), // Ńęîđîńňü
random.Next(1000, 3000), // Âĺń random.Next(1000, 3000), // Âĺń
bodyColor, additionalColor, bodyColor, additionalColor,
@ -97,13 +97,13 @@ namespace AntiAircraftGun
pictureBoxAntiAircraftGun.Height pictureBoxAntiAircraftGun.Height
); );
_drawing.SetPosition(random.Next(10, 100), random.Next(10, 100)); _drawingAntiAirCraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw(); Draw();
} }
private void ButtonStep_Click(object sender, EventArgs e) private void ButtonStep_Click(object sender, EventArgs e)
{ {
if (_drawing == null) if (_drawingAntiAirCraftGun == null)
{ {
return; return;
} }
@ -121,7 +121,7 @@ namespace AntiAircraftGun
return; return;
} }
_abstractStrategy.SetData(new _abstractStrategy.SetData(new
DrawingObjectAntiAirCraftGun(_drawing), pictureBoxAntiAircraftGun.Width, DrawingObjectAntiAirCraftGun(_drawingAntiAirCraftGun), pictureBoxAntiAircraftGun.Width,
pictureBoxAntiAircraftGun.Height); pictureBoxAntiAircraftGun.Height);
comboBoxStrategy.Enabled = false; comboBoxStrategy.Enabled = false;
} }
@ -140,10 +140,10 @@ namespace AntiAircraftGun
} }
private void ButtonSelectZenit_Click(object sender, EventArgs e) private void ButtonSelectZenit_Click(object sender, EventArgs e)
{ {
SelectedZenit = _drawing; SelectedZenit = _drawingAntiAirCraftGun;
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
} }
} }
} }

View File

@ -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
}
}

View File

@ -9,28 +9,28 @@ namespace AntiAircraftGun.MovementStrategy
{ {
public class DrawingObjectAntiAirCraftGun : IMoveableObject public class DrawingObjectAntiAirCraftGun : IMoveableObject
{ {
private readonly BaseDrawingAntiAirCraftGun? _drawningCar = null; private readonly BaseDrawingAntiAirCraftGun? _drawningAntiAirCraftGun = null;
public DrawingObjectAntiAirCraftGun(BaseDrawingAntiAirCraftGun drawningCar) public DrawingObjectAntiAirCraftGun(BaseDrawingAntiAirCraftGun drawningCar)
{ {
_drawningCar = drawningCar; _drawningAntiAirCraftGun = drawningCar;
} }
public ObjectParameters? GetObjectPosition public ObjectParameters? GetObjectPosition
{ {
get get
{ {
if (_drawningCar == null || _drawningCar.EntityAntiAirСraftGun == if (_drawningAntiAirCraftGun == null || _drawningAntiAirCraftGun.AntiAirСraftGun ==
null) null)
{ {
return null; return null;
} }
return new ObjectParameters(_drawningCar.GetPosX, return new ObjectParameters(_drawningAntiAirCraftGun.GetPosX,
_drawningCar.GetPosY, _drawningCar.GetWidth, _drawningCar.GetHeight); _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) => public bool CheckCanMove(DirectionType direction) =>
_drawningCar?.CanMove(direction) ?? false; _drawningAntiAirCraftGun?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) => public void MoveObject(DirectionType direction) =>
_drawningCar?.MoveTransport(direction); _drawningAntiAirCraftGun?.MoveTransport(direction);
} }
} }