2024-05-16 00:31:40 +03:00

74 lines
2.3 KiB
C#

using ProjectBattleship.DrawingObject;
namespace ProjectBattleship.CollectionGenericObjects;
/// <summary>
/// Реализация абстрактной компании - доки
/// </summary>
public class Docks : AbstractCompany
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="collection"></param>
public Docks(int picWidth, int picHeight,
ICollectionGenericObjects<DrawingWarship> collection) :
base(picWidth, picHeight, collection)
{
}
protected override void DrawBackground(Graphics g)
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
Brush brush = new SolidBrush(Color.Black);
for (int i = 0; i < width; ++i)
{
for (int j = 0; j < height; ++j)
{
g.FillRectangle(brush, i * _placeSizeWidth,
j * _placeSizeHeight, 200, 5);
g.FillRectangle(brush, i * _placeSizeWidth,
j * _placeSizeHeight, 5, 80);
}
}
for (int j = 0; j < height - 4; ++j)
{
g.FillRectangle(brush, j * _placeSizeWidth,
height * _placeSizeHeight, 200, 5);
}
}
protected override void SetObjectsPosition()
{
if (_collection == null) return;
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int curWidth = width - 1;
int curHeight = 0;
for (int i = 0; i < _collection.Count; i++)
{
DrawingWarship? _warship = _collection.Get(i);
if (_warship != null)
{
if (_warship.SetPictureSize(_pictureWidth, _pictureHeight))
{
_warship.SetPosition(_placeSizeWidth * curWidth + 20,
curHeight * _placeSizeHeight + 15);
}
}
curWidth--;
if (curWidth < 0)
{
curHeight++;
curWidth = width - 1;
}
if (curHeight >= height)
{
return;
}
}
}
}