Доработка лабораторной №1

This commit is contained in:
DanilaSm08 2024-02-14 15:10:07 +04:00
parent dfb7f4306e
commit eeb472e8b0
2 changed files with 39 additions and 32 deletions

View File

@ -64,49 +64,56 @@ public class DrawningCleaningCar
/// <param name="height">Высота поля</param>
/// <returns>true - границы заданы, false - проверка не найдена, нельзя разместить
/// объект в этих размерах</returns>
public void SetPictureSize(int width, int height)
public Boolean SetPictureSize(int width, int height)
{
if (width <= _drawningCleaningCarWidth || height <= _drawningCleaningCarHeight) return false;
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _drawningCleaningCarWidth || _pictureHeight <= _drawningCleaningCarHeight)
if (_startPosX.HasValue && _startPosY.HasValue)
{
_pictureWidth = null;
_pictureHeight = null;
return;
}
if (_startPosX + _drawningCleaningCarWidth > _pictureWidth)
{
_startPosX = _pictureWidth.Value - _drawningCleaningCarWidth;
}
if (_startPosY + _drawningCleaningCarHeight > _pictureHeight)
{
_startPosY = _pictureHeight.Value - _drawningCleaningCarHeight;
if (_startPosX + _drawningCleaningCarWidth > _pictureWidth)
{
_startPosX = _pictureWidth.Value - _drawningCleaningCarWidth;
}
if (_startPosY + _drawningCleaningCarHeight > _pictureHeight)
{
_startPosY = _pictureHeight.Value - _drawningCleaningCarHeight;
}
}
return true;
}
/// <summary>
/// Установка позиция
/// </summary>
/// <param name="x">Координата Х</param>
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y, int width, int height)
{
//if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) return;
if (width < _drawningCleaningCarWidth || height < _drawningCleaningCarHeight) return;
if (x + _drawningCleaningCarWidth > width || x < 0) return;
if (y + _drawningCleaningCarHeight > height || y < 0) return;
public void SetPosition(int x, int y)
{
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
}
_startPosX = x;
_startPosY = y;
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - перемещение выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction)
if (_drawningCleaningCarHeight + y > _pictureHeight || y < 0)
{
_startPosY = 0;
}
if (_drawningCleaningCarWidth + x > _pictureWidth || x < 0)
{
_startPosX = 0;
}
return;
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - перемещение выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction)
{
if (EntityCleaningCar == null || !_startPosX.HasValue || !_startPosY.HasValue)
{

View File

@ -55,8 +55,8 @@ namespace ProjectCleaningCar
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)));
//_drawningCleaningCar.SetPictureSize(pictureBoxCleaningCar.Width, pictureBoxCleaningCar.Height);
_drawningCleaningCar.SetPosition(random.Next(10, 100), random.Next(10, 100), pictureBoxCleaningCar.Width, pictureBoxCleaningCar.Height);
_drawningCleaningCar.SetPictureSize(pictureBoxCleaningCar.Width, pictureBoxCleaningCar.Height);
_drawningCleaningCar.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
/// <summary>