PIBD-14_Khalikova.A.R_Storm.../ProjectStormtrooper/CollectionGenericObjects/StormtrooperSharingService.cs

71 lines
2.3 KiB
C#
Raw Normal View History

2024-04-02 08:53:49 +04:00
using ProjectStormtrooper.Drawnings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectStormtrooper.CollectionGenericObjects;
/// <summary>
/// Реализация абстрактной компании
/// </summary>
2024-04-02 08:53:49 +04:00
public class StormtrooperSharingService : AbstractCompany
{
public StormtrooperSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningStormtrooperBase> collection) : base(picWidth, picHeight, collection)
{
}
/// <summary>
/// Вывод заднего фона
/// </summary>
/// <param name="g"></param>
2024-04-02 08:53:49 +04:00
protected override void DrawBackgound(Graphics g)
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
Pen pen = new(Color.Black, 2);
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height + 1; ++j)
{
g.DrawLine(pen, i * _placeSizeWidth + 15, j * _placeSizeHeight, i * _placeSizeWidth + 15 + _placeSizeWidth - 55, j * _placeSizeHeight);
g.DrawLine(pen, i * _placeSizeWidth + 15, j * _placeSizeHeight, i * _placeSizeWidth + 15, j * _placeSizeHeight - _placeSizeHeight);
}
}
}
/// <summary>
/// Расстановка объектов
/// </summary>
2024-04-02 08:53:49 +04:00
protected override void SetObjectsPosition()
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int curWidth = width - 1;
int curHeight = 0;
for (int i = 0; i < (_collection?.Count ?? 0); i++)
{
try
2024-04-02 08:53:49 +04:00
{
if (_collection.Get(i) != null)
{
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
_collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 15, curHeight * _placeSizeHeight + 3);
}
2024-04-02 08:53:49 +04:00
}
catch (Exception) { }
2024-04-02 08:53:49 +04:00
if (curWidth > 0)
curWidth--;
else
{
curWidth = width - 1;
curHeight++;
}
if (curHeight > height)
{
return;
}
}
}
}