63 lines
2.0 KiB
C#
63 lines
2.0 KiB
C#
using Battleship.Drawings;
|
|
|
|
namespace Battleship.CollectionGenericObjects;
|
|
|
|
/// <summary>
|
|
/// Реализация абстрактной компании - доки
|
|
/// </summary>
|
|
public class WarshipSharingService : AbstractCompany
|
|
{
|
|
/// <summary>
|
|
/// Конструктор
|
|
/// </summary>
|
|
/// <param name="picWidth"></param>
|
|
/// <param name="picHeight"></param>
|
|
/// <param name="collection"></param>
|
|
public WarshipSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawingWarship> collection) : base(picWidth, picHeight, collection)
|
|
{
|
|
}
|
|
|
|
protected override void DrawBackground(Graphics g)
|
|
{
|
|
Pen pen = new(Color.DarkSlateBlue, 4);
|
|
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 SetObjectsPosition()
|
|
{
|
|
int width = _pictureWidth / _placeSizeWidth;
|
|
int height = _pictureHeight / _placeSizeHeight;
|
|
|
|
int posWidth = 0;
|
|
int posHeight = height - 1;
|
|
|
|
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 + 4, posHeight * _placeSizeHeight + 4);
|
|
}
|
|
|
|
if (posWidth < width)
|
|
posWidth++;
|
|
else
|
|
{
|
|
posWidth = 0;
|
|
posHeight--;
|
|
}
|
|
if (posHeight > height)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
} |