2024-03-18 09:53:51 +04:00

56 lines
1.7 KiB
C#

using ProjectTrolleybus.Drawnings;
namespace ProjectTrolleybus.CollectionGenericObjects;
public class TrolleyBCarSharingService : AbstractCompany
{
public TrolleyBCarSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTrolleyB> collection) : base(picWidth, picHeight, collection)
{
}
protected override 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; 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);
}
}
protected override void SetObjectPosition()
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int posWidth = width;
int posHeight = 0;
for (int i = 0; i < (_collection?.Count ?? 0); i++)
{
if (_collection?.Get(i) != null)
{
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection?.Get(i)?.SetPosition(_placeSizeWidth * posWidth + 5, posHeight * _placeSizeHeight + 5, width, height);
}
if (posWidth > 0)
posWidth--;
else
{
posWidth = width;
posHeight++;
}
if (posHeight > height - 1)
{
return;
}
}
}
}