Compare commits
No commits in common. "203daf9a1605840221bc7bb9097d2d2999336c1f" and "d17975562c5fbf8201c44da0fb13a21f13c4e859" have entirely different histories.
203daf9a16
...
d17975562c
@ -9,26 +9,26 @@ using static System.Windows.Forms.AxHost;
|
||||
|
||||
namespace AntiAircraftGun.DrawingObjects
|
||||
{
|
||||
public class AdvancedDrawingAntiAirCraftGun : BaseDrawingAntiAirCraftGun
|
||||
public class AdvancedDrawingAntAirCraftGun : BaseDrawingAntiAirCraftGun
|
||||
{
|
||||
private Point[] points = new Point[4];
|
||||
|
||||
public AdvancedDrawingAntiAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor, Color dopColor, bool rocket,bool radar, int width, int height) :
|
||||
public AdvancedDrawingAntAirCraftGun(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)
|
||||
{
|
||||
AntiAirСraftGun = new EntityAdvancedAntiAirCraftGun(speed, weight, bodyColor, additionalColor, dopColor, rocket,radar);
|
||||
EntityAntiAirСraftGun = new EntityAdvancedAntiAircraftGun(speed, weight, bodyColor, additionalColor, dopColor, rocket,radar);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (AntiAirСraftGun is not EntityAdvancedAntiAirCraftGun advancedGun)
|
||||
if (EntityAntiAirСraftGun is not EntityAdvancedAntiAircraftGun advancedGun)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new Pen(Color.Black);
|
||||
Brush bodyBrush = new SolidBrush(AntiAirСraftGun.BodyColor);
|
||||
Brush additionalBrush = new SolidBrush(AntiAirСraftGun.AdditionalColor);
|
||||
Brush bodyBrush = new SolidBrush(EntityAntiAirСraftGun.BodyColor);
|
||||
Brush additionalBrush = new SolidBrush(EntityAntiAirСraftGun.AdditionalColor);
|
||||
base.DrawTransport(g);
|
||||
Brush dopBrush = new SolidBrush(advancedGun.DopColor);
|
||||
Pen dopPen = new Pen(advancedGun.DopColor);
|
@ -10,7 +10,7 @@ namespace AntiAircraftGun.DrawingObjects
|
||||
{
|
||||
public class BaseDrawingAntiAirCraftGun
|
||||
{
|
||||
public EntityAntiAirCraftGun? AntiAirСraftGun { get; protected set; }
|
||||
public EntityAntiAirCraftGun? EntityAntiAirС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;
|
||||
AntiAirСraftGun = new EntityAntiAirCraftGun(speed, weight, bodyColor, additionalColor);
|
||||
EntityAntiAirС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,20 +31,21 @@ namespace AntiAircraftGun.DrawingObjects
|
||||
_pictureHeight = height;
|
||||
_zenitWidth = carWidth;
|
||||
_zenitHeight = carHeight;
|
||||
AntiAirСraftGun = new EntityAntiAirCraftGun(speed, weight, bodyColor, additionalColor);
|
||||
EntityAntiAirСraftGun = new EntityAntiAirCraftGun(speed, weight, bodyColor, additionalColor);
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (AntiAirСraftGun == null) return;
|
||||
if (x < 0 || y < 0)
|
||||
{
|
||||
_startPosX = 10;
|
||||
_startPosY = 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
if (x < 0 || y < 0 || x + _zenitWidth >= _pictureWidth || y + _zenitHeight >= _pictureHeight)
|
||||
{
|
||||
_startPosX = 1;
|
||||
_startPosY = 1;
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
@ -70,20 +71,20 @@ namespace AntiAircraftGun.DrawingObjects
|
||||
/// <returns>true - можно переместится по указанному направлению</returns>
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (AntiAirСraftGun == null)
|
||||
if (EntityAntiAirСraftGun == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
//влево
|
||||
DirectionType.Left => _startPosX - AntiAirСraftGun.Step > 0,
|
||||
DirectionType.Left => _startPosX - EntityAntiAirСraftGun.Step > 0,
|
||||
//вверх
|
||||
DirectionType.Up => _startPosY - AntiAirСraftGun.Step > 0,
|
||||
DirectionType.Up => _startPosY - EntityAntiAirСraftGun.Step > 0,
|
||||
// вправо
|
||||
DirectionType.Right =>_startPosX + AntiAirСraftGun.Step + _zenitWidth < _pictureWidth,
|
||||
DirectionType.Right =>_startPosX + EntityAntiAirСraftGun.Step < _pictureWidth - 110,
|
||||
//вниз
|
||||
DirectionType.Down => _startPosY + AntiAirСraftGun.Step + _zenitHeight< _pictureHeight,
|
||||
DirectionType.Down => _startPosY + EntityAntiAirСraftGun.Step < _pictureHeight - 60,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
@ -93,7 +94,7 @@ namespace AntiAircraftGun.DrawingObjects
|
||||
/// <param name="direction">Направление</param>
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (!CanMove(direction) || AntiAirСraftGun == null)
|
||||
if (!CanMove(direction) || EntityAntiAirСraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -101,19 +102,19 @@ namespace AntiAircraftGun.DrawingObjects
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
_startPosX -= (int)AntiAirСraftGun.Step;
|
||||
_startPosX -= (int)EntityAntiAirСraftGun.Step;
|
||||
break;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
_startPosY -= (int)AntiAirСraftGun.Step;
|
||||
_startPosY -= (int)EntityAntiAirСraftGun.Step;
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
_startPosX += (int)AntiAirСraftGun.Step;
|
||||
_startPosX += (int)EntityAntiAirСraftGun.Step;
|
||||
break;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
_startPosY += (int)AntiAirСraftGun.Step;
|
||||
_startPosY += (int)EntityAntiAirСraftGun.Step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -123,8 +124,8 @@ namespace AntiAircraftGun.DrawingObjects
|
||||
|
||||
|
||||
Pen pen = Pens.Black;
|
||||
Brush bodyBrush = new SolidBrush(AntiAirСraftGun.BodyColor);
|
||||
Brush additionalBrush = new SolidBrush(AntiAirСraftGun.AdditionalColor);
|
||||
Brush bodyBrush = new SolidBrush(EntityAntiAirСraftGun.BodyColor);
|
||||
Brush additionalBrush = new SolidBrush(EntityAntiAirСraftGun.AdditionalColor);
|
||||
|
||||
g.FillEllipse(additionalBrush, _startPosX, _startPosY + 40, 110, 10);
|
||||
g.DrawEllipse(pen, _startPosX, _startPosY + 40, 110, 10);
|
||||
|
@ -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;
|
||||
|
@ -6,7 +6,7 @@ namespace AntiAircraftGun
|
||||
{
|
||||
public partial class FormAntiAirCraftGun : Form
|
||||
{
|
||||
private BaseDrawingAntiAirCraftGun _drawingAntiAirCraftGun;
|
||||
private BaseDrawingAntiAirCraftGun _drawing;
|
||||
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
|
||||
@ -20,7 +20,7 @@ namespace AntiAircraftGun
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingAntiAirCraftGun == null)
|
||||
if (_drawing == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -28,29 +28,29 @@ namespace AntiAircraftGun
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawingAntiAirCraftGun.MoveTransport(DirectionType.Up);
|
||||
_drawing.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawingAntiAirCraftGun.MoveTransport(DirectionType.Down);
|
||||
_drawing.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawingAntiAirCraftGun.MoveTransport(DirectionType.Left);
|
||||
_drawing.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawingAntiAirCraftGun.MoveTransport(DirectionType.Right);
|
||||
_drawing.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingAntiAirCraftGun == null)
|
||||
if (_drawing == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new Bitmap(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawingAntiAirCraftGun.DrawTransport(gr);
|
||||
_drawing.DrawTransport(gr);
|
||||
pictureBoxAntiAircraftGun.Image = bmp;
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ namespace AntiAircraftGun
|
||||
bodyColor = dialog.Color;
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
dopColor = dialog.Color;
|
||||
_drawingAntiAirCraftGun = new AdvancedDrawingAntiAirCraftGun(
|
||||
_drawing = new AdvancedDrawingAntAirCraftGun(
|
||||
random.Next(100, 300), // Ńęîđîńňü
|
||||
random.Next(1000, 3000), // Âĺń
|
||||
bodyColor, additionalColor, dopColor,
|
||||
@ -75,7 +75,7 @@ namespace AntiAircraftGun
|
||||
pictureBoxAntiAircraftGun.Height
|
||||
);
|
||||
|
||||
_drawingAntiAirCraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_drawing.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ namespace AntiAircraftGun
|
||||
{
|
||||
bodyColor = dialog.Color;
|
||||
}
|
||||
_drawingAntiAirCraftGun = new BaseDrawingAntiAirCraftGun(
|
||||
_drawing = new BaseDrawingAntiAirCraftGun(
|
||||
random.Next(100, 300), // Ńęîđîńňü
|
||||
random.Next(1000, 3000), // Âĺń
|
||||
bodyColor, additionalColor,
|
||||
@ -97,13 +97,13 @@ namespace AntiAircraftGun
|
||||
pictureBoxAntiAircraftGun.Height
|
||||
);
|
||||
|
||||
_drawingAntiAirCraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_drawing.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingAntiAirCraftGun == null)
|
||||
if (_drawing == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -121,7 +121,7 @@ namespace AntiAircraftGun
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
DrawingObjectAntiAirCraftGun(_drawingAntiAirCraftGun), pictureBoxAntiAircraftGun.Width,
|
||||
DrawingObjectAntiAirCraftGun(_drawing), pictureBoxAntiAircraftGun.Width,
|
||||
pictureBoxAntiAircraftGun.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
@ -140,7 +140,7 @@ namespace AntiAircraftGun
|
||||
}
|
||||
private void ButtonSelectZenit_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedZenit = _drawingAntiAirCraftGun;
|
||||
SelectedZenit = _drawing;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,16 @@
|
||||
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
|
||||
}
|
||||
}
|
@ -9,28 +9,28 @@ namespace AntiAircraftGun.MovementStrategy
|
||||
{
|
||||
public class DrawingObjectAntiAirCraftGun : IMoveableObject
|
||||
{
|
||||
private readonly BaseDrawingAntiAirCraftGun? _drawningAntiAirCraftGun = null;
|
||||
private readonly BaseDrawingAntiAirCraftGun? _drawningCar = null;
|
||||
public DrawingObjectAntiAirCraftGun(BaseDrawingAntiAirCraftGun drawningCar)
|
||||
{
|
||||
_drawningAntiAirCraftGun = drawningCar;
|
||||
_drawningCar = drawningCar;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawningAntiAirCraftGun == null || _drawningAntiAirCraftGun.AntiAirСraftGun ==
|
||||
if (_drawningCar == null || _drawningCar.EntityAntiAirСraftGun ==
|
||||
null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawningAntiAirCraftGun.GetPosX,
|
||||
_drawningAntiAirCraftGun.GetPosY, _drawningAntiAirCraftGun.GetWidth, _drawningAntiAirCraftGun.GetHeight);
|
||||
return new ObjectParameters(_drawningCar.GetPosX,
|
||||
_drawningCar.GetPosY, _drawningCar.GetWidth, _drawningCar.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawningAntiAirCraftGun?.AntiAirСraftGun?.Step ?? 0);
|
||||
public int GetStep => (int)(_drawningCar?.EntityAntiAirСraftGun?.Step ?? 0);
|
||||
public bool CheckCanMove(DirectionType direction) =>
|
||||
_drawningAntiAirCraftGun?.CanMove(direction) ?? false;
|
||||
_drawningCar?.CanMove(direction) ?? false;
|
||||
public void MoveObject(DirectionType direction) =>
|
||||
_drawningAntiAirCraftGun?.MoveTransport(direction);
|
||||
_drawningCar?.MoveTransport(direction);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user