using ProjectLainer.MovementStrategy; using ProjectLainer.DrawningObjects; namespace ProjectLainer.Generics { internal class LainersGenericCollection where T : DrawingEntity where U : IMoveableObject { private readonly int _pictureWidth; private readonly int _pictureHeight; private readonly int _placeSizeWidth = 210; private readonly int _placeSizeHeight = 90; private readonly SetGeneric _collection; public LainersGenericCollection(int picWidth, int picHeight) { int width = picWidth / _placeSizeWidth; int height = picHeight / _placeSizeHeight; _pictureWidth = picWidth; _pictureHeight = picHeight; _collection = new SetGeneric(width * height); } public static bool operator +(LainersGenericCollection collect, T? obj) { if (obj != null && collect != null) return collect._collection.Insert(obj); return false; } public static T? operator -(LainersGenericCollection collect, int pos) { T? obj = collect._collection[pos]; if (obj != null) { collect._collection.Remove(pos); } return obj; } public U? GetU(int pos) { return (U?)_collection[pos]?.GetMoveableObject; } public Bitmap ShowLainers() { Bitmap bmp = new(_pictureWidth, _pictureHeight); Graphics gr = Graphics.FromImage(bmp); DrawBackground(gr); DrawObjects(gr); return bmp; } private void DrawBackground(Graphics g) { Pen pen = new(Color.Black, 3); for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) { for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) {//линия рамзетки места g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); } g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); } } private void DrawObjects(Graphics g) { int i = 0; foreach (var lainer in _collection.GetLainers()) { if (lainer != null) { int inRow = _pictureWidth / _placeSizeWidth; lainer.SetPosition((inRow - 1 - (i % inRow)) * _placeSizeWidth, i / inRow * _placeSizeHeight); lainer.DrawTransport(g); } i++; } } } }