import java.awt.*; public class CruiserGenericCollection { private int _pictureWidth; private int _pictureHeight; private int _placeSizeWidth = 210; private int _placeSizeHeight = 90; private SetGeneric _collection; public CruiserGenericCollection(int picWidth, int picHeight) { int width = picWidth / _placeSizeWidth; int height = picHeight / _placeSizeHeight; _pictureWidth = picWidth; _pictureHeight = picHeight; _collection = new SetGeneric(width * height); } public int plus(CruiserGenericCollection collect, T obj) { if (obj == null) { return -1; } return collect._collection.Insert(obj); } public boolean minus(CruiserGenericCollection collect, int pos) { T obj = collect._collection.Get(pos); if (obj != null) { collect._collection.Remove(pos); } return true; } public U GetU(int pos) { T ans = _collection.Get(pos); if(ans == null) return null; return (U)ans.GetMoveableObject(); } public void ShowCars(Graphics gr) { DrawBackground(gr); DrawObjects(gr); } private void DrawBackground(Graphics g) { for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) { for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) {//линия рамзетки места g.drawLine( i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); } g.drawLine(i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); } } private void DrawObjects(Graphics g) { DrawingCruiser car; int numPlacesInRow = _pictureWidth / _placeSizeWidth; for (int i = 0; i < _collection.Count(); i++) { // TODO получение объекта // TODO установка позиции // TODO прорисовка объекта car = _collection.Get(i); if (car != null) { car.SetPosition((i % numPlacesInRow) * _placeSizeWidth + _placeSizeWidth / 20, _placeSizeHeight * (i / numPlacesInRow) + _placeSizeHeight / 10); car.DrawTransport(g); } } } }