diff --git a/AirBomber/AirBomber/DrawningAirBomber.cs b/AirBomber/AirBomber/DrawningAirBomber.cs
index f4af376..b240427 100644
--- a/AirBomber/AirBomber/DrawningAirBomber.cs
+++ b/AirBomber/AirBomber/DrawningAirBomber.cs
@@ -80,5 +80,23 @@ namespace AirBomber
g.DrawLine(pen, baseTail, new PointF(r.Right, r.Top));
g.DrawLine(pen, baseTail, new PointF(r.Right, r.Bottom));
}
+
+ ///
+ /// Возвращает итератор со свойствами самолета в порядке:
+ /// Скорость -> Вес -> Цвет корпуса -> Тип двигателя, либо null если их нет -> Количество двигателей -> Дополнительный цвет -> Наличие бомб -> Наличие топливных баков
+ ///
+ public override IEnumerator GetEnumerator()
+ {
+ IEnumerator enumBase = base.GetEnumerator();
+ while (enumBase.MoveNext())
+ {
+ yield return enumBase.Current;
+ }
+ var entity = (EntityAirBomber)Airplane;
+ yield return entity.DopColor;
+ yield return entity.HasBombs;
+ yield return entity.HasFuelTanks;
+ yield break;
+ }
}
}
diff --git a/AirBomber/AirBomber/DrawningAirplane.cs b/AirBomber/AirBomber/DrawningAirplane.cs
index 4c3c0c4..abeabfc 100644
--- a/AirBomber/AirBomber/DrawningAirplane.cs
+++ b/AirBomber/AirBomber/DrawningAirplane.cs
@@ -1,16 +1,24 @@
-namespace AirBomber
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+using System.Collections;
+
+namespace AirBomber
{
///
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
///
- public class DrawningAirplane
+ public class DrawningAirplane : IEnumerator, IEnumerable
{
///
/// Класс-сущность
///
public EntityAirplane Airplane { get; protected set; }
-
+
public IAirplaneEngines? DrawningEngines { get; protected set; }
+
+ private IEnumerator? _machineStateEnum = null;
+
+ public object Current => _machineStateEnum?.Current;
+
///
/// Левая координата отрисовки самолета
///
@@ -97,7 +105,7 @@
_pictureHeight = height;
// Проверка на нахождение предмета полностью в границах окна
if (width <= _airplaneWidth || height <= _airplaneHeight
- || _startPosX < 0 || _startPosX + _airplaneWidth > width ||
+ || _startPosX < 0 || _startPosX + _airplaneWidth > width ||
_startPosY < 0 || _startPosY + _airplaneHeight > height)
{
_pictureWidth = null;
@@ -163,14 +171,14 @@
var h = _airplaneHeight;
SolidBrush BodyColorBrush = new(Airplane.BodyColor);
// Треугольник самолета
- g.FillPolygon(BodyColorBrush, new PointF[] {
+ g.FillPolygon(BodyColorBrush, new PointF[] {
new PointF(x , y + h / 2),
new PointF(x + 15, y + h / 2 - 7),
new PointF(x + 15, y + h / 2 + 8),
});
// Тело самолета
g.FillRectangle(BodyColorBrush, x + 15, y + h / 2 - 7, w - 35, 15);
- DrawWing(g, BodyColorBrush, new PointF(x + w / 2 - 20, y + h / 2 - 7), new PointF(x + w / 2, y + h / 2 - 7), true , h / 2 - 7);
+ DrawWing(g, BodyColorBrush, new PointF(x + w / 2 - 20, y + h / 2 - 7), new PointF(x + w / 2, y + h / 2 - 7), true, h / 2 - 7);
DrawWing(g, BodyColorBrush, new PointF(x + w / 2 - 20, y + h / 2 + 7), new PointF(x + w / 2, y + h / 2 + 7), false, h / 2 - 7);
// Линия примыкающая к хвосту слева
@@ -241,5 +249,34 @@
{
return new(_startPosX, _startPosY, _airplaneWidth, _airplaneHeight);
}
+
+ public bool MoveNext()
+ {
+ if (_machineStateEnum == null)
+ {
+ _machineStateEnum = GetEnumerator();
+ }
+ return _machineStateEnum.MoveNext();
+ }
+
+ public void Reset() => throw new NotSupportedException();
+
+ public void Dispose() => GC.SuppressFinalize(this);
+
+ ///
+ /// Возвращает итератор со свойствами самолета в порядке:
+ /// Скорость -> Вес -> Цвет корпуса -> Тип двигателя, либо null если их нет -> Количество двигателей
+ ///
+ virtual public IEnumerator GetEnumerator()
+ {
+ yield return Airplane.Speed;
+ yield return Airplane.Weight;
+ yield return Airplane.BodyColor;
+ yield return DrawningEngines;
+ yield return DrawningEngines?.CountEngines ?? 0;
+ yield break;
+ }
+
+ IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
\ No newline at end of file