70 lines
2.3 KiB
C#
70 lines
2.3 KiB
C#
using ProjectBus.Drawnings;
|
|
using ProjectBus.Entities;
|
|
using ProjectBus.Exceptions;
|
|
using System;
|
|
|
|
namespace ProjectBus.CollectionGenericObject;
|
|
/// <summary>
|
|
/// Реализация абстрактной компании - аренда поезда
|
|
/// </summary>
|
|
public class BusStation : AbstractCompany
|
|
{
|
|
/// <summary>
|
|
/// Конструктор
|
|
/// </summary>
|
|
/// <param name="picWidth"></param>
|
|
/// <param name="picHeight"></param>
|
|
/// <param name="collection"></param>
|
|
public BusStation(int picWidth, int picHeight, ICollectionGenericObjects<DrawningSimpleBus> collection) : base(picWidth, picHeight, collection)
|
|
{
|
|
}
|
|
|
|
protected override void DrawBackgound(Graphics g)
|
|
{
|
|
Pen pen = new(Color.Black);
|
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
|
{
|
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
|
|
{
|
|
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)));
|
|
}
|
|
g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * (_pictureHeight / _placeSizeHeight)), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * (_pictureHeight / _placeSizeHeight)));
|
|
}
|
|
|
|
|
|
}
|
|
|
|
protected override void SetObjectsPosition()
|
|
{
|
|
int n = 0;
|
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
|
{
|
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
|
|
{
|
|
try
|
|
{
|
|
DrawningSimpleBus? drawingSimpleBus = _collection?.Get(n);
|
|
if (drawingSimpleBus != null)
|
|
{
|
|
drawingSimpleBus.SetPictureSize(_pictureWidth, _pictureHeight);
|
|
drawingSimpleBus.SetPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5);
|
|
}
|
|
}
|
|
catch (ObjectNotFoundException e)
|
|
{
|
|
// Relax Man ;)
|
|
}
|
|
catch (PositionOutOfCollectionException e)
|
|
{
|
|
// Relax Man ;)
|
|
}
|
|
|
|
n++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|