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

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="bodyColor">Основной цвет</param>
public DrawningWarPlane(int speed, double weight, Color bodyColor) : this()
{
public void Init(EntityAirFighter entityAirFighter)
EntityWarPlane = new EntityWarPlane(speed, weight, bodyColor);
}
@ -90,7 +90,9 @@ public class DrawningWarPlane
_drawningWarPlaneWidth = drawningWarPlaneWidth;
_drawningWarPlaneHeight = drawningWarPlaneHeight;
}
_startPosY = null;
/// <summary>
@ -98,7 +100,9 @@ public class DrawningWarPlane
/// </summary>
/// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param>
/// <returns></returns>
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
public bool SetPictureSize(int width, int height)
{
if (width > _drawningWarPlaneWidth && height > _drawningWarPlaneHeight)
@ -131,8 +135,12 @@ public class DrawningWarPlane
}
/// <summary>
/// Установка позиции
/// Установка позиции
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
@ -166,25 +174,23 @@ public class DrawningWarPlane
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - перемещение выполнено, false - перемещение невозможно </returns>
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction)
{
if (EntityWarPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX.Value - EntityWarPlane.Step > 0)
if (_startPosX.Value - EntityAirFighter.Step > 0)
if (_startPosX.Value - EntityAirFighter.Step > 0)
{
_startPosX -= (int)EntityWarPlane.Step;
}
@ -196,13 +202,22 @@ public class DrawningWarPlane
_startPosY -= (int)EntityWarPlane.Step;
}
return true;
//вниз
case DirectionType.Down:
if (_startPosY.Value + EntityWarPlane.Step + _drawningWarPlaneWidth < _pictureHeight)
// вправо
case DirectionType.Right:
//TODO прописать логику сдвига в право
if (_startPosX.Value + _drawningAirFlighterWidth + EntityAirFighter.Step < _pictureWidth)
{
_startPosY += (int)EntityWarPlane.Step;
_startPosX += (int)EntityAirFighter.Step;
}
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:
if (_startPosX.Value + EntityWarPlane.Step + _drawningWarPlaneWidth < _pictureWidth)
@ -210,18 +225,55 @@ public class DrawningWarPlane
_startPosX += (int)EntityWarPlane.Step;
}
return true;
return true;
return true;
default:
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 void DrawTransport(Graphics g)
public void DrawTransport(Graphics g)
{
if (EntityWarPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black, 3);
Pen pen_rocket = new(Color.Black);
@ -253,7 +305,7 @@ public class DrawningWarPlane
//залив носа
Brush brBlack = new SolidBrush(Color.Black);
g.FillPolygon(brBlack, body);
g.FillPolygon(brBlack, body);
//залив корпуса
Brush br = new SolidBrush(EntityWarPlane.BodyColor);
g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 60, 100, 20);
@ -262,7 +314,18 @@ public class DrawningWarPlane
g.FillPolygon(br, wingUpper);
g.FillPolygon(br, rearWingUpper);
g.FillPolygon(br, rearWingLower);
g.FillPolygon(br, rearWingLower);
}
g.FillPolygon(brAdd, AddWingUpper);
g.FillPolygon(brAdd, AddWingLower);
}
}
g.FillPolygon(brAdd, AddWingUpper);
g.FillPolygon(brAdd, AddWingLower);
}
}
}