61 lines
2.0 KiB
C#

using ProjectMonorail.CollectionGenericObject;
using ProjectMonorail.Drawings;
using ProjectMonorail.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMonorail.CollectionGenericObjects;
public class TrainSharingService : AbstractCompany
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="collection"></param>
public TrainSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawingTrain> collection) : base(picWidth, picHeight, collection)
{
}
protected override void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
int posX = 0;
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
int posY = 0;
g.DrawLine(pen, posX, posY, posX, posY + _placeSizeHeight * (_pictureHeight / _placeSizeHeight));
for (int j = 0; j <= _pictureHeight / _placeSizeHeight; j++)
{
g.DrawLine(pen, posX, posY, posX + _placeSizeWidth - 30, posY);
posY += _placeSizeHeight;
}
posX += _placeSizeWidth;
}
}
protected override void SetObjectsPosition()
{
int counter = 0;
int valPlaceY = _pictureHeight / _placeSizeHeight;
for (int y = ((valPlaceY - 1) * _placeSizeHeight) + 30; y >= 0; y -= _placeSizeHeight)
{
for (int x = 10; x + _placeSizeWidth < _pictureWidth; x += _placeSizeWidth)
{
try
{
_collection?.Get(counter)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection?.Get(counter)?.SetPosition(x, y);
counter++;
}
catch (ObjectNotFoundException) { }
catch (PositionOutOfCollectionException) { }
}
}
}
}