Правлен PlanesGenericCollection

This commit is contained in:
Никита Потапов 2023-10-24 12:43:15 +04:00
parent 650b42c43a
commit d140d781b7
2 changed files with 21 additions and 12 deletions

View File

@ -25,7 +25,11 @@ public class PlanesGenericCollection<T extends DrawingPlane, U extends IMoveable
}
public T Sub(int pos) {
return _collection.Remove(pos);
T obj = _collection.Get(pos);
if (obj != null) {
_collection.Remove(pos);
}
return obj;
}
public U GetU(int pos) {
@ -55,12 +59,11 @@ public class PlanesGenericCollection<T extends DrawingPlane, U extends IMoveable
private void DrawObjects(Graphics g) {
int placesColumnCount = _pictureHeight / _placeSizeHeight;
int placesRowCount = _pictureWidth / _placeSizeWidth;
for (int i = 0; i < _collection.Count(); i++) {
// получение объекта
var obj = _collection.Get(i);
int i = 0;
for (var obj :
_collection.GetEnumerator()) {
// установка позиции
if (obj == null)
continue;
if (obj != null) {
obj.SetPosition(
(placesRowCount - 1) * _placeSizeWidth - (i % placesColumnCount * _placeSizeWidth) + (_placeSizeWidth - obj.GetWidth()) / 2,
i / placesColumnCount * _placeSizeHeight + (_placeSizeHeight - obj.GetHeight()) / 2
@ -68,5 +71,7 @@ public class PlanesGenericCollection<T extends DrawingPlane, U extends IMoveable
// прорисовка объекта
obj.DrawTransport(g);
}
i++;
}
}
}

View File

@ -59,4 +59,8 @@ public class SetGeneric<T extends DrawingPlane> {
// Вставка в список по позиции
_places.set(position, plane);
}
public ArrayList<T> GetEnumerator() {
return _places;
}
}