Коллекция объектов

This commit is contained in:
nezui1 2024-03-19 18:02:35 +04:00
parent d215fc5864
commit bf7cfe1f84

View File

@ -76,7 +76,7 @@ public class DrawningWarPlane
/// <param name="weight">Вес</param> /// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param> /// <param name="bodyColor">Основной цвет</param>
public DrawningWarPlane(int speed, double weight, Color bodyColor) : this() public DrawningWarPlane(int speed, double weight, Color bodyColor) : this()
{ public void Init(EntityAirFighter entityAirFighter)
EntityWarPlane = new EntityWarPlane(speed, weight, bodyColor); EntityWarPlane = new EntityWarPlane(speed, weight, bodyColor);
} }
@ -90,7 +90,9 @@ public class DrawningWarPlane
_drawningWarPlaneWidth = drawningWarPlaneWidth; _drawningWarPlaneWidth = drawningWarPlaneWidth;
_drawningWarPlaneHeight = drawningWarPlaneHeight; _drawningWarPlaneHeight = drawningWarPlaneHeight;
} _startPosY = null;
/// <summary> /// <summary>
@ -98,7 +100,9 @@ public class DrawningWarPlane
/// </summary> /// </summary>
/// <param name="width">Ширина поля</param> /// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param> /// <param name="height">Высота поля</param>
/// <returns></returns> /// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
public bool SetPictureSize(int width, int height) public bool SetPictureSize(int width, int height)
{ {
if (width > _drawningWarPlaneWidth && height > _drawningWarPlaneHeight) if (width > _drawningWarPlaneWidth && height > _drawningWarPlaneHeight)
@ -131,6 +135,10 @@ public class DrawningWarPlane
} }
/// <summary> /// <summary>
/// Установка позиции /// Установка позиции
/// </summary> /// </summary>
@ -166,25 +174,23 @@ public class DrawningWarPlane
} }
/// <summary> /// <summary>
/// Изменение направления перемещения /// Изменение направления перемещения
/// </summary> /// </summary>
/// <param name="direction">Направление</param> /// <param name="direction">Направление</param>
/// <returns>true - перемещение выполнено, false - перемещение невозможно </returns> /// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction) public bool MoveTransport(DirectionType direction)
{ {
if (EntityWarPlane == null || !_startPosX.HasValue || !_startPosY.HasValue) if (EntityWarPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
{ {
return false; return false;
} }
switch (direction) switch (direction)
{ {
//влево
case DirectionType.Left:
if (_startPosX.Value - EntityWarPlane.Step > 0) if (_startPosX.Value - EntityWarPlane.Step > 0)
if (_startPosX.Value - EntityAirFighter.Step > 0)
if (_startPosX.Value - EntityAirFighter.Step > 0)
{ {
_startPosX -= (int)EntityWarPlane.Step; _startPosX -= (int)EntityWarPlane.Step;
} }
@ -196,13 +202,22 @@ public class DrawningWarPlane
_startPosY -= (int)EntityWarPlane.Step; _startPosY -= (int)EntityWarPlane.Step;
} }
return true; return true;
//вниз // вправо
case DirectionType.Down: case DirectionType.Right:
if (_startPosY.Value + EntityWarPlane.Step + _drawningWarPlaneWidth < _pictureHeight) //TODO прописать логику сдвига в право
if (_startPosX.Value + _drawningAirFlighterWidth + EntityAirFighter.Step < _pictureWidth)
{ {
_startPosY += (int)EntityWarPlane.Step;
_startPosX += (int)EntityAirFighter.Step;
} }
return true; return true;
if (_startPosY.Value + EntityWarPlane.Step + _drawningWarPlaneWidth < _pictureHeight)
if (_startPosY.Value + EntityAirFighter.Step + _drawningAirFlighterHeight < _pictureHeight)
if (_startPosY.Value + EntityAirFighter.Step + _drawningAirFlighterHeight < _pictureHeight)
{
_startPosY += (int)EntityWarPlane.Step;
//вправо //вправо
case DirectionType.Right: case DirectionType.Right:
if (_startPosX.Value + EntityWarPlane.Step + _drawningWarPlaneWidth < _pictureWidth) if (_startPosX.Value + EntityWarPlane.Step + _drawningWarPlaneWidth < _pictureWidth)
@ -210,18 +225,55 @@ public class DrawningWarPlane
_startPosX += (int)EntityWarPlane.Step; _startPosX += (int)EntityWarPlane.Step;
} }
return true; return true;
return true;
return true;
default: default:
return false; return false;
} }
} }
public static GraphicsPath RoundedRect(Graphics g, Rectangle bounds, int radius)
{
int diameter = radius * 2;
Size size = new Size(diameter, diameter);
Rectangle arc = new Rectangle(bounds.Location, size);
GraphicsPath path = new GraphicsPath();
if (radius == 0)
{
path.AddRectangle(bounds);
return path;
}
// top left arc
path.AddArc(arc, 180, 90);
// top right arc
arc.X = bounds.Right - diameter;
path.AddArc(arc, 270, 90);
// bottom right arc
arc.Y = bounds.Bottom - diameter;
path.AddArc(arc, 0, 90);
// bottom left arc
arc.X = bounds.Left;
path.AddArc(arc, 90, 90);
g.FillPath(Brushes.Black, path);
path.CloseFigure();
return path;
public virtual void DrawTransport(Graphics g) public virtual void DrawTransport(Graphics g)
public void DrawTransport(Graphics g)
public void DrawTransport(Graphics g)
{ {
if (EntityWarPlane == null || !_startPosX.HasValue || !_startPosY.HasValue) if (EntityWarPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
{ {
return; return;
}
Pen pen = new(Color.Black, 3); Pen pen = new(Color.Black, 3);
Pen pen_rocket = new(Color.Black); Pen pen_rocket = new(Color.Black);
@ -253,7 +305,7 @@ public class DrawningWarPlane
//залив носа //залив носа
Brush brBlack = new SolidBrush(Color.Black); Brush brBlack = new SolidBrush(Color.Black);
g.FillPolygon(brBlack, body); g.FillPolygon(brBlack, body);
g.FillPolygon(brBlack, body);
//залив корпуса //залив корпуса
Brush br = new SolidBrush(EntityWarPlane.BodyColor); Brush br = new SolidBrush(EntityWarPlane.BodyColor);
g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 60, 100, 20); g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 60, 100, 20);
@ -262,7 +314,18 @@ public class DrawningWarPlane
g.FillPolygon(br, wingUpper); g.FillPolygon(br, wingUpper);
g.FillPolygon(br, rearWingUpper); g.FillPolygon(br, rearWingUpper);
g.FillPolygon(br, rearWingLower); g.FillPolygon(br, rearWingLower);
g.FillPolygon(br, rearWingLower);
} }
g.FillPolygon(brAdd, AddWingUpper);
g.FillPolygon(brAdd, AddWingLower);
}
}
g.FillPolygon(brAdd, AddWingUpper);
g.FillPolygon(brAdd, AddWingLower);
}
}
} }