PIbd-21 Potapov N.S. LabWork04 #4

Closed
ns.potapov wants to merge 5 commits from LabWork04 into LabWork03
Showing only changes of commit 2a452af6b5 - Show all commits

View File

@ -70,7 +70,12 @@ namespace ProjectStormtrooper
/// <returns></returns>
public static T? operator -(PlanesGenericCollection<T, U> collect, int pos)
{
return collect._collection.Remove(pos);
T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
}
return obj;
}
/// <summary>
/// Получение объекта IMoveableObject
@ -79,7 +84,7 @@ namespace ProjectStormtrooper
/// <returns></returns>
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
return (U?)_collection[pos]?.GetMoveableObject;
}
/// <summary>
/// Вывод всего набора объектов
@ -117,17 +122,20 @@ namespace ProjectStormtrooper
{
int placesColumnCount = _pictureHeight / _placeSizeHeight;
int placesRowCount = _pictureWidth / _placeSizeWidth;
for (int i = 0; i < _collection.Count; i++)
int i = 0;
foreach (var plane in _collection.GetPlanes())
{
// получение объекта
var obj = _collection.Get(i);
// установка позиции
obj?.SetPosition(
(int)((placesRowCount - 1) * _placeSizeWidth - (i % placesColumnCount * _placeSizeWidth) + (_placeSizeWidth - obj?.GetWidth) / 2),
(int)(i / placesColumnCount * _placeSizeHeight + (_placeSizeHeight - obj?.GetHeight) / 2)
);
// прорисовка объекта
obj?.DrawTransport(g);
if (plane != null)
{
// установка позиции
plane.SetPosition(
(int)((placesRowCount - 1) * _placeSizeWidth - (i % placesColumnCount * _placeSizeWidth) + (_placeSizeWidth - plane.GetWidth) / 2),
(int)(i / placesColumnCount * _placeSizeHeight + (_placeSizeHeight - plane.GetHeight) / 2)
);
// прорисовка объекта
plane.DrawTransport(g);
}
i++;
}
}
}