PIBD14-BOYKO-M.S.SuperEasyS.../ProjectElectroTrans/CollectionGenericObjects/TransDepoService.cs

71 lines
2.4 KiB
C#
Raw Permalink Normal View History

2024-03-13 19:49:07 +04:00
using ProjectElectroTrans.Drawnings;
using ProjectElectroTrans.Entities;
using System;
2024-04-24 23:26:19 +04:00
using ProjectElectroTrans.Exceptions;
2024-03-13 19:49:07 +04:00
namespace ProjectElectroTrans.CollectionGenericObjects;
/// <summary>
/// Реализация абстрактной компании - аренда поезда
/// </summary>
public class TransDepoService : AbstractCompany
{
2024-04-24 23:26:19 +04:00
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="collection"></param>
public TransDepoService(int picWidth, int picHeight, ICollectionGenericObjects<DrawingTrans> collection) : base(
picWidth, picHeight, collection)
{
}
2024-03-13 19:49:07 +04:00
2024-04-24 23:26:19 +04:00
protected override void DrawBackgound(Graphics g)
{
2024-03-13 19:49:07 +04:00
Pen pen = new(Color.Black);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
2024-04-24 23:26:19 +04:00
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
2024-03-13 19:49:07 +04:00
{
2024-04-24 23:26:19 +04:00
g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j),
new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * j));
g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j),
new(_placeSizeWidth * i, _placeSizeHeight * (j + 1)));
}
2024-03-13 19:49:07 +04:00
2024-04-24 23:26:19 +04:00
g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * (_pictureHeight / _placeSizeHeight)),
new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * (_pictureHeight / _placeSizeHeight)));
}
2024-03-13 19:49:07 +04:00
}
2024-04-24 23:26:19 +04:00
protected override void SetObjectsPosition()
{
int n = 0;
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
{
try
{
DrawingTrans? drawingTrans = _collection?.Get(n);
if (drawingTrans != null)
{
drawingTrans.SetPictureSize(_pictureWidth, _pictureHeight);
drawingTrans.SetPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5);
}
}
catch (ObjectNotFoundException e)
{
// Relax Man ;)
}
catch (PositionOutOfCollectionException e)
{
// Relax Man ;)
}
n++;
}
}
}
2024-03-13 19:49:07 +04:00
}