Правки в PlanesGenericCollection & исправления в SetGeneric

This commit is contained in:
malimova 2023-10-22 14:05:39 +04:00
parent 6c82157b44
commit 521d4750de
2 changed files with 13 additions and 11 deletions

View File

@ -65,7 +65,7 @@ namespace AirBomber
/// <returns></returns> /// <returns></returns>
public static bool operator -(PlanesGenericCollection<T, U> collect, int pos) public static bool operator -(PlanesGenericCollection<T, U> collect, int pos)
{ {
T? obj = collect._collection.Get(pos); T? obj = collect._collection[pos];
if (obj != null) if (obj != null)
{ {
collect._collection.Remove(pos); collect._collection.Remove(pos);
@ -80,7 +80,7 @@ namespace AirBomber
/// <returns></returns> /// <returns></returns>
public U? GetU(int pos) public U? GetU(int pos)
{ {
return (U?)_collection.Get(pos)?.GetMoveableObject; return (U?)_collection[pos]?.GetMoveableObject;
} }
/// <summary> /// <summary>
/// Вывод всего набора объектов /// Вывод всего набора объектов
@ -121,16 +121,18 @@ namespace AirBomber
private void DrawObjects(Graphics g) private void DrawObjects(Graphics g)
{ {
int widthObjCount = _pictureWidth / _placeSizeWidth; int widthObjCount = _pictureWidth / _placeSizeWidth;
for (int i = 0; i < _collection.Count; i++) int i = 0;
foreach (var plane in _collection.GetPlanes())
{ {
T? type = _collection.Get(i); {
if (type != null) if (plane != null)
{ {
int row = i / widthObjCount; int row = i / widthObjCount;
int col = widthObjCount - 1 - (i % widthObjCount); int col = widthObjCount - 1 - (i % widthObjCount);
type.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight); plane.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight);
type?.DrawPlane(g); plane?.DrawPlane(g);
}
} }
} }
} }

View File

@ -123,12 +123,12 @@ namespace AirBomber
/// Проход по списку /// Проход по списку
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public IEnumerable<T?> GetCars(int? maxCars = null) public IEnumerable<T?> GetPlanes(int? maxPlanes = null)
{ {
for (int i = 0; i < _places.Count; ++i) for (int i = 0; i < _places.Count; ++i)
{ {
yield return _places[i]; yield return _places[i];
if (maxCars.HasValue && i == maxCars.Value) if (maxPlanes.HasValue && i == maxPlanes.Value)
{ {
yield break; yield break;
} }