73 lines
2.3 KiB
C#
73 lines
2.3 KiB
C#
using ProjectBattleship.DrawingObject;
|
|
using ProjectBattleship.Exceptions;
|
|
|
|
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()
|
|
{
|
|
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
|
|
{
|
|
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
|
|
_collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 10, curHeight * _placeSizeHeight + 10);
|
|
}
|
|
catch (ObjectNotFoundException) { }
|
|
catch (PositionOutOfCollectionException e) { }
|
|
if (curWidth > 0)
|
|
curWidth--;
|
|
else
|
|
{
|
|
curWidth = width - 1;
|
|
curHeight++;
|
|
}
|
|
|
|
if (curHeight >= height)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
} |