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

View File

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